add services/worker/src/db/client.js

This commit is contained in:
Zac Gaetano 2026-04-07 21:58:20 -04:00
parent 76e15b4b76
commit 9e2833ba85

View file

@ -0,0 +1,30 @@
import pg from 'pg';
const { Pool } = pg;
let pool;
export const getPool = () => {
if (!pool) {
pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
}
return pool;
};
export const query = async (text, params) => {
const client = await getPool().connect();
try {
return await client.query(text, params);
} finally {
client.release();
}
};
export const closePool = async () => {
if (pool) {
await pool.end();
pool = null;
}
};