Giter VIP home page Giter VIP logo

Comments (2)

odavid avatar odavid commented on August 14, 2024

Thank you @Faithfinder...
The way the library works is that it starts a transaction and put the EntityManager within the cls-hook Namespace.
I don't see a real way of doing it the way you want, without changing the code of the callers...
I am sorry...

from typeorm-transactional-cls-hooked.

Faithfinder avatar Faithfinder commented on August 14, 2024

No worries. What I wanted to enable, is refactoring the code from the end of the call chain, rather than beginning. I suppose this library could somehow patch TypeORM's methods that start transactions to put the entity manager where we want it. The use case is not really worth the additional complexity though, probably.
The workaround is quite simple, if a bit ugly, really. I'll leave it here in case someone googles and stumbles upon this issue.

You can refactor the top level of transactional chain to use @Transactional() instead of getConnection().transaction(), and pass the manager further down the chain by getting the manager property of any repo you use. After that you can use both "styles" of transactions and refactor both the top and the bottom of the call chain at your leisure.

Pseudo code example. This:

  await getConnection().transaction(async transactionalEntityManager => {
     this.startTransactionalWork(transactionalEntityManager)
  });

startTransactionalWork(transactionalEntityManager) {
    const transactionalRepo = transactionalEntityManager.getRepository();
    continueTransactionalWork(transactionalEntityManager)
  }

becomes this:

@Transactional()
startTransactionalWork() {
    const transactionalEntityManager = this.anyInjectedRepository.manager;
    continueTransactionalWork(transactionalEntityManager)
  }

from typeorm-transactional-cls-hooked.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.