Abort DB operations / Transaction using AbortSignal
See original GitHub issueFeature Description
The Problem
Aborting DB operations is useful when the user abort some request when the DB operation is no longer needed (e.g. getting result for autocomplete and then the user type more characters (this is not my use case but rather a common use case that need the abort feature))
The Solution
Using AbortSignal
to abort DB operation and transaction.
There are 2 approaches I have in mind:
- Passing signal
- Returning object with abort function
I prefer the 1st option as it keep the library usage design
Usage
When I use
signal
in the below example I mean anAbortSignal
instance
Repository
and EntityManager
userRepository.find({
withDeleted: true,
signal,
});
QueryBuilder
const firstUser = await connection
.getRepository(User)
.createQueryBuilder("user")
.where("user.id = :id", { id: 1 })
// here:
.addSignal(signal)
.getOne();
Transactions
Using Connection or EntityManager:
// An isolation level can be passed in the object near the signal property
await getManager().transaction({ signal }, async transactionalEntityManager => {
});
Using QueryRunner
:
await queryRunner.startTransaction({ signal });
Using decorators: How this should be used? Maybe can set the abort signal on the passed manager
Passing the signal to the DB transaction will abort the transaction when the signal abort emit, passing
Considered Alternatives
Additional Context
Relevant Database Driver(s)
All of them basically
Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Node 12’s Maintenance support ends on 2022-04-30 (66 days from now).
Work on this feature could begin now and wait to be merged until after Node 12’s EOL, since it is relatively near.
Every place that I see there isn’t any fluent interface around
AbortSignal
it’s mostly simply passing signal as part of the options of a given function that execute operations.Is still any plan to support this feature?