function withTransaction
withTransaction<T>(
work: TransactionWork<T>,
unnamed 1?: { invalidateCaches?: boolean; },
): Promise<T>

Use this rather than a plain batch only when a multi-step write needs logic between steps, such as create → check capacity → finalize, where a zero-row guard must abort and undo everything.

Concurrent calls serialise on the shared connection. A retry re-runs work on a fresh transaction, so work must be safe to run twice.

Cache invalidations fire once the commit succeeds. Settings writers that synchronize their own cache can explicitly preserve the loaded snapshot.

Type Parameters

Parameters

work: TransactionWork<T>
optional
unnamed 1: { invalidateCaches?: boolean; }

Return Type

Promise<T>

Usage

import { withTransaction } from "docs/database.ts";