Replies: 2 comments 2 replies
-
|
This should probably be moved to the |
Beta Was this translation helpful? Give feedback.
-
|
When I saw this, I thought it was a great idea, so I implemented it with some extras (savepoints + "safe mode"). Here's my opinion after doing so:
In node v24+, the performance impact is non-existent. In older versions, it's about ~7-20% cpu overhead (older versions being much worse). This typically equates to only added ms and is probably not noticeable compared to IO overhead. However, I think I'd like to do my own performance tests at some point against in memory database instances. If you have any pointers, let me know!
As per my answer above: maybe this should be a plugin as performance is determined by the chosen runtime. Once node 24 becomes the next LTS, it should probably be added in.
Some common pitfalls can happen, which is why I implemented "safe mode" (naming? maybe debug mode?).
I've implemented some workarounds that log the error as a warning. This is meant to lead a developer to fix these problems. When safe mode is off, these are thrown as errors.
To be honest, this was probably the hardest thing to implement. I think I did a decent job since the database is correctly interfaced between a union type of Postgres, MySQL, and SQLite with a function overloading type to differentiate the three. From what I'm seeing: if I pass in PGLite, it resolves to showing PGLite as the database. If either of you have any pointers, please let me know! And thank you for writing this spec @agcty , I made sure to credit you in the README 😃 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Currently, when working with transactions in Drizzle ORM, one we need to explicitly pass the transaction object to every function that needs to participate in the transaction. This leads to verbose code and makes it challenging to manage transactions across multiple function calls, especially in complex business logic.
Example of current approach:
Proposed Solution
Implement an implicit transaction context using AsyncLocalStorage or a similar mechanism. This would allow functions to access the current transaction without explicitly passing it as an argument.
Example of proposed approach:
Benefits
Implementation Considerations
withTransactionto create transaction contexts anduseTransactionto access the current transaction.Questions for Discussion
Related Discussion
An old issue #1473 already brought up this idea and I think it has a valid point. It mentions https://www.baeldung.com/spring-transactional-propagation-isolation which could be taken as a reference for a drizzle implementation.
What are your thoughts on this? How are people rolling transaction context at the moment?
Beta Was this translation helpful? Give feedback.
All reactions