queryData method

  1. @override
Future<List> queryData(
  1. String collectionId, {
  2. required Map<String, dynamic> where,
  3. required String orderBy,
  4. bool descending = true,
  5. int? limit,
  6. int? offset,
  7. List<Object?>? startAfter,
})
override

Implementation

@override
Future<List> queryData(String collectionId,
    {required Map<String, dynamic> where,
    required String orderBy,
    bool descending = true,
    int? limit,
    int? offset,
    List<Object?>? startAfter}) async {
  logger.finest('before');
  await initialize();
  logger.finest('after');
  assert(_db != null);
  CollectionReference collectionRef = _db!.collection(collectionId);
  Query<Object?> query = collectionRef.orderBy(orderBy, descending: descending);
  where.map((mid, value) {
    query = query.where(mid, isEqualTo: value);
    return MapEntry(mid, value);
  });

  if (limit != null) query = query.limit(limit);
  if (startAfter != null && startAfter.isNotEmpty) query = query.startAfter(startAfter);

  return await query.get().then((snapshot) {
    return snapshot.docs.map((doc) {
      //logger.finest(doc.data()!.toString());
      return doc.data()! as Map<String, dynamic>;
    }).toList();
  });
}