Skip to main content

nestjs-transactions

Declarative @Transactional() for NestJS — TypeORM & Prisma, no monkey-patching

@Injectable()
export class MemberService {
constructor(
@InjectRepository(Member) private readonly repo: Repository<Member>,
private readonly accounting: AccountingService,
) {}

@Transactional()
async register(name: string) {
const member = await this.repo.save({ name });
await this.accounting.openAccount(member); // joins the SAME transaction
return member; // no decorator needed there
}
}

Invisible propagation

Transactions flow through CLS (AsyncLocalStorage), so a call several services deep joins the same transaction and rolls back together.

No monkey-patching

Built on the actively maintained @nestjs-cls/transactional. TypeORM and Prisma classes are never patched at startup — a library upgrade can’t break you unexpectedly.

Familiar ergonomics

Keep @InjectRepository(Entity), add @Transactional(), done. The decorator-based DX of typeorm-transactional, on a maintained foundation.