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

patch repository prototype and the prototype extend method #14

Closed mekh closed 1 year ago

mekh commented 1 year ago

This patch allows using either dataSource.getRepository().extend() or custom repositories:

@Injectable()
export class CustomRepository extends Repository<Entity> {
  constructor(private readonly dataSource: DataSource) {
    super(Entity, dataSource.manager);
  }

  async customMethod() {}
}
export const customRepository = dataSource.getRepository(Entity)
    .extend({
      async customMethod(): Promise<any> {
          ...
      },
    });
Aliheym commented 1 year ago

Hi, thanks for good PR. Do you want to support custom repositories classes from the TypeORM v0.2?

mekh commented 1 year ago

Hi, I'm maintaining a project that uses typeorm v0.3.7, @nestjs/typeorm v9.0.1 and custom repositories built using this: CustomRepository for typeorm@0.3.x

It would be great to have your module support this approach.

AmoOAO commented 1 year ago

This is working for me !!! PLS review & merge it !

lukeurban commented 1 year ago

Doesn't work :(

Aliheym commented 1 year ago

Sorry for such delay. I've just released this feature.

@mekh thank you for your PR.