UNPKG

ts-firebird

Version:
61 lines 2.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_firebird_1 = require("node-firebird"); const util_1 = require("util"); const firebird_transaction_1 = __importDefault(require("./firebird.transaction")); class FirebirdDatabase { constructor(db = null) { this.db = db; } async attach(options) { this.db = await (0, util_1.promisify)(node_firebird_1.attach)(options); return this; } async create(options) { this.db = await (0, util_1.promisify)(node_firebird_1.create)(options); return this; } async attachOrCreate(options) { this.db = await (0, util_1.promisify)(node_firebird_1.attachOrCreate)(options); return this; } static async buildAndAttach(options) { const fd = new FirebirdDatabase(); return fd.attach(options); } checkDb() { if (!this.db) throw new Error('Database is null'); } detach() { this.checkDb(); this.db.detach(); } async query(query, params, detach = false) { this.checkDb(); const asyncQuery = (0, util_1.promisify)(this.db.query); const res = await asyncQuery.call(this.db, query, params); if (detach) this.detach(); return res; } async execute(query, params, detach = false) { this.checkDb(); const asyncExecute = (0, util_1.promisify)(this.db.execute); const res = await asyncExecute.call(this.db, query, params); if (detach) this.detach(); return res; } async transaction(isolation = node_firebird_1.ISOLATION_READ_COMMITTED) { this.checkDb(); const transaction = new firebird_transaction_1.default(this.db, isolation); await transaction.init(); return transaction; } } exports.default = FirebirdDatabase; //# sourceMappingURL=firebird.database.js.map