Coming from typeorm-transactional?
If you're used to marking methods @Transactional() and letting your
repositories run inside the transaction, the setup here is deliberately small:
- Swap
@nestjs/typeorm'sTypeOrmModulefor this package'sNestjsTypeormModule—forRoot()creates theDataSource(same options) and wires transaction propagation in one import: no global bootstrap call before startup, no manual data-source registration. - Use
NestjsTypeormModule.forFeature([Entity])where you'd register repositories for a feature (same shape asTypeOrmModule.forFeature). - Keep your services exactly as they are:
@InjectRepository(Entity)plus@Transactional({ ... }), with the same options-object syntax forPropagation,IsolationLevel, and the lifecycle hooks.
What's different (and why)
- No monkey-patching.
typeorm-transactionalpatches TypeORM at startup; this package registers ordinary DI providers built on@nestjs-cls/transactional. See Concepts. - No
initializeTransactionalContext()/addTransactionalDataSource(). Those global setup calls are replaced by the singleNestjsTypeormModule.forRoot()import. - Custom repositories: a plain repository's
repo.extend()can't be intercepted — extendNestjsTypeormRepositoryinstead.
The lifecycle hooks (runOnTransactionCommit / Rollback / Complete) take no
connection argument, matching typeorm-transactional, so those calls port over
unchanged.
Migrating from v4 (TransactionalModule)
v5 merges the previous two-module setup into the single NestjsTypeormModule:
- Replace
import { TypeOrmModule } from '@nestjs/typeorm'+import { TransactionalModule } from '@nestjs-transactions/typeorm'with a singleimport { NestjsTypeormModule } from '@nestjs-transactions/typeorm'. - Delete the
TransactionalModule.forRoot(...)lines; movedefaultTxOptions/enableTransactionProxyintoNestjsTypeormModule.forRoot({ ...dbOptions, ... }).namenow also names the transactional connection (connectionNameis gone from the root options). - Rename both
TypeOrmModule.forFeature(...)andTransactionalModule.forFeature(...)toNestjsTypeormModule.forFeature(...)— same signature. TransactionalRepositoryis renamedNestjsTypeormRepositoryand now extends TypeORM'sRepository<Entity>: replacethis.repo.x()withthis.x()(thethis.repogetter is gone;this.managerandthis.txHostremain). Same constructor signature (super(Entity, txHost)).- Attaching to an externally managed
DataSource(TransactionalModule.forRoot({ dataSource, imports })) is no longer part of the public surface —forRootalways owns theDataSource. If your app must keep managing theDataSourceitself, register the CLS plugin directly with@nestjs-cls/transactionaland wire repositories withprovideTransactionAwareRepository.