This commit is contained in:
16
packages/server/src/db/connection.ts
Normal file
16
packages/server/src/db/connection.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||
import postgres from 'postgres';
|
||||
import * as schema from './schema.js';
|
||||
|
||||
export function createDb(connectionString: string) {
|
||||
const client = postgres(connectionString);
|
||||
return drizzle(client, { schema });
|
||||
}
|
||||
|
||||
export type Db = ReturnType<typeof createDb>;
|
||||
|
||||
/** The transaction handle drizzle passes to `db.transaction(cb)`. */
|
||||
export type DbTransaction = Parameters<Parameters<Db['transaction']>[0]>[0];
|
||||
|
||||
/** A query executor that is either the root db or an open transaction. */
|
||||
export type DbExecutor = Db | DbTransaction;
|
||||
Reference in New Issue
Block a user