"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemaInspector = void 0;
const knex_1 = __importDefault(require("knex"));
const dotenv_1 = __importDefault(require("dotenv"));
const camelcase_1 = __importDefault(require("camelcase"));
const path_1 = __importDefault(require("path"));
const index_1 = __importDefault(require("../knex-schema-inspector/lib/index"));
dotenv_1.default.config({ path: path_1.default.resolve(__dirname, '../../', '.env') });
const connectionConfig = {};
for (let [key, value] of Object.entries(process.env)) {
    key = key.toLowerCase();
    if (key.startsWith('db') === false)
        continue;
    if (key === 'db_client')
        continue;
    key = key.slice(3); // remove `DB_`
    connectionConfig[camelcase_1.default(key)] = value;
}
const knexConfig = {
    client: process.env.DB_CLIENT,
    connection: connectionConfig,
    migrations: {
        extension: 'ts',
        directory: './src/database/migrations',
    },
    seeds: {
        extension: 'ts',
        directory: './src/database/seeds/',
    },
};
if (process.env.DB_CLIENT === 'sqlite3') {
    knexConfig.useNullAsDefault = true;
}
const database = knex_1.default(knexConfig);
exports.schemaInspector = index_1.default(database);
exports.default = database;
