where method
QueryBuilder
where(
- Object field, {
- Object? isEqualTo,
- Object? isNotEqualTo,
- Object? isLessThan,
- Object? isLessThanOrEqualTo,
- Object? isGreaterThan,
- Object? isGreaterThanOrEqualTo,
- Object? arrayContains,
- Object? arrayNotContains,
- Iterable<
Object?> ? arrayContainsAny, - Iterable<
Object?> ? arrayNotContainsAny, - Iterable<
Object?> ? whereIn, - Iterable<
Object?> ? whereNotIn, - bool? isNull,
Implementation
QueryBuilder where(
Object field, {
Object? isEqualTo,
Object? isNotEqualTo,
Object? isLessThan,
Object? isLessThanOrEqualTo,
Object? isGreaterThan,
Object? isGreaterThanOrEqualTo,
Object? arrayContains,
Object? arrayNotContains,
Iterable<Object?>? arrayContainsAny,
Iterable<Object?>? arrayNotContainsAny,
Iterable<Object?>? whereIn,
Iterable<Object?>? whereNotIn,
bool? isNull,
}) {
if (field is Filter) {
return _filter(field);
} else {
_data = _data.where((doc) {
final i = doc[field];
if (isEqualTo != null && i == isEqualTo) {
return true;
} else if (isNotEqualTo != null && i != isNotEqualTo) {
return true;
} else if (isLessThan != null && i != null && i < isLessThan) {
return true;
} else if (isLessThanOrEqualTo != null &&
i != null &&
i <= isLessThanOrEqualTo) {
return true;
} else if (isGreaterThan != null && i != null && i > isGreaterThan) {
return true;
} else if (isGreaterThanOrEqualTo != null &&
i != null &&
i >= isGreaterThanOrEqualTo) {
return true;
} else if (arrayContains != null &&
i is Iterable &&
i.contains(arrayContains)) {
return true;
} else if (arrayNotContains != null &&
i is Iterable &&
!i.contains(arrayNotContains)) {
return true;
} else if (arrayContainsAny != null &&
i is Iterable &&
i.any((e) => arrayContainsAny.contains(e))) {
return true;
} else if (arrayNotContainsAny != null &&
i is Iterable &&
!i.any((e) => arrayNotContainsAny.contains(e))) {
return true;
} else if (whereIn != null && whereIn.contains(i)) {
return true;
} else if (whereNotIn != null && whereNotIn.contains(i)) {
return true;
} else if (isNull != null && (i == null) == isNull) {
return true;
} else {
return false;
}
}).toList();
return QueryBuilder(List.from(_data), this, orders);
}
}