Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.
https://papooch.github.io/nestjs-cls/
MIT License
443 stars 28 forks source link

Support for Mikro-ORM #164

Open vroudge opened 3 months ago

vroudge commented 3 months ago

Seeing as Mikro-orm is an unit-of-work-first ORM, I think it would be great to see a plugin for it for nestjs-cls.

It would be particularly relevant as it uses itself transactional contexts through async_hooks to deal with persisting transactions accross different contexts.

Papooch commented 3 months ago

I looked at MikroORM, but couldn't figure out how to make it work together with their notion of entity managers.

All other adapters work by having access to a single underlying connection object that they can use to start the transaction. With MikroORM, the transaction decorator would somehow need to get ahold of the current entity manager instance even if no transaction is in progress.

However, it is still in my back-log, so maybe I'll figure it out eventually - maybe the adapter abstraction would need to be refactored a bit to support MikroORM. I would definitely appreciate some help in that regard.