import postgres from 'postgres';
import { env } from './env.js';
let sql = null;
export function db() {
    if (!sql) {
        if (!env.DATABASE_URL) {
            throw new Error('DATABASE_URL not configured');
        }
        sql = postgres(env.DATABASE_URL, { max: 10, idle_timeout: 30 });
    }
    return sql;
}
export async function closeDb() {
    if (sql) {
        await sql.end();
        sql = null;
    }
}
//# sourceMappingURL=db.js.map