"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
class DB {
    constructor(configDir, dbName) {
        if (!fs_1.default.existsSync(configDir)) {
            fs_1.default.mkdirSync(configDir, { recursive: true });
        }
        this.db = new better_sqlite3_1.default(path_1.default.join(configDir, `${dbName}.db`));
    }
    get(sql, params) {
        return this.db.prepare(sql).get(...params);
    }
    all(sql, params) {
        return this.db.prepare(sql).all(...params);
    }
    run(sql, args) {
        args = args || [];
        return this.db.prepare(sql).run(...args);
    }
    upsert(table, data) {
        let sql = `REPLACE INTO ${table} `;
        sql += `(${Object.keys(data).join(", ")}) VALUES `;
        sql += `(${Object.values(data)
            .map((n) => "?")
            .join(", ")});`;
        return this.run(sql, Object.values(data));
    }
}
exports.default = DB;
//# sourceMappingURL=db.js.map