-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
126d345
commit e7216b0
Showing
4 changed files
with
226 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
:: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
title: drizzle | ||
icon: i-carbon-rain-drizzle |