lookupValue<T extends Model> method
Looks up a single key
in the datastore, and returns the associated
Model object.
If orElse
is specified, then it will be consulted to provide a default
value for the model object in the event that key
was not found in the
datastore.
If the key
is not found in the datastore and orElse
was not
specified, then a KeyNotFoundException will be thrown.
Implementation
Future<T> lookupValue<T extends Model>(Key key,
{T Function()? orElse}) async {
final values = await lookup<T>(<Key>[key]);
assert(values.length == 1);
var value = values.single;
if (value == null) {
if (orElse != null) {
value = orElse();
} else {
throw KeyNotFoundException(key);
}
}
return value;
}