"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
var knex_1 = require("knex");
var env_js_1 = require("../config/env.js");
exports.db = (0, knex_1.default)({
    client: env_js_1.env.DB_CLIENT,
    connection: {
        host: env_js_1.env.DB_HOST,
        port: env_js_1.env.DB_PORT,
        database: env_js_1.env.DB_NAME,
        user: env_js_1.env.DB_USER,
        password: env_js_1.env.DB_PASSWORD,
        ssl: env_js_1.env.DB_SSL ? { rejectUnauthorized: false } : false,
    },
    pool: {
        min: 0,
        max: 10,
        afterCreate: function (connection, done) {
            var _a;
            var clientName = String((_a = env_js_1.env.DB_CLIENT) !== null && _a !== void 0 ? _a : '').toLowerCase();
            if (clientName === 'pg' || clientName === 'postgres' || clientName === 'postgresql') {
                connection.query("SET TIME ZONE '".concat(env_js_1.env.DB_TIME_ZONE, "'"), function (error) {
                    done(error, connection);
                });
                return;
            }
            if (clientName === 'mysql' || clientName === 'mysql2') {
                connection.query('SET time_zone = "+09:00"', function (error) {
                    done(error, connection);
                });
                return;
            }
            done(null, connection);
        },
    },
});
