odavid / typeorm-transactional-cls-hooked

A Transactional Method Decorator for typeorm that uses cls-hooked to handle and propagate transactions between different repositories and service methods. Inpired by Spring Trasnactional Annotation and Sequelize CLS
MIT License
524 stars 86 forks source link

Does TransactionRepository decorator work with Transactional? #38

Closed ydinari closed 3 years ago

ydinari commented 4 years ago

When working with typeorm Transaction decorator you can inject repositories as parameters to the decorated function using TransactionRepository decorator. Can you use that with the Transactional decorator?

odavid commented 4 years ago

Never tried that, so I cannot really tell. Seems a bit conflict to the Transactional concept, since it must come with typeorm @Transaction decorator, which opens a transaction and closes it when the method finishes.

I actually think it will not work, since the typeorm @Transaction creates an entityManager, but does not push it to the cls-hooked context, so therefore it won't be around in the next method.