increment method

Future<void> increment(
  1. String table,
  2. String key,
  3. num by
)

Folds a signed by into this node's sub-counter of the PnCounter record at table/key, creating the counter (at 0 + by) if the record does not exist yet.

Throws ArgumentError if the record exists but is not a counter.

Implementation

Future<void> increment(String table, String key, num by) async {
  final current = await _inner.value(table, key);
  if (current != null && storedCrdtTag(current) != pnCounterTag) {
    throw ArgumentError(
      'Field "$key" is not a PnCounter; only counter fields can be '
      'incremented.',
    );
  }
  if (current != null && by == 0) return; // Nothing to fold in.
  await _inner.put(table, key, pnApplyDelta(current, nodeId, by),
      crdtType: const PnCounter());
}