Skip to content

Commit

Permalink
Add transactor.baseExecutionPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
caseywebdev committed May 10, 2023
1 parent b6d04f7 commit 629e994
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/execution/transaction.js
Expand Up @@ -219,6 +219,10 @@ class Transaction extends EventEmitter {
return makeTransactor(this, connection, trxClient);
})
.then((transactor) => {
this.baseExecutionPromise = transactor.baseExecutionPromise = this
.outerTx
? this.outerTx.baseExecutionPromise
: executionPromise;
transactor.executionPromise = executionPromise;

// If we've returned a "thenable" from the transaction container, assume
Expand Down
18 changes: 18 additions & 0 deletions test/integration/execution/transaction.js
Expand Up @@ -810,5 +810,23 @@ module.exports = function (knex) {
// closed it. (Ex: this was the case for OracleDB before fixing #3721)
});
});

it('exposes baseExecutionPromise', async function () {
let baseExecutionPromise;
await knex.transaction(async function (trx1) {
expect(trx1.baseExecutionPromise).to.equal(trx1.executionPromise);
await trx1.transaction(async function (trx2) {
expect(trx2.baseExecutionPromise).to.equal(trx1.executionPromise);
await trx1.transaction(async function (trx3) {
baseExecutionPromise = trx3.baseExecutionPromise;
expect(baseExecutionPromise).to.equal(trx1.executionPromise);
await trx3.select(1);
});
await expect(baseExecutionPromise).to.not.have.been.resolved;
});
await expect(baseExecutionPromise).to.not.have.been.resolved;
});
await expect(baseExecutionPromise).to.have.been.resolved;
});
});
};

0 comments on commit 629e994

Please sign in to comment.