18 lines
439 B
TypeScript
18 lines
439 B
TypeScript
import pg from 'pg';
|
|
import type { QueryResult, QueryResultRow } from 'pg';
|
|
|
|
const pool = new pg.Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
});
|
|
|
|
export const query = <R extends QueryResultRow = QueryResultRow>(
|
|
text: string,
|
|
params?: unknown[]
|
|
): Promise<QueryResult<R>> => pool.query<R>(text, params);
|
|
|
|
export const getPool = (): pg.Pool => pool;
|
|
|
|
export const close = (): Promise<void> => pool.end();
|
|
|
|
export default pool;
|