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('queryData $collectionId');
  await initialize();
  assert(AbsDatabase.sbDBConn != null);

  if (AbsDatabase.sbDBConn == null) {
    logger.severe('sbDBConn is null');
    return [];
  }
  SupabaseQueryBuilder fromRef = AbsDatabase.sbDBConn!.from(collectionId);
  PostgrestFilterBuilder filterBuilder = fromRef.select();
  where.forEach((key, value) {
    filterBuilder = queryMaker('"$key"', OperType.isEqualTo, value, filterBuilder);
  });

  // Map<String, Object> objWhere = {};
  // where.forEach((key, value) {
  //   objWhere[key] = value;
  // });

  if (limit != null) {
    if (offset != null) {
      return await filterBuilder
          .order(orderBy, ascending: !descending)
          .limit(limit)
          .range(offset, offset + limit);
    }
    return await filterBuilder.order(orderBy, ascending: !descending).limit(limit);
  }
  return await filterBuilder.order(orderBy, ascending: !descending);
}