blob: db001b76dc165c36bd8bc3fcc221a7a9ab1c0ba9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import pg from "pg";
import { env } from "$env/dynamic/private";
const pool = new pg.Pool({
database: env.POSTGRES_DB || "postgres",
user: env.POSTGRES_USERNAME || "postgres",
host: env.POSTGRES_HOST || "localhost",
port: Number(env.POSTGRES_PORT || 5432),
});
// Prevent errors in idle clients from terminating Node process.
// See: https://node-postgres.com/features/pooling
// See: https://nodejs.org/api/events.html#error-events
pool.on("error", (err, client) => {
console.error("Database error: ", err, client);
});
export function getDbClient(): Promise<pg.PoolClient> {
return pool.connect();
}
|