feat: db connection and migration
This commit is contained in:
13
server/utils/db.ts
Normal file
13
server/utils/db.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user