Files
red/teressa-copeland-homes/src/lib/db/index.ts
Chandler Copeland fa7d6a9636 feat(17-01): enable standalone output, limit DB pool to 5, remove @vercel/blob
- Add output: 'standalone' to next.config.ts for Docker three-stage build
- Change postgres(url) to postgres(url, { max: 5 }) to avoid Neon free tier exhaustion
- Remove dead @vercel/blob dependency (imported nowhere in codebase)
2026-04-03 16:53:18 -06:00

25 lines
702 B
TypeScript

import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
type DrizzleDb = ReturnType<typeof createDb>;
function createDb() {
const url = process.env.DATABASE_URL;
if (!url) {
throw new Error("DATABASE_URL environment variable is not set");
}
const client = postgres(url, { max: 5 });
return drizzle({ client, schema });
}
// Lazy singleton — created on first use, not at module load time
let _db: DrizzleDb | undefined;
export const db = new Proxy({} as DrizzleDb, {
get(_target, prop: string | symbol) {
if (!_db) _db = createDb();
return (_db as unknown as Record<string | symbol, unknown>)[prop];
},
});