"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.connectDatabase = void 0;
const sequelize_1 = require("sequelize");
exports.connectDatabase = (options) => __awaiter(void 0, void 0, void 0, function* () {
    const { host, username, password, database, logging } = options;
    // Use port 5432 by default
    const port = options.port || 5432;
    // Connect to the database
    const sequelize = new sequelize_1.Sequelize({
        dialect: 'postgres',
        host,
        port,
        username,
        password,
        database,
        pool: {
            max: 10,
            min: 0,
        },
        logging,
    });
    // Test the connection
    yield sequelize.authenticate();
    // All good, return the connection
    return sequelize;
});
//# sourceMappingURL=index.js.map