queryPage method
Future<List>
queryPage(
- String collectionId, {
- required Map<
String, QueryValue> where, - required Map<
String, OrderDirection> orderBy, - int? limit,
- int? offset,
- List<
Object?> ? startAfter,
override
Implementation
@override
Future<List> queryPage(
String collectionId, {
required Map<String, QueryValue> where,
required Map<String, OrderDirection> orderBy, // 최대 2개 까지만 유효함.
int? limit,
int? offset,
List<Object?>? startAfter, // 사용안됨.
}) async {
logger.finest('queryPage');
await initialize();
assert(AbsDatabase.sbDBConn != null);
SupabaseQueryBuilder fromRef = AbsDatabase.sbDBConn!.from(collectionId);
PostgrestFilterBuilder filterBuilder = fromRef.select();
where.forEach((key, value) {
filterBuilder = queryMaker(key, value.operType, value.value, filterBuilder);
});
// Map<String, Object> objWhere = {};
// where.forEach((key, value) {
// objWhere[key] = value;
// });
if (orderBy.isEmpty) {
if (limit != null) {
if (offset != null) {
return await filterBuilder.limit(limit).range(offset, offset + limit);
}
return await filterBuilder.limit(limit);
}
return await filterBuilder.select();
}
if (orderBy.length == 1) {
OrderDirection value = orderBy.values.first;
String key = orderBy.keys.first;
if (limit != null) {
if (offset != null) {
return await filterBuilder
.order(key, ascending: value == OrderDirection.ascending)
.limit(limit)
.range(offset, offset + limit);
}
return await filterBuilder
.order(key, ascending: value == OrderDirection.ascending)
.limit(limit);
}
return await filterBuilder.order(key, ascending: value == OrderDirection.ascending);
}
OrderDirection value1 = orderBy.values.first;
String key1 = orderBy.keys.first;
OrderDirection value2 = orderBy.values.elementAt(1);
String key2 = orderBy.keys.elementAt(1);
if (limit != null) {
if (offset != null) {
return await filterBuilder
.order(key1, ascending: value1 == OrderDirection.ascending)
.order(key2, ascending: value2 == OrderDirection.ascending)
.limit(limit)
.range(offset, offset + limit);
}
return await filterBuilder
.order(key1, ascending: value1 == OrderDirection.ascending)
.order(key2, ascending: value2 == OrderDirection.ascending)
.limit(limit);
}
return await filterBuilder
.order(key1, ascending: value1 == OrderDirection.ascending)
.order(key1, ascending: value1 == OrderDirection.ascending);
}