From 5581db398320765081ac97c04291365370d189dc Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Sun, 7 Jul 2024 13:20:28 +0800 Subject: [PATCH] chore(db): add type --- packages/db/package.json | 3 ++- packages/db/src/db.ts | 6 +++++- pnpm-lock.yaml | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/db/package.json b/packages/db/package.json index 4d664789..195fe151 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -19,6 +19,7 @@ "pg": "^8.11.5" }, "dependencies": { - "postgres": "^3.4.4" + "postgres": "^3.4.4", + "@earthworm/schema": "workspace:^" } } diff --git a/packages/db/src/db.ts b/packages/db/src/db.ts index 1a1a501e..033ffedb 100644 --- a/packages/db/src/db.ts +++ b/packages/db/src/db.ts @@ -4,10 +4,14 @@ import dotenv from "dotenv"; import { drizzle } from "drizzle-orm/postgres-js"; import postgres from "postgres"; +import { schemas } from "@earthworm/schema"; + const envName = process.env.NODE_ENV === "prod" ? ".env.prod" : ".env"; dotenv.config({ path: path.resolve(__dirname, `../../../apps/api/${envName}`) }); console.log("connection string: ", process.env.DATABASE_URL); const connection = postgres(process.env.DATABASE_URL ?? ""); -export const db = drizzle(connection); +export const db = drizzle(connection, { + schema: schemas, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee80277b..de011105 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -360,6 +360,9 @@ importers: packages/db: dependencies: + '@earthworm/schema': + specifier: workspace:^ + version: link:../schema postgres: specifier: ^3.4.4 version: 3.4.4