2026-05-22 12:25:41 +00:00
|
|
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
|
|
|
import postgres from 'postgres';
|
|
|
|
|
import { env } from '../config/env';
|
|
|
|
|
import * as schema from './schema';
|
|
|
|
|
|
2026-05-22 14:26:13 +00:00
|
|
|
let db: ReturnType<typeof drizzle<typeof schema>> | undefined;
|
|
|
|
|
|
2026-05-22 12:25:41 +00:00
|
|
|
export function createDbClient() {
|
|
|
|
|
if (!env.databaseUrl) {
|
|
|
|
|
throw new Error('DATABASE_URL is required to create a database client');
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 14:26:13 +00:00
|
|
|
db ??= drizzle(postgres(env.databaseUrl), { schema });
|
|
|
|
|
return db;
|
2026-05-22 12:25:41 +00:00
|
|
|
}
|