"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPool = getPool;
exports.closePool = closePool;
exports.getConnection = getConnection;
const pg_1 = require("pg");
const config_1 = require("../../modules/config");
let pool = null;
function getPool() {
    if (!pool) {
        pool = new pg_1.Pool(config_1.postgres_options);
    }
    return pool;
}
async function closePool() {
    if (pool) {
        await pool.end();
        pool = null;
    }
}
/**
 * HotMesh connection descriptor: `{ class: Client, options: postgres_options }`.
 * Use this everywhere HotMesh / Durable APIs need a connection config
 * instead of importing `pg` and `postgres_options` directly.
 */
function getConnection() {
    return { class: pg_1.Client, options: config_1.postgres_options };
}
