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
522 stars 86 forks source link

add runInTransaction and wrapInTransaction #94

Closed lytc closed 3 years ago

lytc commented 3 years ago

Hi @odavid , I created this PR for this request https://github.com/odavid/typeorm-transactional-cls-hooked/issues/92, could you help to have a look?

odavid commented 3 years ago

Hi @lytc, thanks for the contribution!

I feel you also need to add the runInTransaction function to the exports within the index.ts

koenpunt commented 3 years ago

Not sure if this is the correct thread to bring this up, but I feel it might be related; I'm using this library indirectly (through typeorm-test-transactions), and I was wondering if it would possible to have separate "start" and "stop" transaction methods? So not a function wrapper (or decorator).

I hope to be able to use it in before/after hooks of jest, to automatically "wrap" every test in a transaction;

beforeEach(() => startTransaction());

test('do something with the database', async () => {
  await someDbAction();
});

afterEach(() => rollbackTransaction());

Or more plainly;

await startTransaction();
await someDbAction();
await rollbackTransaction();
lytc commented 3 years ago

Hi @lytc, thanks for the contribution!

I feel you also need to add the runInTransaction function to the exports within the index.ts

I added that already!

lytc commented 3 years ago

Hi @odavid , Thanks for your review, I make the change regarding to your comments!

odavid commented 3 years ago

Thank you!