🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

nestjs-typeorm-unit-of-work

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

nestjs-typeorm-unit-of-work

Package for typeorm, which helps to realize "unit of work" pattern

0.1.3
unpublished
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

NestJS Typeorm Unit Of Work (Not stable)

Package for typeorm, which helps to realize "unit of work" pattern. Monorepo containing Nest module and example

Installation

    npm i nestjs-typeorm-unit-of-work

Documentation

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        type: 'postgres',
        host: configService.getOrThrow('DB_HOST'),
        port: Number(configService.getOrThrow('DB_PORT')),
        username: configService.getOrThrow('DB_USER'),
        password: configService.get('DB_PASSWORD'),
        database: configService.getOrThrow('DB_DATABASE'),
        entities: [EmployeeEntity],
      }),
    }),
    TypeormUnitOfWorkModule.forRootAsync({
      inject: [getDataSourceToken()],
      useFactory: (dataSource: DataSource): ITypeormUnitOfWorkModuleOptions => ({
        dataSource,
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
@Injectable()
export class AppService {
  constructor(
    @InjectTypeormUnitOfWork() private readonly unitOfWork: UnitOfWork,
  ) {
  }

  async example (): Promise<number> {
    await this.unitOfWork.start();

    const employeeRepository = await this.unitOfWork.getRepository<EmployeeEntity>(EmployeeEntity);

    const {
      isSuccess,
      data: employeeId,
    } = await this.unitOfWork.commit<number>(
      async () => {
        const employee = await employeeRepository.save({
          firstName: 'firstName',
          lastName: 'lastName',
          yearlyIncomes: 100,
        });

        await employeeRepository.update(employee.id, {
          yearlyIncomes: employee.yearlyIncomes + 100,
        })

        return employee.id;
      }
    )

    return employeeId;
  }
}

Keywords

nest

FAQs

Package last updated on 27 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts