| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- /*
- * Copyright 2017 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #import <Foundation/Foundation.h>
- #import "FIRFirestoreSource.h"
- #import "FIRListenerRegistration.h"
- @class FIRFieldPath;
- @class FIRFirestore;
- @class FIRQuerySnapshot;
- @class FIRDocumentSnapshot;
- NS_ASSUME_NONNULL_BEGIN
- /**
- * A block type used to handle failable snapshot method callbacks.
- */
- typedef void (^FIRQuerySnapshotBlock)(FIRQuerySnapshot *_Nullable snapshot,
- NSError *_Nullable error);
- /**
- * A `FIRQuery` refers to a Query which you can read or listen to. You can also construct
- * refined `FIRQuery` objects by adding filters and ordering.
- */
- NS_SWIFT_NAME(Query)
- @interface FIRQuery : NSObject
- /** :nodoc: */
- - (id)init __attribute__((unavailable("FIRQuery cannot be created directly.")));
- /** The `FIRFirestore` for the Firestore database (useful for performing transactions, etc.). */
- @property(nonatomic, strong, readonly) FIRFirestore *firestore;
- #pragma mark - Retrieving Data
- /**
- * Reads the documents matching this query.
- *
- * This method attempts to provide up-to-date data when possible by waiting for
- * data from the server, but it may return cached data or fail if you are
- * offline and the server cannot be reached. See the
- * `getDocuments(source:completion:)` method to change this behavior.
- *
- * @param completion a block to execute once the documents have been successfully read.
- * documentSet will be `nil` only if error is `non-nil`.
- */
- - (void)getDocumentsWithCompletion:(FIRQuerySnapshotBlock)completion
- NS_SWIFT_NAME(getDocuments(completion:));
- /**
- * Reads the documents matching this query.
- *
- * @param source indicates whether the results should be fetched from the cache
- * only (`Source.cache`), the server only (`Source.server`), or to attempt
- * the server and fall back to the cache (`Source.default`).
- * @param completion a block to execute once the documents have been successfully read.
- * documentSet will be `nil` only if error is `non-nil`.
- */
- - (void)getDocumentsWithSource:(FIRFirestoreSource)source
- completion:(FIRQuerySnapshotBlock)completion
- NS_SWIFT_NAME(getDocuments(source:completion:));
- /**
- * Attaches a listener for QuerySnapshot events.
- *
- * @param listener The listener to attach.
- *
- * @return A FIRListenerRegistration that can be used to remove this listener.
- */
- - (id<FIRListenerRegistration>)addSnapshotListener:(FIRQuerySnapshotBlock)listener
- NS_SWIFT_NAME(addSnapshotListener(_:));
- /**
- * Attaches a listener for QuerySnapshot events.
- *
- * @param includeMetadataChanges Whether metadata-only changes (i.e. only
- * `FIRDocumentSnapshot.metadata` changed) should trigger snapshot events.
- * @param listener The listener to attach.
- *
- * @return A FIRListenerRegistration that can be used to remove this listener.
- */
- - (id<FIRListenerRegistration>)
- addSnapshotListenerWithIncludeMetadataChanges:(BOOL)includeMetadataChanges
- listener:(FIRQuerySnapshotBlock)listener
- NS_SWIFT_NAME(addSnapshotListener(includeMetadataChanges:listener:));
- #pragma mark - Filtering Data
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be equal to the specified value.
- *
- * @param field The name of the field to compare.
- * @param value The value the field must be equal to.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- isEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be equal to the specified value.
- *
- * @param path The path of the field to compare.
- * @param value The value the field must be equal to.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- isEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be less than the specified value.
- *
- * @param field The name of the field to compare.
- * @param value The value the field must be less than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- isLessThan:(id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be less than the specified value.
- *
- * @param path The path of the field to compare.
- * @param value The value the field must be less than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- isLessThan:(id)value NS_SWIFT_NAME(whereField(_:isLessThan:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be less than or equal to the specified value.
- *
- * @param field The name of the field to compare
- * @param value The value the field must be less than or equal to.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- isLessThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be less than or equal to the specified value.
- *
- * @param path The path of the field to compare
- * @param value The value the field must be less than or equal to.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- isLessThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isLessThanOrEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must greater than the specified value.
- *
- * @param field The name of the field to compare
- * @param value The value the field must be greater than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- isGreaterThan:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must greater than the specified value.
- *
- * @param path The path of the field to compare
- * @param value The value the field must be greater than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- isGreaterThan:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThan:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be greater than or equal to the specified value.
- *
- * @param field The name of the field to compare
- * @param value The value the field must be greater than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- isGreaterThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThanOrEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * contain the specified field and the value must be greater than or equal to the specified value.
- *
- * @param path The path of the field to compare
- * @param value The value the field must be greater than.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- isGreaterThanOrEqualTo:(id)value NS_SWIFT_NAME(whereField(_:isGreaterThanOrEqualTo:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field, it must be an array, and the array must contain the provided value.
- *
- * A query can have only one arrayContains filter.
- *
- * @param field The name of the field containing an array to search
- * @param value The value that must be contained in the array
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- arrayContains:(id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field, it must be an array, and the array must contain the provided value.
- *
- * A query can have only one arrayContains filter.
- *
- * @param path The path of the field containing an array to search
- * @param value The value that must be contained in the array
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- arrayContains:(id)value NS_SWIFT_NAME(whereField(_:arrayContains:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field, the value must be an array, and that array must contain at least one value
- * from the provided array.
- *
- * A query can have only one `arrayContainsAny` filter and it cannot be combined with
- * `arrayContains` or `in` filters.
- *
- * @param field The name of the field containing an array to search.
- * @param values The array that contains the values to match.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- arrayContainsAny:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field, the value must be an array, and that array must contain at least one value
- * from the provided array.
- *
- * A query can have only one `arrayContainsAny` filter and it cannot be combined with
- * `arrayContains` or `in` filters.
- *
- * @param path The path of the field containing an array to search.
- * @param values The array that contains the values to match.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- arrayContainsAny:(NSArray<id> *)values
- NS_SWIFT_NAME(whereField(_:arrayContainsAny:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field and the value must equal one of the values from the provided array.
- *
- * A query can have only one `in` filter, and it cannot be combined with an `arrayContainsAny`
- * filter.
- *
- * @param field The name of the field to search.
- * @param values The array that contains the values to match.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereField:(NSString *)field
- in:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must contain
- * the specified field and the value must equal one of the values from the provided array.
- *
- * A query can have only one `in` filter, and it cannot be combined with an `arrayContainsAny`
- * filter.
- *
- * @param path The path of the field to search.
- * @param values The array that contains the values to match.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path
- in:(NSArray<id> *)values NS_SWIFT_NAME(whereField(_:in:));
- /**
- * Creates and returns a new `FIRQuery` with the additional filter that documents must
- * satisfy the specified predicate.
- *
- * @param predicate The predicate the document must satisfy. Can be either comparison
- * or compound of comparison. In particular, block-based predicate is not supported.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryFilteredUsingPredicate:(NSPredicate *)predicate NS_SWIFT_NAME(filter(using:));
- #pragma mark - Sorting Data
- /**
- * Creates and returns a new `FIRQuery` that's additionally sorted by the specified field.
- *
- * @param field The field to sort by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryOrderedByField:(NSString *)field NS_SWIFT_NAME(order(by:));
- /**
- * Creates and returns a new `FIRQuery` that's additionally sorted by the specified field.
- *
- * @param path The field to sort by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)path NS_SWIFT_NAME(order(by:));
- /**
- * Creates and returns a new `FIRQuery` that's additionally sorted by the specified field,
- * optionally in descending order instead of ascending.
- *
- * @param field The field to sort by.
- * @param descending Whether to sort descending.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryOrderedByField:(NSString *)field
- descending:(BOOL)descending NS_SWIFT_NAME(order(by:descending:));
- /**
- * Creates and returns a new `FIRQuery` that's additionally sorted by the specified field,
- * optionally in descending order instead of ascending.
- *
- * @param path The field to sort by.
- * @param descending Whether to sort descending.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)path
- descending:(BOOL)descending NS_SWIFT_NAME(order(by:descending:));
- #pragma mark - Limiting Data
- /**
- * Creates and returns a new `FIRQuery` that only returns the first matching documents up to
- * the specified number.
- *
- * @param limit The maximum number of items to return.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryLimitedTo:(NSInteger)limit NS_SWIFT_NAME(limit(to:));
- /**
- * Creates and returns a new `FIRQuery` that only returns the last matching documents up to
- * the specified number.
- *
- * A query with a `limit(ToLast:)` clause must have at least one `orderBy` clause.
- *
- * @param limit The maximum number of items to return.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryLimitedToLast:(NSInteger)limit NS_SWIFT_NAME(limit(toLast:));
- #pragma mark - Choosing Endpoints
- /**
- * Creates and returns a new `FIRQuery` that starts at the provided document (inclusive). The
- * starting position is relative to the order of the query. The document must contain all of the
- * fields provided in the orderBy of this query.
- *
- * @param document The snapshot of the document to start at.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryStartingAtDocument:(FIRDocumentSnapshot *)document
- NS_SWIFT_NAME(start(atDocument:));
- /**
- * Creates and returns a new `FIRQuery` that starts at the provided fields relative to the order of
- * the query. The order of the field values must match the order of the order by clauses of the
- * query.
- *
- * @param fieldValues The field values to start this query at, in order of the query's order by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryStartingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(start(at:));
- /**
- * Creates and returns a new `FIRQuery` that starts after the provided document (exclusive). The
- * starting position is relative to the order of the query. The document must contain all of the
- * fields provided in the orderBy of this query.
- *
- * @param document The snapshot of the document to start after.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryStartingAfterDocument:(FIRDocumentSnapshot *)document
- NS_SWIFT_NAME(start(afterDocument:));
- /**
- * Creates and returns a new `FIRQuery` that starts after the provided fields relative to the order
- * of the query. The order of the field values must match the order of the order by clauses of the
- * query.
- *
- * @param fieldValues The field values to start this query after, in order of the query's order
- * by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryStartingAfterValues:(NSArray *)fieldValues NS_SWIFT_NAME(start(after:));
- /**
- * Creates and returns a new `FIRQuery` that ends before the provided document (exclusive). The end
- * position is relative to the order of the query. The document must contain all of the fields
- * provided in the orderBy of this query.
- *
- * @param document The snapshot of the document to end before.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryEndingBeforeDocument:(FIRDocumentSnapshot *)document
- NS_SWIFT_NAME(end(beforeDocument:));
- /**
- * Creates and returns a new `FIRQuery` that ends before the provided fields relative to the order
- * of the query. The order of the field values must match the order of the order by clauses of the
- * query.
- *
- * @param fieldValues The field values to end this query before, in order of the query's order by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryEndingBeforeValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(before:));
- /**
- * Creates and returns a new `FIRQuery` that ends at the provided document (exclusive). The end
- * position is relative to the order of the query. The document must contain all of the fields
- * provided in the orderBy of this query.
- *
- * @param document The snapshot of the document to end at.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryEndingAtDocument:(FIRDocumentSnapshot *)document NS_SWIFT_NAME(end(atDocument:));
- /**
- * Creates and returns a new `FIRQuery` that ends at the provided fields relative to the order of
- * the query. The order of the field values must match the order of the order by clauses of the
- * query.
- *
- * @param fieldValues The field values to end this query at, in order of the query's order by.
- *
- * @return The created `FIRQuery`.
- */
- - (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(at:));
- @end
- NS_ASSUME_NONNULL_END
|