put method
Associates value with key. If a mapping already exists,
the old value is replaced.
Returns the commit-log sequence number assigned to this write,
or null if no sequence number was produced (when skipCommit
is true, or when this backend does not maintain a commit
log).
Throws a DataStoreException if the underlying store fails.
Implementation
@override
Future<int?> put(String key, AtData value, {bool skipCommit = false}) async {
final k = _validateAndNormalize(key);
if (!_existsSync(k)) {
return create(key, value, skipCommit: skipCommit);
}
final existing = _getSync(k);
final toStore = AtData()
..data = value.data
..metaData = AtMetadataBuilder(
atSign: atSign,
newAtMetaData: value.metaData,
existingMetaData: existing?.metaData,
).build();
final result = _db.runInTransaction(() {
_upsertAtData(k, toStore);
return skipCommit ? -1 : _commitOrNull(k, CommitOp.UPDATE_ALL);
});
_changes.add(KeyUpdated(k));
return result;
}