Skip to content

Commit

Permalink
feat(docs): add drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Dec 22, 2023
1 parent 126d345 commit e7216b0
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 16 deletions.
19 changes: 3 additions & 16 deletions .docs/content/pergel/3.nuxt/bullmq/1.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,8 @@ pergel install

:read-more{title="Install Pergel CLI" to="/pergel/cli"}

4. Prepare Type Definitions:

::code-group
```sh [pnpm]
pnpm nuxt prepare
```
```sh [npm]
npm run nuxt prepare
```
```sh [yarn]
yarn nuxt prepare
```
::

5. Add your server plugin:
4. Add your server plugin:

This code blog is a listener.

Expand Down Expand Up @@ -124,7 +111,7 @@ pergelMyproject().bullmq().nitroPlugin({})
::


6. Use anywhere server side:
5. Use anywhere server side:

::code-group
```ts [server/api/test.ts]
Expand Down Expand Up @@ -164,7 +151,7 @@ export default defineEventHandler(async () => {
```
::

7. Add .env file
6. Add .env file

Root directory of your project `pergel` folder inside `README.yaml` file. Check for `projectName` and `S3` section.

Expand Down
144 changes: 144 additions & 0 deletions .docs/content/pergel/3.nuxt/drizzle/1.installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
title: Installation
description: 'Pergel Nuxt Module for Drizzle'
links:
- label: 'drizzle-orm'
icon: i-simple-icons-npm
to: https://www.npmjs.com/package/drizzle-orm
---

- Auto generate environment variables
- Auto up database dev mode
- Auto import `tables[projectName]`
- Compile time type safety
- ClI support
- Studio support
- Nuxt Devtools support
- Auto import support `eq`, `like` and more
- Auto generated folders `schema`, `migrations`, `seed`


1. Project configuration:


::code-group
```ts [nuxt.config.ts]
export default defineNuxtConfig({
modules: ['@pergel/nuxt'],
pergel: {
projects: {
myproject: {
// ... other modules
// driver default postgresjs:pg
drizzle: true, // or { driver: 'postgresjs:pg' }
},
// bookList: {
// ses: false
// },
},
},
})
```
::

::callout{color="amber" icon="i-ph-warning-duotone"}
Currently supports default `postgresjs`. You can send pr for different db or open issua.
::

::callout{color="amber" icon="i-ph-warning-duotone"}
Node >= 20.8.0 is required.
Nuxt >= 3.9.0 is required.
::

2. Type Generation and `pergel/README.yaml` generation:

::code-group
```sh [pnpm]
pnpm nuxt prepare
```
```sh [npm]
npm run nuxt prepare
```
```sh [yarn]
yarn nuxt prepare
```
::

3. Auto install dependencies:

::code-group
```sh [terminal]
pergel install
```
```sh [terminal]
# pergel cli upgrade.Make sure it is always up to date.
pnpm i -g pergel
npm i -g pergel
yarn global add pergel
```
::

:read-more{title="Install Pergel CLI" to="/pergel/cli"}

::callout{icon="i-ph-info" color="yellow"}
Check your `pergel/[projectName]/drizzle`

Check following files:

- [ ] `pergel/[projectName]/drizzle/schema/index.ts`
- [ ] `pergel/[projectName]/drizzle/seed/index.ts`
- [ ] `pergel/[projectName]/drizzle/drizzle.config.ts`
::


4. Add your api handler and use it:

Let's showcase an example use. `tables[projectName]` is automatically generated.

::code-group
```ts [server/api/test.ts]
export default defineEventHandler(async () => {
const connect = await pergelTest().drizzle().postgresjs().connect({})
const result = await connect.select().from(tablesMyproject.user)
return {
statusCode: 200,
body: JSON.stringify(result),
}
})
```
::


5. Add .env file

Root directory of your project `pergel` folder inside `README.yaml` file. Check for `projectName` and `drizzle` section.

::code-group
```sh [.env]
# You see this in your README.yaml file
env:
NUXT_MYPROJECT_DRIZZLE_PG_URL:
...

# Copy and change `:` to `=` and add your credentials
NUXT_MYPROJECT_BULLMQ_OPTIONS_HOST=
...
```
::

::callout{icon="i-ph-check-circle-duotone" color="green"}
Well done! You have successfully installed the module.
::

::callout{icon="i-ph-check-circle-duotone" color="yellow"}
Scripts

Root directory of your project `pergel` folder inside `README.yaml` file. Check for `projectName` and `drizzle` section.

You can copy your scripts to package.json if you want. Or you can run them via cli. Check `scripts` and `cli` in `README.yaml` file.
::

::callout{icon="i-ph-check-circle-duotone" color="yellow"}
More information about the module [API](./2.api.md)
::

77 changes: 77 additions & 0 deletions .docs/content/pergel/3.nuxt/drizzle/2.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: API
description: 'Pergel Nuxt Module for Drizzle API'
links:
- label: 'drizzle-orm'
icon: i-simple-icons-npm
to: https://www.npmjs.com/package/drizzle-orm
---

::callout{icon="i-ph-warning-duotone" color="amber"}
Project name `pergelMyproject` is used as an example. Please change it to your project name.
::


## Configuration

```ts
/**
* Postres.js database
* @link https://github.com/porsager/postgres
* @default 'postgresjs:pg'
*/
driver?: 'postgresjs:pg'

/**
* Database schemas
* @default 'pergel/{projectName}/{moduleName}/schema'
*/
schemaPath?: string

/**
* Database migrations
* @default 'pergel/{projectName}/{moduleName}/migrations'
*/
migrationsPath?: string

/**
* Merge schemas
* @default true
*/
mergeSchemas?: boolean

autoImportPrefix?: {
filters: string
}

/**
* Database seeds
* @default true
*/
studio?: false

dev?: {
/**
* Database seeds
* @default 'pergel orm -s=push -p={projectName}''
*/
cli?: string | false
}
```

## Usage

### Client
`connect` method returns `Promise<Drizzle>`

```ts
const client = await pergelTest().drizzle().postgresjs().connect({})
```

### Schema

```ts
pergelTest().drizzle().schema.[tableName].user
// or auto import
tables[projectName].user
```
2 changes: 2 additions & 0 deletions .docs/content/pergel/3.nuxt/drizzle/_dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: drizzle
icon: i-carbon-rain-drizzle

0 comments on commit e7216b0

Please sign in to comment.