getSequenceNextTxn method

Future<int> getSequenceNextTxn(
  1. String sequenceName
)

Implementation

Future<int> getSequenceNextTxn(String sequenceName) async {
  final record = await sequenceRecords.getBySequenceName(sequenceName);

  if (record == null) {
    const firstValue = 1;
    await sequenceRecords.put(
      SequenceRecord()
        ..sequenceName = sequenceName
        ..latestValue = firstValue,
    );
    return firstValue;
  }

  final nextValue = record.latestValue + 1;

  await sequenceRecords.put(
    SequenceRecord()
      ..id = record.id
      ..sequenceName = sequenceName
      ..latestValue = nextValue,
  );

  return nextValue;
}