import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import * as schema from "./schema"; let database: PostgresJsDatabase | undefined; export function getDb() { const url = process.env.DATABASE_URL; if (!url) throw new Error("DATABASE_URL is required for database-backed operations."); database ??= drizzle(postgres(url, { max: Number(process.env.DATABASE_POOL_SIZE ?? 10), prepare: false, connection: { application_name: "gcsim-translator-readonly", }, }), { schema }); return database; }