DB Transaction, AsyncLocalStorage and Middleware
Hello,
I'm trying to add an abstraction for db transaction using Drizzle-ORM. For this I want to create a transaction and put it in the AsyncLocalStorage of Node.js, so that I can retrieve it using a function in my repositories without passing the transaction everywhere.
Can I do this sort of things with the middleware ?
Because at first this seems to work but then after like 5-10 seconds the server just shutdown with only an error code (no other information):
Thanks in advance :).
1 Reply
foreign-sapphire•5mo ago
Hey, I usually put things inside the "event.context" and then retrieve them wherever I need. Something like this could work:
You can register it as global middleware, so the db is always available on the context