Class: TransactionManager
Defined in: server/persistence/transaction-manager.ts:84
Per-request transaction routing.
TransactionManager uses AsyncLocalStorage to let repository code resolve
"the current database handle" without explicitly threading a transaction
argument through every call. When code runs inside
startOrUseTransaction(prisma, fn), calls to getTx(prisma) return the
active transaction. Outside a transaction, calls return the raw client.
Nested calls reuse the outer transaction rather than starting a new one.
Constructors
Constructor
new TransactionManager(): TransactionManager;Returns
TransactionManager
Methods
getTx()
static getTx<TTx>(prismaClient: PrismaClientLike<TTx>): TTx;Defined in: server/persistence/transaction-manager.ts:105
Get the active transaction, or fall back to the passed client if there's no active transaction. Throws if the passed client doesn't match the transaction's client — mixing clients inside a single transaction is a programmer error.
Type Parameters
| Type Parameter |
|---|
TTx |
Parameters
| Parameter | Type |
|---|---|
prismaClient | PrismaClientLike<TTx> |
Returns
TTx
isInTransaction()
static isInTransaction(): boolean;Defined in: server/persistence/transaction-manager.ts:95
Check if currently executing inside a transaction context.
Returns
boolean
startOrUseTransaction()
static startOrUseTransaction<TTx, T>(
prismaClient: PrismaClientLike<TTx>,
fn: (tx: TTx) => Promise<T>,
options?: TransactionOptions
): Promise<T>;Defined in: server/persistence/transaction-manager.ts:125
Run fn inside a transaction. If a transaction is already active on this
ALS context with the same prismaClient, reuse it. Otherwise start a new
one. All getTx(prismaClient) calls within fn return the transaction.
Type Parameters
| Type Parameter |
|---|
TTx |
T |
Parameters
| Parameter | Type |
|---|---|
prismaClient | PrismaClientLike<TTx> |
fn | (tx: TTx) => Promise<T> |
options? | TransactionOptions |
Returns
Promise<T>