import pg from 'pg';
import { DEFAULT_DATABASE_URL } from '../../config/src/index.js';
const { Pool } = pg;
export function createPool(options = {}) {
    return new Pool({
        connectionString: options.connectionString || process.env.DATABASE_URL || DEFAULT_DATABASE_URL,
        max: options.max || 10,
        idleTimeoutMillis: options.idleTimeoutMillis || 30_000,
    });
}
export async function query(pool, sql, params = []) {
    const result = await pool.query(sql, params);
    return result.rows;
}
export async function queryOne(pool, sql, params = []) {
    const rows = await query(pool, sql, params);
    return rows[0] ?? null;
}
