mirror of
https://github.com/knex/knex.git
synced 2025-06-26 22:00:25 +00:00
Add transactor.parentTransaction (#5567)
This commit is contained in:
parent
770b2f20ac
commit
d908f09d17
@ -219,6 +219,10 @@ class Transaction extends EventEmitter {
|
|||||||
return makeTransactor(this, connection, trxClient);
|
return makeTransactor(this, connection, trxClient);
|
||||||
})
|
})
|
||||||
.then((transactor) => {
|
.then((transactor) => {
|
||||||
|
this.transactor = transactor;
|
||||||
|
if (this.outerTx) {
|
||||||
|
transactor.parentTransaction = this.outerTx.transactor;
|
||||||
|
}
|
||||||
transactor.executionPromise = executionPromise;
|
transactor.executionPromise = executionPromise;
|
||||||
|
|
||||||
// If we've returned a "thenable" from the transaction container, assume
|
// If we've returned a "thenable" from the transaction container, assume
|
||||||
|
@ -810,5 +810,27 @@ module.exports = function (knex) {
|
|||||||
// closed it. (Ex: this was the case for OracleDB before fixing #3721)
|
// closed it. (Ex: this was the case for OracleDB before fixing #3721)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('exposes the parent transaction', async () => {
|
||||||
|
await knex.transaction(async (trx1) => {
|
||||||
|
expect(trx1.parentTransaction).to.equal(undefined);
|
||||||
|
|
||||||
|
await trx1.transaction(async (trx2) => {
|
||||||
|
expect(trx2.parentTransaction).to.equal(trx1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await trx1.transaction(async (trx2) => {
|
||||||
|
expect(trx2.parentTransaction).to.equal(trx1);
|
||||||
|
|
||||||
|
await trx2.transaction(async (trx3) => {
|
||||||
|
expect(trx3.parentTransaction).to.equal(trx2);
|
||||||
|
});
|
||||||
|
|
||||||
|
await trx2.transaction(async (trx3) => {
|
||||||
|
expect(trx3.parentTransaction).to.equal(trx2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
@ -2323,6 +2323,7 @@ declare namespace Knex {
|
|||||||
interface Transaction<TRecord extends {} = any, TResult = any[]>
|
interface Transaction<TRecord extends {} = any, TResult = any[]>
|
||||||
extends Knex<TRecord, TResult> {
|
extends Knex<TRecord, TResult> {
|
||||||
executionPromise: Promise<TResult>;
|
executionPromise: Promise<TResult>;
|
||||||
|
parentTransaction?: Transaction;
|
||||||
isCompleted: () => boolean;
|
isCompleted: () => boolean;
|
||||||
|
|
||||||
query<TRecord extends {} = any, TResult = void>(
|
query<TRecord extends {} = any, TResult = void>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user