Aliheym / typeorm-transactional

A Transactional Method Decorator for TypeORM that uses Async Local Storage or cls-hooked to handle and propagate transactions between different repositories and service methods.
MIT License
201 stars 27 forks source link

[Feature Request] Implement @Transactional() decorator on class level #5

Open Aliheym opened 2 years ago

Aliheym commented 2 years ago

Description

Allow using @Transactional() decorator with the entire class (apply to all methods). This decorator needs to have the same interface as the existing one. We also need a possibility to ignore some class methods (something like another decorator or additional option).

@Transactional({ propagation: Propagation.REQUIRES_NEW })
class PostsService {
  constructor() {
    // ...
  }

  // If we need to ignore we can use a new decorator @NonTransactional() 
  // or using new option @Transactional({ ignore: true }) (?) think about it
  async getPostById() {
     // ...
   }

  // If we use explicit`@Transactional()  then we need to override options that were defined in class-level `@Transactional`
  @Transactional({  propagation: Propagation.NESTED })
  async updatePost() {
     // ...
   }
}

Of course, we need tests and documentation for these new features.

vvtri commented 1 year ago

Hi @Aliheym, when this ready to be used ?