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 typeorm Adapter for @nestjs-cls/transactional #140

Closed giosueDelgado closed 7 months ago

giosueDelgado commented 7 months ago

The @nestjs-cls/transactional plugin currently supports a variety of ORM adapters like Prisma, Knex, and Pg-promise to enable CLS (Continuation Local Storage)-based transaction management. This feature allows transaction contexts to be passed seamlessly across different layers of an application without manually threading transaction objects through every call.

To extend the utility of this package to a broader audience, there is a need to implement an adapter for TypeORM. TypeORM is a widely-used ORM that supports both Active Record and Data Mapper patterns, making it a preferred choice for many TypeScript developers using NestJS.

giosueDelgado commented 7 months ago

FYI @Papooch

Papooch commented 7 months ago

Thanks, I'd like to mention (for the sake of context, as we talked on Discord previously) that there's a more complete implementation of the @Transactional decorator for TypeORM maintained by the community.

While supporting TypeORM was initially a non-goal, I changed my mind and I'm now not opposed to having an adapter for it, considering the linked implementation relies on monkey-patching TypeORM, which this plugin aims not to do.

I see you already created a PR, so let's address any technical details there.


P.S. I have a feeling that you let ChatGPT generate the issue text, am I right? :sweat_smile:

giosueDelgado commented 7 months ago

Thanks, I'd like to mention (for the sake of context, as we talked on Discord previously) that there's a more complete implementation of the @Transactional decorator for TypeORM maintained by the community.

While supporting TypeORM was initially a non-goal, I changed my mind and I'm now not opposed to having an adapter for it, considering the linked implementation relies on monkey-patching TypeORM, which this plugin aims not to do.

I see you already created a PR, so let's address any technical details there.

P.S. I have a feeling that you let ChatGPT generate the issue text, am I right? 😅

Perfect! Yes I rewrite the issue text :)

NarHakobyan commented 7 months ago

Hey, Just come here to say it's not a good idea to support typeorm, lib almost is not maintainable and have a lot of breaking changes, it would be better to support MikroOrm

One of the popular issues: https://github.com/typeorm/typeorm/issues/10638

Papooch commented 7 months ago

@NarHakobyan I agree, adding MikroORM support was on my list, too (and I'm open to contributions).

But having an adapter for TypeORM doesn't hurt that much, since there's very little typeorm-specific code anyways.

giosueDelgado commented 7 months ago

Good evening. @NarHakobyan I understand you, me and a new team are discussing with the creator of typeorm and we want to make great again TypeOrm (but this is another story...) For the adapter is not a problem have it and use this for the many projects that at the moment are using TypeOrm. Have the adapter for typeorm is not exclusive to create also one for Mikrorm!

Papooch commented 7 months ago

@nestjs-cls/transactional-adapter-typeorm was released.

giosueDelgado commented 7 months ago

@nestjs-cls/transactional-adapter-typeorm was released.

Cool! Thanks