feat: add db.ts

This commit is contained in:
gitadmin 2026-05-02 13:07:29 +00:00
parent 4bddb6cc34
commit 0a344f2dc3

31
db.ts Normal file
View file

@ -0,0 +1,31 @@
import pg from "pg";
const { Pool } = pg;
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL must be set. Provision a Postgres database and set DATABASE_URL.");
}
export const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 15,
idleTimeoutMillis: 30_000,
connectionTimeoutMillis: 8_000,
keepAlive: true,
keepAliveInitialDelayMillis: 10_000,
});
pool.on("error", (err) => {
console.error("[db:pool] idle client error:", err.message);
});
export const bgPool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
idleTimeoutMillis: 20_000,
connectionTimeoutMillis: 10_000,
keepAlive: true,
});
bgPool.on("error", (err) => {
console.error("[db:bgPool] idle client error:", err.message);
});