getQuery function
Implementation
Query? getQuery(collection,
{String? orderBy,
bool? descending,
DocumentSnapshot? startAfter,
int? limit,
int? privilegeLevel,
String? appId,
EliudQuery? eliudQuery}) {
var useThisCollection = collection;
// Are we ordering?
if (orderBy != null) {
useThisCollection =
useThisCollection.orderBy(orderBy, descending: descending);
}
if (privilegeLevel != null) {
// Do we have some limits in terms of privilege?
useThisCollection = useThisCollection
.where('conditions.privilegeLevelRequired', isEqualTo: privilegeLevel)
.where('appId', isEqualTo: appId);
}
if ((eliudQuery != null) &&
/*
(eliudQuery.conditions != null) &&
*/
(eliudQuery.conditions.isNotEmpty)) {
for (var i = 0; i < eliudQuery.conditions.length; i++) {
var condition = eliudQuery.conditions[i];
if (condition.isLessThanOrEqualTo != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isLessThanOrEqualTo: condition.isLessThanOrEqualTo);
}
if (condition.isLessThan != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isLessThan: condition.isLessThan);
}
if (condition.isEqualTo != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isEqualTo: condition.isEqualTo);
}
if (condition.isGreaterThanOrEqualTo != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isGreaterThanOrEqualTo: condition.isGreaterThanOrEqualTo);
}
if (condition.isGreaterThan != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isGreaterThan: condition.isGreaterThan);
}
if (condition.isNull != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
isNull: condition.isNull);
}
if (condition.arrayContains != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
arrayContains: condition.arrayContains);
}
if (condition.arrayContainsAny != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
arrayContainsAny: condition.arrayContainsAny);
}
if (condition.whereIn != null) {
useThisCollection = useThisCollection.where(
getFirestoreField(condition.field),
whereIn: condition.whereIn);
}
}
}
// Are we paginating?
if (startAfter != null) {
useThisCollection = useThisCollection.startAfterDocument(startAfter);
}
if (limit != null) {
useThisCollection = useThisCollection.limit(limit);
}
return useThisCollection;
}