-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use AsyncLocalStorage for transaction context support #13889
Labels
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
new feature
This change adds new functionality, like a new method or class
Milestone
Comments
ajwootto
added
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
new feature
This change adds new functionality, like a new method or class
labels
Sep 22, 2023
This is a good suggestion, we will investigate how we can support this. |
vkarpov15
added a commit
that referenced
this issue
May 10, 2024
…cally setting `session` on all transactions Fix #13889
vkarpov15
added a commit
that referenced
this issue
May 15, 2024
feat: add `transactionAsyncLocalStorage` option to opt in to automatically setting `session` on all transactions
This was referenced Jun 7, 2024
This was referenced Jul 4, 2024
vkarpov15
added a commit
that referenced
this issue
Jul 19, 2024
feat: add transactionAsyncLocalStorage option to opt in to automatically setting session on all transactions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
new feature
This change adds new functionality, like a new method or class
Prerequisites
🚀 Feature Proposal
A few other ORMs use the NodeJS
AsyncLocalStorage
API to provide a more ergonomic way of using transactions. One example is Sequelize: https://sequelize.org/docs/v7/querying/transactions/#disabling-clsBasically this allows someone to write a bunch of business logic that might span several different function calls etc. while having all the ORM database calls automatically use a transaction that was started earlier in the callstack, without having to pass an object like
session
around and manually provide it to each ORM call.I think this would be a pretty powerful alternative interface for transactions
Motivation
We are writing an API where we have a use-case that requires us to start a transaction at the beginning of every request and then use it for each DB operation that occurs within that request's business logic, before committing the transaction at the end.
Currently that requires us to find our own way to pass the session object around, eg:
but with this proposal you wouldn't need to provide the session:
Example
No response
The text was updated successfully, but these errors were encountered: