Skip to content

Commit cbd48b8

Browse files
committed
docs: update
1 parent 196109c commit cbd48b8

File tree

7 files changed

+102
-8
lines changed

7 files changed

+102
-8
lines changed

docs/content/2.usage/1.database.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,40 @@ title: Database
33
description: How to create a database and store entries with NuxtHub.
44
---
55

6-
NuxtHub Database is a layer to [Cloudflare D1](https://developers.cloudflare.com/d1), serverless SQL databases.
6+
NuxtHub Database is a layer to [Cloudflare D1](https://developers.cloudflare.com/d1){target=_blank}, serverless SQL databases.
77

88
<!-- TODO: config, binding ? -->
99

1010
Once properly configured, NuxtHub module exposes a server composable to the application.
1111

1212
## `useDatabase()`
1313

14-
Server composable that returns a set of methods from [D1Database](https://developers.cloudflare.com/d1/build-databases/query-databases/).
14+
Server composable that returns a set of methods from [D1Database](https://developers.cloudflare.com/d1/build-databases/query-databases/){target=_blank}.
15+
16+
::callout{icon="i-heroicons-light-bulb"}
17+
This composable exposes low level API, so we recommand using our pattern with [`useDB()`](/recipes/drizzle#usedb) incombination to [Drizzle](https://orm.drizzle.team/docs/overview){target=_blank} to enhance your DX.
18+
::
1519

1620
### `exec()`
1721

22+
Executes one or more queries directly without prepared statements or parameters binding.
23+
24+
[Read more on Cloudflare](https://developers.cloudflare.com/d1/build-databases/query-databases/#await-dbexec){target=_blank}.
25+
1826
### `dump()`
1927

28+
Dumps the entire D1 database to an SQLite compatible file inside an ArrayBuffer.
29+
30+
[Read more on Cloudflare](https://developers.cloudflare.com/d1/build-databases/query-databases/#await-dbdump){target=_blank}.
31+
2032
### `prepare()`
2133

34+
Generates a prepared statement to be used later.
35+
36+
[Read more on Cloudflare](https://developers.cloudflare.com/d1/build-databases/query-databases/#prepared-and-static-statements){target=_blank}.
37+
2238
### `batch()`
39+
40+
Sends a list of prepared statements and get the results in the same order.
41+
42+
[Read more on Cloudflare](https://developers.cloudflare.com/d1/build-databases/query-databases/#dbbatch){target=_blank}.

docs/content/2.usage/2.kv.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ title: KV
33
description: How to use key-value data storage with NuxtHub.
44
---
55

6-
NuxtHub KV is a layer to [Cloudflare Workers KV](https://developers.cloudflare.com/kv), a global, low-latency, key-value data storage.
6+
NuxtHub KV is a layer to [Cloudflare Workers KV](https://developers.cloudflare.com/kv){target=_blank}, a global, low-latency, key-value data storage.
77

88
<!-- TODO: config, binding ? -->
99

1010
Once properly configured, NuxtHub module exposes a server composable to the application.
1111

1212
## `useKV()`
1313

14-
Server composable that returns a [Storage](https://unstorage.unjs.io/getting-started/usage#interface).
14+
Server composable that returns a [Storage](https://unstorage.unjs.io/getting-started/usage#interface){target=_blank}.

docs/content/2.usage/3.blob.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Blob
33
description: How to store objects with NuxtHub.
44
---
55

6-
NuxtHub Blob is a layer to [Cloudflare R2](https://developers.cloudflare.com/r2), allowing to store large amounts of unstructured data.
6+
NuxtHub Blob is a layer to [Cloudflare R2](https://developers.cloudflare.com/r2){target=_blank}, allowing to store large amounts of unstructured data.
77

88
<!-- TODO: config, binding ? -->
99

@@ -45,7 +45,7 @@ export default eventHandler(async (event) => {
4545

4646
#### Params
4747

48-
- `event`: [`H3Event`](https://github.com/unjs/h3)
48+
- `event`: [`H3Event`](https://github.com/unjs/h3){target=_blank}
4949
- `pathname`: `string`
5050

5151
#### Return

docs/content/2.usage/4.analytics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Analytics
33
description: How to track events with NuxtHub.
44
---
55

6-
NuxtHub Analytics is a layer to [Cloudflare Workers Analytics Engine](https://developers.cloudflare.com/analytics/analytics-engine/), allowing to get analytics about anything.
6+
NuxtHub Analytics is a layer to [Cloudflare Workers Analytics Engine](https://developers.cloudflare.com/analytics/analytics-engine/){target=_blank}, allowing to get analytics about anything.
77

88
<!-- TODO: config, binding ? -->
99

docs/content/3.recipes/1.validation.md

+32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ description:
55

66
## Blob
77

8+
To enhance your development experience with blobs, here are some utils:
9+
810
### `ensureBlob()`
911

12+
`ensureBlob()` is a handy util to validate a `Blob` by checking its size and type:
13+
14+
```ts
15+
export default eventHandler(async (event) => {
16+
const form = await readFormData(event)
17+
const file = form.get('file') as Blob
18+
19+
if (!file || !file.size) {
20+
throw createError({ statusCode: 400, message: 'No file provided' })
21+
}
22+
23+
ensureBlob(file, { maxSize: '1MB', types: ['image' ]})
24+
25+
// ...
26+
})
27+
```
28+
29+
#### Params
30+
31+
- `file`: `Blob`
32+
- `options`: `Object`
33+
- `maxSize`: `string`
34+
- `types`: `string[]`
35+
36+
#### Return
37+
38+
Returns nothing.
39+
40+
Throws an error if `file` doesn't meet the requirements.
41+
1042
<!-- TODO -->

docs/content/3.recipes/2.hooks.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ description:
55

66
## Hooks
77

8-
### `onHubReady`
8+
### `onHubReady()`
9+
10+
Use `onHubReady()` to ensure the execution of some code once NuxtHub environment bindings are set.
11+
12+
```ts
13+
onHubReady(async () => {
14+
const myConfig = useKV().getItem('my-config')
15+
// ...
16+
})
17+
```
918

1019
<!-- TODO -->

docs/content/3.recipes/3.drizzle.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Drizzle
3+
description:
4+
---
5+
6+
## Database
7+
8+
To enhance your development experience with databases, we recommand creating this type of composable:
9+
10+
### `useDB()`
11+
12+
```ts
13+
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
14+
import { drizzle } from 'drizzle-orm/d1'
15+
export { sql } from 'drizzle-orm'
16+
17+
const todos = sqliteTable('todos', {
18+
id: integer('id').primaryKey(),
19+
title: text('title').notNull(),
20+
completed: integer('completed').notNull().default(0),
21+
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
22+
})
23+
24+
export const tables = {
25+
todos
26+
}
27+
28+
export function useDB() {
29+
return drizzle(useDatabase(), { schema: tables })
30+
}
31+
```
32+
33+
This allows you to conveniently reference your tables and interact directly with the [Drizzle API](https://orm.drizzle.team/docs/overview).

0 commit comments

Comments
 (0)