-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages/drizzledb-pg): initial drizzle postgres database library (
#29)
- Loading branch information
1 parent
a15c09b
commit f142514
Showing
13 changed files
with
1,243 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,6 @@ vite.config.ts.timestamp-* | |
|
||
# vercel | ||
.vercel/ | ||
|
||
# local docker volumes | ||
/.docker/ |
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,30 @@ | ||
services: | ||
postgres: | ||
image: postgres:16.2-alpine | ||
restart: always | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres | ||
- POSTGRES_DB=postgres | ||
logging: | ||
options: | ||
max-size: 10m | ||
max-file: '3' | ||
ports: | ||
- '5432:5432' | ||
volumes: | ||
- ./.docker/pg-data:/var/lib/postgresql/data | ||
|
||
mailpit: | ||
image: axllent/mailpit | ||
restart: always | ||
environment: | ||
MP_MAX_MESSAGES: 5000 | ||
MP_DATA_FILE: /data/mailpit.db | ||
MP_SMTP_AUTH_ACCEPT_ANY: 1 | ||
MP_SMTP_AUTH_ALLOW_INSECURE: 1 | ||
ports: | ||
- 8025:8025 | ||
- 1025:1025 | ||
volumes: | ||
- ./.docker/mailpit-data:/data |
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,45 @@ | ||
import { defineConfig } from 'drizzle-kit' | ||
|
||
export default defineConfig({ | ||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#out | ||
*/ | ||
out: './drizzle', | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#schema | ||
*/ | ||
schema: './src/schema/*', | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#breakpoints | ||
*/ | ||
breakpoints: false, | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#verbose | ||
*/ | ||
verbose: true, | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#strict | ||
*/ | ||
strict: true, | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#schemafilter | ||
*/ | ||
schemaFilter: ['public'], | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#driver | ||
*/ | ||
driver: 'pg', | ||
|
||
/** | ||
* https://orm.drizzle.team/kit-docs/config-reference#driver | ||
*/ | ||
dbCredentials: { | ||
connectionString: process.env.DB_CONNECTION_STRING, | ||
}, | ||
}) |
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,3 @@ | ||
import config from '@toolchain/eslint-config/profile/node' | ||
|
||
export default config |
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,39 @@ | ||
{ | ||
"name": "@packages/drizzledb-pg", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Drizzle ORM Database Client and Schema for PostgreSQL", | ||
"license": "UNLICENSED", | ||
"type": "module", | ||
"exports": { | ||
"./client": "./src/client/index.ts", | ||
"./schema": "./src/schema/index.ts" | ||
}, | ||
"scripts": { | ||
"clean": "del .turbo coverage", | ||
"db:generate": "drizzle-kit generate:pg", | ||
"db:migrate": "node --env-file=.env --import=tsx ./src/migrate.ts", | ||
"db:push": "drizzle-kit push:pg", | ||
"db:studio": "drizzle-kit studio", | ||
"lint": "eslint .", | ||
"test": "vitest run", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"dotenv": "16.4.5", | ||
"drizzle-orm": "0.30.4", | ||
"postgres": "3.4.4", | ||
"znv": "0.4.0", | ||
"zod": "3.22.4" | ||
}, | ||
"devDependencies": { | ||
"@toolchain/eslint-config": "workspace:*", | ||
"@toolchain/typescript-config": "workspace:*", | ||
"@toolchain/vitest-config": "workspace:*", | ||
"@types/node": "20.11.30", | ||
"@types/pg": "8.11.4", | ||
"drizzle-kit": "0.20.14", | ||
"pg": "8.11.3", | ||
"tsx": "4.7.1" | ||
} | ||
} |
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 @@ | ||
export { db } from './postgresjs-client.js' |
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,19 @@ | ||
import { drizzle } from 'drizzle-orm/postgres-js' | ||
import postgres from 'postgres' | ||
import { parseEnv, z } from 'znv' | ||
|
||
import 'dotenv/config' | ||
|
||
const { DB_CONNECTION_STRING, DB_MAX_CONNECTIONS } = parseEnv(process.env, { | ||
DB_CONNECTION_STRING: z.string().url().default('postgresql://undefined'), | ||
DB_MAX_CONNECTIONS: z.number().min(1).default(1), | ||
}) | ||
|
||
export const connection = postgres(DB_CONNECTION_STRING, { | ||
max: DB_MAX_CONNECTIONS, | ||
connection: { | ||
application_name: 'postgres.js', | ||
}, | ||
}) | ||
|
||
export const db = drizzle(connection) |
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,17 @@ | ||
import { migrate } from 'drizzle-orm/postgres-js/migrator' | ||
|
||
import { connection, db } from './client/postgresjs-client.js' | ||
|
||
try { | ||
console.log('Drizzle database migration starting...') | ||
|
||
await migrate(db, { | ||
migrationsFolder: './drizzle', | ||
}) | ||
|
||
console.log('Drizzle database migration completed successfully!') | ||
} catch (err) { | ||
console.log('Drizzle database migrations failed!', err) | ||
} finally { | ||
await connection.end() | ||
} |
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 @@ | ||
export { count } from 'drizzle-orm' |
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,6 @@ | ||
{ | ||
"extends": "./node_modules/@toolchain/typescript-config/tsconfig-base.json", | ||
"compilerOptions": { | ||
"types": ["vitest/globals"] | ||
} | ||
} |
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,15 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies -- (as designed, vite is hoisted and available globally) | ||
import { defineConfig, mergeConfig } from 'vitest/config' | ||
|
||
import sharedConfig from '@toolchain/vitest-config' | ||
|
||
import packageJson from './package.json' | ||
|
||
export default mergeConfig( | ||
sharedConfig, | ||
defineConfig({ | ||
test: { | ||
name: packageJson.name, | ||
}, | ||
}), | ||
) |
Oops, something went wrong.