From 629e994670f1ce9656ccc1b157506e1d4848fcad Mon Sep 17 00:00:00 2001 From: Casey Foster Date: Wed, 10 May 2023 09:32:26 -0500 Subject: [PATCH] Add transactor.baseExecutionPromise --- lib/execution/transaction.js | 4 ++++ test/integration/execution/transaction.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/execution/transaction.js b/lib/execution/transaction.js index 40532cfc0c..f75c7b4ef4 100644 --- a/lib/execution/transaction.js +++ b/lib/execution/transaction.js @@ -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 diff --git a/test/integration/execution/transaction.js b/test/integration/execution/transaction.js index 8524ef9be8..e46802affb 100644 --- a/test/integration/execution/transaction.js +++ b/test/integration/execution/transaction.js @@ -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; + }); }); };