UNPKG

ts-sql-query

Version:

Type-safe SQL query builder like QueryDSL or JOOQ in Java or Linq in .Net for TypeScript with MariaDB, MySql, Oracle, PostgreSql, Sqlite and SqlServer support.

44 lines (43 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SqlTransactionQueryRunner = void 0; const ManagedTransactionQueryRunner_1 = require("./ManagedTransactionQueryRunner"); class SqlTransactionQueryRunner extends ManagedTransactionQueryRunner_1.ManagedTransactionQueryRunner { constructor() { super(...arguments); this.transactionLevel = 0; } executeBeginTransaction() { return this.executeMutation('begin transaction', []).then(() => { this.transactionLevel++; return undefined; }); } executeCommit() { return this.executeMutation('commit', []).then(() => { // Transaction count only modified when commit successful, in case of error there is still an open transaction this.transactionLevel--; if (this.transactionLevel < 0) { this.transactionLevel = 0; } }); } executeRollback() { return this.executeMutation('rollback', []).then(() => { this.transactionLevel--; if (this.transactionLevel < 0) { this.transactionLevel = 0; } }, (error) => { this.transactionLevel--; if (this.transactionLevel < 0) { this.transactionLevel = 0; } throw error; }); } isTransactionActive() { return this.transactionLevel > 0; } } exports.SqlTransactionQueryRunner = SqlTransactionQueryRunner;