update method

  1. @override
Future? update(
  1. Entity entity,
  2. Map data,
  3. Iterable<String>? fields
)
override

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 in data
  • 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);
}