update method
Updates the entity with the given OID into database. *
-
data
- the content of the entity. It might contain
- more fields than what are specified in
fields
. - And, these fields shall be ignored.
-
fields
- the fields to update. If null, all fields indata
- shall be stored.
Implementation
@override
Future? update(Entity entity, Map data, Iterable<String>? fields) {
final oid = entity.oid;
if (fields != null) {
final prevValue = _load(oid);
if (prevValue == null)
throw StateError("Not found: $oid");
for (final fd in fields)
prevValue[fd] = data[fd];
data = prevValue;
}
_storage[oid] = json.encode(data);
}