UNPKG

inceptum

Version:

hipages take on the foundational library for enterprise-grade apps written in NodeJS

55 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class DBTransaction { /** * * @param transaction */ constructor(transaction) { this.rolledBack = false; this.transaction = transaction; } async begin() { await this.doTransactionBegin(); this.transaction.begin(); this.transaction.addCommitListener(() => this.doTransactionCommit()); this.transaction.addRollbackListener(() => this.doTransactionRollback()); this.transaction.addEndListener(() => this.doTransactionEnd()); } query(sql, ...bindArrs) { return this.runQueryPrivate(sql, bindArrs); } queryAssoc(sql, bindObj) { return this.runQueryAssocPrivate(sql, bindObj); } doTransactionBegin() { return this.runQueryPrivate(this.getTransactionBeginSQL()); } // tslint:disable-next-line:prefer-function-over-method getTransactionBeginSQL() { return 'BEGIN'; } doTransactionCommit() { return this.runQueryPrivate(this.getTransactionCommitSQL()); } // tslint:disable-next-line:prefer-function-over-method getTransactionCommitSQL() { return 'COMMIT'; } doTransactionRollback() { this.rolledBack = true; return this.runQueryPrivate(this.getTransactionRollbackSQL()); } // tslint:disable-next-line:prefer-function-over-method getTransactionRollbackSQL() { return 'ROLLBACK'; } async end() { await this.transaction.end(); } isRolledBack() { return this.rolledBack; } } exports.DBTransaction = DBTransaction; //# sourceMappingURL=DBTransaction.js.map