ReadonlydatabaseThe database connection this transaction function is bound to.
ReadonlydeferredExecute with DEFERRED transaction mode. The database lock is not acquired until the first read or write operation. This is the default SQLite behavior.
ReadonlyexclusiveExecute with EXCLUSIVE transaction mode. Acquires an exclusive lock immediately, blocking all other connections. Use sparingly as it prevents all concurrent access.
ReadonlyimmediateExecute with IMMEDIATE transaction mode. Acquires a write lock immediately, blocking other writers. Recommended for transactions that will write to prevent SQLITE_BUSY errors.
A function wrapped in a transaction. When called, it automatically:
The function also has variants for different transaction modes accessible as properties (
.deferred,.immediate,.exclusive).Note: Each variant is itself a
TransactionFunctionwith circular references to all other variants. This matches better-sqlite3's behavior where you can chain variants liketxn.deferred.immediate()- the last variant in the chain determines the actual transaction mode used.Example