collectionQueries method
List<Query<DynamicMap> > ?
collectionQueries(
- List<
Object?> items, - Query<
DynamicMap> generator(), - ModelQueryFilter filter,
- ModelAdapterCollectionQuery query, [
- FirestoreModelAdapterBase? adapter,
Implementation
List<Query<DynamicMap>>? collectionQueries(
List<Object?> items,
Query<DynamicMap> Function() generator,
ModelQueryFilter filter,
ModelAdapterCollectionQuery query, [
FirestoreModelAdapterBase? adapter,
]) {
if (!items.every((e) => enabledQuery(e, filter, query, adapter))) {
return null;
}
switch (filter.type) {
case ModelQueryFilterType.arrayContainsAny:
final list = items
.map((e) => convertQueryValue(e, filter, query, adapter))
.toList();
final queries = <Query<DynamicMap>>[];
for (var i = 0; i < list.length; i += _kCollectionQuerySplitCount) {
queries.add(
generator().where(
filter.key!,
arrayContainsAny: list
.sublist(
i,
min(i + _kCollectionQuerySplitCount, list.length),
)
.toList(),
),
);
}
return queries;
case ModelQueryFilterType.whereIn:
final list = items
.map((e) => convertQueryValue(e, filter, query, adapter))
.toList();
final queries = <Query<DynamicMap>>[];
for (var i = 0; i < list.length; i += _kCollectionQuerySplitCount) {
queries.add(
generator().where(
filter.key!,
whereIn: list
.sublist(
i,
min(i + _kCollectionQuerySplitCount, list.length),
)
.toList(),
),
);
}
return queries;
case ModelQueryFilterType.whereNotIn:
final list = items
.map((e) => convertQueryValue(e, filter, query, adapter))
.toList();
final queries = <Query<DynamicMap>>[];
for (var i = 0;
i < list.length;
i += _kCollectionQuerySplitCountOnNotIn) {
queries.add(
generator().where(
filter.key!,
whereNotIn: list
.sublist(
i,
min(i + _kCollectionQuerySplitCountOnNotIn, list.length),
)
.toList(),
),
);
}
return queries;
case ModelQueryFilterType.geoHash:
final list = items
.map((e) => convertQueryValue(e, filter, query, adapter))
.toList();
final queries = <Query<DynamicMap>>[];
for (var i = 0; i < list.length; i++) {
final hash = list[i].toString();
queries.add(
generator()
.orderBy(
filter.key!,
)
// ignore: prefer_interpolation_to_compose_strings
.startAt([hash]).endAt([hash + "\uf8ff"]),
);
}
return queries;
default:
return [
generator(),
];
}
}