find method
It finds an Entity for the given Id.
@param id the Id of the Entity to be found @return the Entity if found or an empty result if not
Implementation
@override
Future<Optional<T>> find(String id, Function deserialize) async {
final client = _client();
try {
var faunaResponse = await client.query(Get(Ref(Collection(collection), id)));
var data = faunaResponse.toJson();
var resource = data['resource'];
if(resource != null) {
T t = deserialize(resource['data'].object);
return Optional.of(t);
}
return Optional.empty();
}
catch(e) {
print(e);
return Optional.empty();
}
finally {
client.close();
}
}