Skip to main content

Module txn

Module txn 

Source
Expand description

Kit transaction wrapper around a MongrelDB core transaction.

Constraints are enforced with the guard-table architecture shared with the TypeScript kit:

  • Unique constraints reserve a row in __kit_unique_keys keyed by the typed encoded unique key. Concurrent inserts of the same value collide on that key and one transaction retries.
  • Foreign keys verify the parent row exists and then touch the parent’s __kit_row_guards row. A concurrent parent delete also writes that guard key, forcing a write-write conflict so the unsafe snapshot interleaving is impossible.
  • Primary keys are handled like the TypeScript kit. An auto-assigned (sequence-default) primary key is guaranteed unique and needs no check. An explicit single-column primary key is checked directly against the visible rows (no guard row). Only an explicit composite primary key reserves a __pk_<table> guard in __kit_unique_keys (it has no single native key to probe), so a duplicate-PK insert is rejected instead of silently upserting.

Reads inside a transaction use the transaction’s read snapshot; writes staged earlier in the same transaction are tracked in memory so read-your-writes behaves correctly even though the core transaction cannot read its own staging.

Structs§

Transaction
A kit transaction.