create method

  1. @override
Future<int?> create(
  1. String key,
  2. AtData value, {
  3. bool skipCommit = false,
})
override

If no mapping exists for key, associates it with value and returns the commit-log sequence number; otherwise behaviour is implementation-defined (typically throws).

Returns the commit-log sequence number assigned to this write, or null if no sequence number was produced.

Throws a DataStoreException if the underlying store fails.

Implementation

@override
Future<int?> create(String key, AtData value,
    {bool skipCommit = false}) async {
  final k = _validateAndNormalize(key);
  _checkMaxLength(k);
  final toStore = AtData()
    ..data = value.data
    ..metaData =
        AtMetadataBuilder(atSign: atSign, newAtMetaData: value.metaData)
            .build();
  final commitOp = _commitOpForNewWrite(value.metaData);
  final result = _db.runInTransaction(() {
    _upsertAtData(k, toStore);
    return skipCommit ? -1 : _commitOrNull(k, commitOp);
  });
  _changes.add(KeyAdded(k));
  return result;
}