Skip to content

Commit 251a70f

Browse files
author
Brian Chen
authored
Make IN queries publicly available (#4174)
1 parent ffe4a3a commit 251a70f

File tree

6 files changed

+93
-125
lines changed

6 files changed

+93
-125
lines changed

Firestore/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Unreleased
2+
- [feature] Added `whereField(_:in:)` and `whereField(_:arrayContainsAny:)` query
3+
operators. `whereField(_:in:)` finds documents where a specified field’s value
4+
is IN a specified array. `whereField(_:arrayContainsAny:)` finds documents
5+
where a specified field is an array and contains ANY element of a specified
6+
array.
27

38
# v1.6.1
49
- [fixed] Fix a race condition that could cause a segmentation fault during
@@ -196,7 +201,7 @@
196201
# v0.13.0
197202
- [feature] Added `FieldValue.arrayUnion()` and `FieldValue.arrayRemove()` to
198203
atomically add and remove elements from an array field in a document.
199-
- [feature] Added `whereField(arrayContains:)` query filter to find
204+
- [feature] Added `whereField(_:arrayContains:)` query filter to find
200205
documents where an array field contains a specific element.
201206
- [fixed] Fixed compilation with older Xcode versions (#1517).
202207
- [fixed] Fixed a performance issue where large write batches with hundreds of

Firestore/Example/Tests/Integration/API/FIRQueryTests.mm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@ - (void)testQueriesCanUseArrayContainsFilters {
324324
}
325325

326326
- (void)testQueriesCanUseInFilters {
327-
// TODO(b/138855186): Re-enable in prod once feature lands in backend.
328-
if (![FSTIntegrationTestCase isRunningAgainstEmulator]) return;
329-
330327
NSDictionary *testDocs = @{
331328
@"a" : @{@"zip" : @98101},
332329
@"b" : @{@"zip" : @91102},
@@ -349,9 +346,6 @@ - (void)testQueriesCanUseInFilters {
349346
}
350347

351348
- (void)testQueriesCanUseInFiltersWithDocIds {
352-
// TODO(b/138855186): Re-enable in prod once feature lands in backend.
353-
if (![FSTIntegrationTestCase isRunningAgainstEmulator]) return;
354-
355349
NSDictionary *testDocs = @{
356350
@"aa" : @{@"key" : @"aa"},
357351
@"ab" : @{@"key" : @"ab"},
@@ -367,9 +361,6 @@ - (void)testQueriesCanUseInFiltersWithDocIds {
367361
}
368362

369363
- (void)testQueriesCanUseArrayContainsAnyFilters {
370-
// TODO(b/138855186): Re-enable in prod once feature lands in backend.
371-
if (![FSTIntegrationTestCase isRunningAgainstEmulator]) return;
372-
373364
NSDictionary *testDocs = @{
374365
@"a" : @{@"array" : @[ @42 ]},
375366
@"b" : @{@"array" : @[ @"a", @42, @"c" ]},

Firestore/Source/API/FIRQuery+Internal.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,6 @@ NS_ASSUME_NONNULL_BEGIN
4242

4343
- (const api::Query &)apiQuery;
4444

45-
/**
46-
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
47-
* the specified field, the value must be an array, and that array must contain at least one value
48-
* from the provided array.
49-
*
50-
* A query can have only one arrayContains filter and it cannot be combined with arrayContains or
51-
* in.
52-
*
53-
* @param field The name of the field containing an array to search.
54-
* @param value The value that contains the values to match.
55-
*
56-
* @return The created `FIRQuery`.
57-
*/
58-
// TODO(b/138855186): Expose to public once backend is ready.
59-
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(NSArray<id> *)value;
60-
61-
/**
62-
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
63-
* the specified field, the value must be an array, and that array must contain at least one value
64-
* from the provided array.
65-
*
66-
* A query can have only one arrayContains filter and it cannot be combined with arrayContains or
67-
* in.
68-
*
69-
* @param path The path of the field containing an array to search.
70-
* @param value The value that contains the values to match.
71-
*
72-
* @return The created `FIRQuery`.
73-
*/
74-
// TODO(b/138855186): Expose to public once backend is ready.
75-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(NSArray<id> *)value;
76-
77-
/**
78-
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
79-
* the specified field and the value must equal one of the values from the provided array.
80-
*
81-
* A query can have only one in filter, and it cannot be combined with arrayContainsAny.
82-
*
83-
* @param field The name of the field to search.
84-
* @param value The value that contains the values to match.
85-
*
86-
* @return The created `FIRQuery`.
87-
*/
88-
// TODO(b/138855186): Expose to public once backend is ready.
89-
- (FIRQuery *)queryWhereField:(NSString *)field in:(NSArray<id> *)value;
90-
91-
/**
92-
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
93-
* the specified field and the value must equal one of the values from the provided array.
94-
*
95-
* A query can have only one in filter, and it cannot be combined with arrayContainsAny.
96-
*
97-
* @param path The path of the field to search.
98-
* @param value The value that contains the values to match.
99-
*
100-
* @return The created `FIRQuery`.
101-
*/
102-
// TODO(b/138855186): Expose to public once backend is ready.
103-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(NSArray<id> *)value;
104-
10545
@end
10646

10747
NS_ASSUME_NONNULL_END

Firestore/Source/API/FIRQuery.mm

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isGreaterThanOrEqualTo:(i
252252
value:value];
253253
}
254254

255+
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(NSArray<id> *)value {
256+
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny field:field value:value];
257+
}
258+
259+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(NSArray<id> *)value {
260+
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny
261+
path:path.internalValue
262+
value:value];
263+
}
264+
265+
- (FIRQuery *)queryWhereField:(NSString *)field in:(NSArray<id> *)value {
266+
return [self queryWithFilterOperator:Filter::Operator::In field:field value:value];
267+
}
268+
269+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(NSArray<id> *)value {
270+
return [self queryWithFilterOperator:Filter::Operator::In path:path.internalValue value:value];
271+
}
272+
255273
- (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
256274
NSComparisonPredicate *comparison = (NSComparisonPredicate *)predicate;
257275
if (comparison.comparisonPredicateModifier != NSDirectPredicateModifier) {
@@ -546,24 +564,6 @@ - (Bound)boundFromFieldValues:(NSArray<id> *)fieldValues isBefore:(BOOL)isBefore
546564

547565
@implementation FIRQuery (Internal)
548566

549-
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(NSArray<id> *)value {
550-
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny field:field value:value];
551-
}
552-
553-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(NSArray<id> *)value {
554-
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny
555-
path:path.internalValue
556-
value:value];
557-
}
558-
559-
- (FIRQuery *)queryWhereField:(NSString *)field in:(NSArray<id> *)value {
560-
return [self queryWithFilterOperator:Filter::Operator::In field:field value:value];
561-
}
562-
563-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(NSArray<id> *)value {
564-
return [self queryWithFilterOperator:Filter::Operator::In path:path.internalValue value:value];
565-
}
566-
567567
- (const core::Query &)query {
568568
return _query.query();
569569
}

0 commit comments

Comments
 (0)