Files

14 lines
362 B
TypeScript

import postgres from "postgres";
let _sql: ReturnType<typeof postgres> | null = null;
/** Lazily-created shared postgres.js connection pool. */
export function getSql() {
if (!_sql) {
const url = process.env.DATABASE_URL;
if (!url) throw new Error("DATABASE_URL not set");
_sql = postgres(url, { max: 5, idle_timeout: 30 });
}
return _sql;
}