Add Drizzle ORM with shared db package (#10)
This commit is contained in:
parent
6a3e566438
commit
9deda5f125
13 changed files with 783 additions and 109 deletions
17
packages/db/src/index.ts
Normal file
17
packages/db/src/index.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import * as plannerSchema from "./schema/planner";
|
||||
import * as journalSchema from "./schema/journal";
|
||||
|
||||
export function createDb(connectionString?: string) {
|
||||
const client = postgres(
|
||||
connectionString ?? process.env.DATABASE_URL ?? "postgres://trails:trails@localhost:5432/trails",
|
||||
);
|
||||
return drizzle(client, {
|
||||
schema: { ...plannerSchema, ...journalSchema },
|
||||
});
|
||||
}
|
||||
|
||||
export type Database = ReturnType<typeof createDb>;
|
||||
|
||||
export { plannerSchema, journalSchema };
|
||||
Loading…
Add table
Add a link
Reference in a new issue