Skip to main content

Getting started

nestjs-transactions ships one adapter per ORM. Pick the one that matches your stack — both give you the same @Transactional() decorator and CLS-based propagation.

TypeORM

npm install @nestjs-transactions/typeorm @nestjs-transactions/core \
@nestjs/typeorm typeorm @nestjs-cls/transactional \
@nestjs-cls/transactional-adapter-typeorm nestjs-cls

Use NestjsTypeormModule from this package instead of @nestjs/typeorm's TypeOrmModule — one module owns both the database connection and transaction propagation:

// app.module.ts
import { NestjsTypeormModule } from '@nestjs-transactions/typeorm';

@Module({
imports: [NestjsTypeormModule.forRoot({/* all @nestjs/typeorm options ... */})],
})
export class AppModule {}

// member.module.ts — same shape as @nestjs/typeorm's forFeature
@Module({
imports: [NestjsTypeormModule.forFeature([Member])],
providers: [MemberService],
})
export class MemberModule {}

That's the whole setup. Continue to the TypeORM adapter for propagation modes, multiple data sources, custom repositories, and testing utilities.

Prisma

npm install @nestjs-transactions/prisma @nestjs-transactions/core \
@prisma/client @nestjs-cls/transactional \
@nestjs-cls/transactional-adapter-prisma nestjs-cls
// app.module.ts
import { TransactionalModule } from '@nestjs-transactions/prisma';

@Module({
imports: [
PrismaModule,
TransactionalModule.forRoot({
prismaToken: PrismaService,
sqlFlavor: 'postgresql', // enables Propagation.NESTED (savepoints)
imports: [PrismaModule],
}),
],
})
export class AppModule {}

Continue to the Prisma adapter for the full setup, propagation, and transaction options.

Peer dependencies

Every package listed in the install command is a peer dependency (@nestjs/common and @nestjs/core are peers too, but every NestJS app already has them) — the adapters ship zero runtime dependencies, so you always control the exact ORM and nestjs-cls versions.