Papooch / nestjs-cls

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

Add transactional adapter support for mongoose #154

Closed GO-DIE closed 4 months ago

GO-DIE commented 5 months ago

mongoose is a popular mongodb client package that is used by many people including myself, and I am eager to add an official transactional adapter to mongoose.

Papooch commented 5 months ago

Hi, I was planning to add support for plain mongodb at some point (or welcome a contribution).

In terms of mongoose - I don't know if you're aware, but they offer a built-in transaction propagation with AsyncLocalStorage (i.e. the very same thing that a @nestjs-cls/transactional plugin would offer, so the only benefit would be the option to use the @Transactional decorator)

GO-DIE commented 5 months ago

Hi, I was planning to add support for plain mongodb at some point (or welcome a contribution).

In terms of mongoose - I don't know if you're aware, but they offer a built-in transaction propagation with AsyncLocalStorage (i.e. the very same thing that a @nestjs-cls/transactional plugin would offer, so the only benefit would be the option to use the @Transactional decorator)

Yes, I understand, but I don't think there is a conflict because mongoose's support for AsyncLocalStorage makes us easier to provide a transaction adapter for us to use the @Transactional decorator feature.

Papooch commented 5 months ago

@GO-DIE Would you like to have a go at implementing it? I am definitely open to contributions.

Papooch commented 4 months ago

I found some free time and put together a mongoose adapter. Feel free to test it for your use-case.

@nestjs-cls/transactional >= 2.4.0 is required.