Problem
First, a disclaimer: AsyncLocalStorage is not available in all supported versions of Node.js yet but this can either be discussed for the future or there are ways of having similar APIs in older version sof Node.js depending on the choices made.
Right now (if I understand the doc well), to build a transaction, one must keep a list of writes and commit all of them at once at the end. So let's imagine in a web server, when the user wants all the db writes linked with the HTTP requests to be in the same transaction, they would have to do something like attaching an array to a request object or something like that, add all the writes to it and commit before the response with prisma.$transaction(...).
Suggested solution
Using an API like AsyncLocalStorage can give the following UX:
prisma.$openTransaction()
...
write_1
...
write_n
prisma.$commitTransaction() <- all the writes are automatically linked with the current transaction
This has a few shortcomings:
Alternatives
N/A
Additional context
So I am mostly trying the water to see if there would be interest and what would be the feedback over here on such feature :)
Problem
First, a disclaimer:
AsyncLocalStorageis not available in all supported versions of Node.js yet but this can either be discussed for the future or there are ways of having similar APIs in older version sof Node.js depending on the choices made.Right now (if I understand the doc well), to build a transaction, one must keep a list of writes and commit all of them at once at the end. So let's imagine in a web server, when the user wants all the db writes linked with the HTTP requests to be in the same transaction, they would have to do something like attaching an array to a request object or something like that, add all the writes to it and commit before the response with
prisma.$transaction(...).Suggested solution
Using an API like AsyncLocalStorage can give the following UX:
This has a few shortcomings:
Alternatives
N/A
Additional context
So I am mostly trying the water to see if there would be interest and what would be the feedback over here on such feature :)