feat: add db.ts
This commit is contained in:
parent
4bddb6cc34
commit
0a344f2dc3
1 changed files with 31 additions and 0 deletions
31
db.ts
Normal file
31
db.ts
Normal 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);
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue