← back to Ventura Corridor
db/pool.ts
26 lines
/**
* PG connection pool — single instance, used everywhere.
* Reads DATABASE_URL from .env (Unix-socket path on local Mac).
*/
import 'dotenv/config';
import pg from 'pg';
const { Pool } = pg;
export const pool = new Pool({
connectionString: process.env.DATABASE_URL || 'postgresql:///ventura_corridor?host=/tmp',
max: 8,
idleTimeoutMillis: 30_000,
});
pool.on('error', (err) => {
console.error('[pg pool error]', err);
});
export async function query<T extends pg.QueryResultRow = pg.QueryResultRow>(
text: string,
params?: unknown[],
): Promise<pg.QueryResult<T>> {
return pool.query<T>(text, params);
}