method IDatabaseService.transaction
Since 0.1.0
IDatabaseService.transaction<T>(
work: (uow: IUnitOfWork) => Promise<T>,
): Promise<T>

Execute the work callback within a database transaction.

On success the transaction commits and the callback result is returned. On error the transaction rolls back and the error propagates.

Type Parameters

Return type of the work callback

Parameters

work: (uow: IUnitOfWork) => Promise<T>

Function receiving a transaction-scoped Unit of Work

optional
options: TransactionOptions

Optional transaction settings, including requested isolation

Return Type

Promise<T>

The result of the work callback

Throws

Error

If the work callback throws — transaction is rolled back

Usage

import { type IDatabaseService } from "database-plugin/src/index.ts";