Skip to main content

Propagation

Control how a @Transactional() method relates to an already-active transaction with the Propagation enum:

import { Propagation, Transactional } from '@nestjs-transactions/typeorm';

@Transactional({ propagation: Propagation.REQUIRES_NEW })
async audit(entry: AuditEntry) {
/* commits even if the caller rolls back */
}
ModeBehavior
REQUIRED (default)Join the current transaction, or start one
REQUIRES_NEWAlways start an independent transaction
NESTEDSavepoint: inner rollback doesn't kill the outer tx
MANDATORYThrow TransactionNotActiveError if no transaction
NEVERThrow TransactionAlreadyActiveError if inside one
SUPPORTSJoin if present, run plainly otherwise
NOT_SUPPORTEDSuspend the transaction for this call

The default is REQUIRED: a method with no explicit propagation joins the caller's transaction if one is active, or opens a new one otherwise.