transactionSync<T> method
T
transactionSync<T>(
- T body()
Runs body as one atomic transaction.
Writes performed through this engine while body runs (including writes
made by Collection methods) are buffered, become visible to point reads
inside the transaction, and are committed as a single WAL frame. If body
throws, nothing is applied.
Limitations: one writer, no nesting, and scans/cursors do not see uncommitted writes (point reads do). This is a deliberate, documented single-process model, not MVCC.
Implementation
T transactionSync<T>(T Function() body) {
_checkWritable();
_checkOpen();
if (_txOps != null) {
throw const VelxoConflictException(
'nested transactions are not supported',
);
}
_txOps = <String, WalOp>{};
try {
final result = body();
final ops = _txOps!.values.toList(growable: false);
_txOps = null;
if (ops.isNotEmpty) _applyBatch(ops);
return result;
} catch (_) {
_txOps = null;
rethrow;
}
}