1.0.0-alpha.10 • Published 3 years ago

@przemyslawwalczak/nest-tx-typeorm v1.0.0-alpha.10

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Usage

import { Injectable, Module } from '@nestjs/common';
import { InjectTransactionManager, TransactionManager } from '@leocode/nest-tx-core';
import {
  getEntityManagerFromTypeORMTransaction,
  TypeORMTransactionManagerModule
} from '@leocode/nest-tx-typeorm';

@Injectable()
class CatsService {
  constructor(
    @InjectTransactionManager() private readonly transactionManager: TransactionManager,
  ) {
  }

  public async save() {
    await this.transactionManager.withTransaction(async tx => {
      const manager = getEntityManagerFromTypeORMTransaction(tx);

      const qb = await manager
        .createQueryBuilder()
        .select('id')
        .from('cats')
        .getRawMany();
    });
  }
}


@Module({
  providers: [
    CatsService,
  ]
})
class CatsModule {}

@Module({
  imports: [
    TypeORMTransactionManagerModule.forRoot(),
    CatsModule,
  ],
})
class AppModule {}