Callback-free transactions - @transactional
decorator
#2349
Omer-Shahar
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I had an idea to write decorators for running transactions in a more convenient way:
This code will also work when moving some of the logic to another method - without the need to pass the
db
object as an argument.The
db
object imported fromdb.ts
will automatically use the correct object for the transaction.Notice the new
db.isTransacting
property, which istrue
only when running inside a transaction.If you want to use the global
db
object even when inside a transaction, you can use thedb.baseDB
property.This is the link to the repo.
Feel free to ask questions, add improvements and fix any bugs that you find :)
Beta Was this translation helpful? Give feedback.
All reactions