getOptional method

Future<Optional<JBDOC>> getOptional(
  1. String collection,
  2. int id
)

Get json body of document identified by id and stored in collection.

Implementation

Future<Optional<JBDOC>> getOptional(String collection, int id) {
  return get(collection, id).then((doc) => Optional.of(doc)).catchError((err) {
    if (err is EJDB2Error && err.isNotFound()) {
      return Future.value(const Optional<JBDOC>.absent());
    }
    return Future.error(err);
  });
}