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, // appwrite only
  List<Object?>? startAfter, // firebase only
}) async {
  await initialize();

  try {
    //String orderType = descending ? 'DESC' : 'ASC';

    List<dynamic> queryList = [];
    where.map((mid, value) {
      queryList.add(Query.equal(mid, value));
      return MapEntry(mid, value);
    });

    List<String> additional = [
      descending ? Query.orderDesc(orderBy) : Query.orderAsc(orderBy),
    ];
    if (limit != null) {
      additional.add(Query.limit(limit));
    }
    if (offset != null) {
      additional.add(Query.offset(offset));
    }

    final result = await database!.listDocuments(
        databaseId: myConfig!.serverConfig.dbConnInfo.appId,
        collectionId: collectionId,
        queries: [
          ...queryList,
          ...additional,
        ] // index 를 만들어줘야 함.
        //orderAttributes: [orderBy],
        //orderTypes: [orderType],
        //limit: limit,
        //offset: offset,
        );
    return result.documents.map((doc) {
      //logger.finest(doc.data.toString());
      return doc.data;
    }).toList();
  } on AppwriteException catch (e) {
    if (e.code == 404) {
      logger.finest(e.message!);
      return [];
    }
    if (e.message != null) {
      throw HycopException(message: e.message!, code: e.code);
    }
    throw HycopException(message: 'Appwrite error', code: e.code);
  }
}