update method

int update(
  1. TxnContext ctx,
  2. bool predicate(
    1. Map<String, dynamic>
    ),
  3. Map<String, dynamic> updates,
  4. Set<int> activeTransactions,
)

Update rows matching predicate with updates under ctx. Returns count of updated rows.

Implementation

int update(
  TxnContext ctx,
  bool Function(Map<String, dynamic>) predicate,
  Map<String, dynamic> updates,
  Set<int> activeTransactions,
) {
  int count = 0;
  for (final chain in _chains.values) {
    final visible = chain.visibleVersion(ctx);
    if (visible == null) continue;
    if (!predicate(visible.values)) continue;

    // Write-write conflict check
    _checkWriteConflict(chain.head, activeTransactions, ctx.txnId);

    // Mark current head as deleted by this txn
    chain.head.deletedByTxn = ctx.txnId;

    // Create new version with updated values
    final newValues = Map<String, dynamic>.from(visible.values)
      ..addAll(updates);
    final newVersion = MvccRowVersion(
      rowId: visible.rowId,
      values: newValues,
      createdByTxn: ctx.txnId,
      prev: chain.head, // link to old version
    );
    chain.head = newVersion;
    count++;
  }
  return count;
}