"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Sqlite = require("sqlite3");
class DB {
    open(path) {
        return new Promise((resolve, reject) => {
            this.db = new (Sqlite.verbose()).Database(path, Sqlite.OPEN_READWRITE, error => {
                if (error) {
                    reject(error);
                }
                else {
                    resolve();
                }
            });
        });
    }
    close() {
        return new Promise((resolve, reject) => {
            var _a;
            (_a = this.db) === null || _a === void 0 ? void 0 : _a.close(error => {
                if (error) {
                    reject(error);
                }
                else {
                    resolve();
                }
            });
        });
    }
    update(sql, values) {
        return new Promise((resolve, reject) => {
            var _a;
            (_a = this.db) === null || _a === void 0 ? void 0 : _a.serialize(() => {
                var _a, _b, _c, _d;
                if (values) {
                    const stmt = (_a = this.db) === null || _a === void 0 ? void 0 : _a.prepare(sql);
                    (_b = stmt) === null || _b === void 0 ? void 0 : _b.run(...values);
                    (_c = stmt) === null || _c === void 0 ? void 0 : _c.finalize();
                    resolve();
                }
                else {
                    (_d = this.db) === null || _d === void 0 ? void 0 : _d.run(sql);
                    resolve();
                }
            });
        });
    }
}
exports.DB = DB;
//# sourceMappingURL=db.js.map