insert method

int insert(
  1. TxnContext ctx,
  2. Map<String, dynamic> values
)

Insert a new row with values under transaction ctx. Returns the assigned row ID.

Implementation

int insert(TxnContext ctx, Map<String, dynamic> values) {
  final id = values.containsKey('id') && values['id'] is int
      ? (values['id'] as int)
      : _nextRowId;
  if (id >= _nextRowId) _nextRowId = id + 1;

  final withId = Map<String, dynamic>.from(values);
  withId['id'] = id;

  final version = MvccRowVersion(
    rowId: id,
    values: withId,
    createdByTxn: ctx.txnId,
  );
  _chains[id] = MvccVersionChain(version);
  return id;
}