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/prisma';

@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
NESTED requires sqlFlavor

Propagation.NESTED requires sqlFlavor (savepoints are emulated with raw SQL — not available on MongoDB). Without sqlFlavor, a NESTED call inside a transaction logs a warning and runs as an independent transaction (like REQUIRES_NEW) — it does not join the outer one. REQUIRES_NEW (and the NESTED fallback) take a second pooled connection.