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

When i use Propagation.NESTED, serializable not work #47

Open GuihaiHU opened 4 years ago

GuihaiHU commented 4 years ago

I write a method A with transaction SERIALIZABLE in my code, and it works as my expect. However, When I add another method B with transaction Propagation.NESTED, and A calls B. I found the transaction A not work like SERIALIZABLE. This is my code.

 @Transactional({ isolationLevel: IsolationLevel.SERIALIZABLE })
  async addUserScoreAuto(user: AuthUser) {
    await this.service.findOrCreate({ userId: user.id });
  }
 @Transactional({ propagation: Propagation.NESTED })
  async findOrCreate(info: DeepPartial<T>): Promise<[T, boolean]> {
    const entity = await this.repo.findOne(info);
    if (!entity) {
      return [await this.repo.save(info), true];
    }
    return [entity, false];
  }
xfishernet commented 2 years ago

any news?