appendBatch method

Future<int> appendBatch(
  1. List<({WalOp op, Map<String, dynamic> payload, String table, int? txnId})> ops
)

Implementation

Future<int> appendBatch(List<({
  WalOp op,
  String table,
  Map<String, dynamic> payload,
  int? txnId,
})> ops) async {
  if (_closed) throw StateError('WAL is closed');
  int lastLsn = _lsn;
  for (final o in ops) {
    _lsn++;
    final record = WalRecord(
      op:       o.op,
      table:    o.table,
      payload:  o.payload,
      lsn:      _lsn,
      txnId:    o.txnId ?? _currentTxnId,
      checksum: 0,
    );
    await _writeRecord(record);
    lastLsn = _lsn;
  }
  // Single flush for the entire batch (group commit)
  await _flush();
  _flushedLsn = lastLsn;
  return lastLsn;
}