read static method

Future read(
  1. {required String collection,
  2. List? filters,
  3. List? sorts,
  4. int? limit,
  5. Function? onSuccess,
  6. Function? onError}
)

Implementation

static Future<dynamic> read(
    {required String collection,
    List<dynamic>? filters,
    List<dynamic>? sorts,
    int? limit,
    Function? onSuccess,
    Function? onError}) async {
  filters ??= [];
  sorts ??= [];
  List<dynamic> data = [];
  dynamic collectionRef = _filteredCollectionRef(
      collection: collection, filters: filters, sorts: sorts);
  if (limit != null) collectionRef = collectionRef.limit(limit);
  await collectionRef.get().then((QuerySnapshot querySnapshot) {
    if (querySnapshot.docs.isNotEmpty) data = querySnapshot.docs;
    if (onSuccess != null) onSuccess(querySnapshot);
  }).catchError((error) {
    if (onError != null) onError(error);
  });
  return limit == 1 ? (data.isNotEmpty ? data[0] : null) : data;
}