function writeRowInTransaction
writeRowInTransaction<State = never>(
statement: InStatement,
existingId: number | null,
persist: (
tx: TxScope,
id: number,
state: State | null,
) => Promise<void>
,
readState?: TransactionStateReader<State>,
): Promise<number>

Write one row statement in a fresh write transaction and run persist (the coupled join-table writes) on the same tx, so the row and its side writes commit or roll back together. On update, an optional readState runs before the statement and its result reaches persist; creates skip it. Returns the row id — existingId on update, or the key the INSERT returned on create.

Type Parameters

State = never

Parameters

statement: InStatement
existingId: number | null
persist: (
tx: TxScope,
id: number,
state: State | null,
) => Promise<void>
optional
readState: TransactionStateReader<State>

Return Type

Promise<number>

Usage

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