class

MongrelDB::Transaction

Inherits Reference < Object

Transaction stages operations locally and commits them atomically in a single /kit/txn request. The engine enforces unique, foreign-key, check, and trigger constraints at commit time; on any violation all operations roll back and #commit raises a ConflictError.

A Transaction is single-use -- call #commit or #rollback once, then create a new one with Client#begin_transaction.

Constructors

new(client : Client)

Initialize a new Transaction. Normally created via Client#begin_transaction.

Source

Instance methods

commit(idempotency_key : String | Nil = nil) : Array(Hash(String, JSON::Any))

Commit all staged operations atomically.

  • idempotency_key - optional idempotency key for safe retries -- the daemon returns the original response on duplicate commits, even after a crash.
Source
count

The number of staged operations.

Source
delete(table : String, row_id : Int64) : Transaction

Stage a delete by the internal row id.

Source
delete_by_pk(table : String, pk : CellValue) : Transaction

Stage a delete by primary-key value.

Source
put(table : String, cells : Cells, returning : Bool = false) : Transaction

Stage a put (insert) operation.

Source
rollback

Rollback (discard all staged operations).

Source
upsert(table : String, cells : Cells, update_cells : Cells | Nil = nil, returning : Bool = false) : Transaction

Stage an upsert (insert-or-update) operation.

Source