Couchbase Lite
Objective-C API for iOS and Mac OS
CBLQuery.h
Go to the documentation of this file.
1 //
2 // CBLQuery.h
3 // CouchbaseLite
4 //
5 // Created by Jens Alfke on 6/18/12.
6 // Copyright (c) 2012-2013 Couchbase, Inc. All rights reserved.
7 //
8 
9 #import "CBLBase.h"
10 
13 
15 
16 typedef NS_ENUM(unsigned, CBLAllDocsMode) {
17  kCBLAllDocs,
18  kCBLIncludeDeleted,
19  kCBLShowConflicts,
20  kCBLOnlyConflicts,
21  kCBLBySequence
22 };
23 
24 
26 typedef NS_ENUM(unsigned, CBLIndexUpdateMode) {
27  kCBLUpdateIndexBefore,
28  kCBLUpdateIndexNever,
29  kCBLUpdateIndexAfter
30 };
31 
32 
34 @interface CBLQuery : NSObject
35 
37 @property (readonly, nullable) CBLView* view;
38 
40 @property (readonly) CBLDatabase* database;
41 
43 @property NSUInteger limit;
44 
47 @property NSUInteger skip;
48 
50 @property BOOL descending;
51 
53 @property (copy, nullable) id startKey;
54 
56 @property (copy, nullable) id endKey;
57 
60 @property (copy, nullable) NSString* startKeyDocID;
61 
64 @property (copy, nullable) NSString* endKeyDocID;
65 
67 @property BOOL inclusiveStart;
68 
70 @property BOOL inclusiveEnd;
71 
84 @property NSUInteger prefixMatchLevel;
85 
91 @property (copy, nullable) CBLArrayOf(NSSortDescriptor*)* sortDescriptors;
92 
98 @property (strong, nullable) NSPredicate* postFilter;
99 
105 @property CBLIndexUpdateMode indexUpdateMode;
106 
108 @property (copy, nullable) NSArray* keys;
109 
112 @property BOOL mapOnly;
113 
115 @property NSUInteger groupLevel;
116 
121 @property BOOL prefetch;
122 
131 @property CBLAllDocsMode allDocsMode;
132 
135 - (nullable CBLQueryEnumerator*) run: (NSError**)outError;
136 
139 - (void) runAsync: (void (^)(CBLQueryEnumerator*, NSError*))onComplete __attribute__((nonnull));
140 
143 
144 - (instancetype) init NS_UNAVAILABLE;
145 
146 @end
147 
148 
151 @interface CBLLiveQuery : CBLQuery
152 
156 @property (nonatomic) NSTimeInterval updateInterval;
157 
161 - (void) start;
162 
164 - (void) stop;
165 
168 @property (readonly, strong, nullable) CBLQueryEnumerator* rows;
169 
172 - (BOOL) waitForRows;
173 
176 @property (readonly, nullable) NSError* lastError;
177 
180 - (void) queryOptionsChanged;
181 
182 @end
183 
184 
187 @interface CBLQueryEnumerator : NSEnumerator <NSCopying>
188 
190 @property (readonly) NSUInteger count;
191 
193 @property (readonly) UInt64 sequenceNumber;
194 
196 @property (readonly) BOOL stale;
197 
198 - (nullable CBLQueryRow*) nextObject;
199 
201 - (nullable CBLQueryRow*) nextRow;
202 
204 - (CBLQueryRow*) rowAtIndex: (NSUInteger)index;
205 
219 - (void) sortUsingDescriptors: (NSArray*)sortDescriptors;
220 
221 - (instancetype) init NS_UNAVAILABLE;
222 - (void) reset __attribute__((deprecated("call allObjects and iterate that array multiple times")));
223 
224 @end
225 
226 
229 @interface CBLQueryRow : NSObject
230 
232 @property (readonly) id key;
233 
236 @property (readonly, nullable) id value;
237 
241 @property (readonly, nullable) NSString* documentID;
242 
251 @property (readonly, nullable) NSString* sourceDocumentID;
252 
254 @property (readonly) NSString* documentRevisionID;
255 
256 @property (readonly) CBLDatabase* database;
257 
261 @property (readonly, nullable) CBLDocument* document;
262 
268 @property (readonly, nullable) CBLJSONDict* documentProperties;
269 
273 - (nullable id) keyAtIndex: (NSUInteger)index;
274 
276 //@property (readonly, nullable) id key0, key1, key2, key3;
277 @property (readonly, nullable) id key0;
278 @property (readonly, nullable) id key1;
279 @property (readonly, nullable) id key2;
280 @property (readonly, nullable) id key3;
281 
283 @property (readonly) UInt64 sequenceNumber;
284 
290 @property (readonly, nullable) CBLArrayOf(CBLSavedRevision*)* conflictingRevisions;
291 
292 - (instancetype) init NS_UNAVAILABLE;
293 
294 @end
295 
296 
CBLArrayOf(NSSortDescriptor *) *sortDescriptors
An optional array of NSSortDescriptor objects; overrides the default by-key ordering.
instancetype NS_UNAVAILABLE()
#define NS_ASSUME_NONNULL_BEGIN
Definition: CBLBase.h:20
A "view" in a CouchbaseLite database – essentially a persistent index managed by map/reduce...
Definition: CBLView.h:58
BOOL descending
Should the rows be returned in descending key order? Default value is NO.
Definition: CBLQuery.h:50
A CouchbaseLite database.
Definition: CBLDatabase.h:38
NSArray * keys
If non-nil, the query will fetch only the rows with the given keys.
Definition: CBLQuery.h:108
A CBLQuery subclass that automatically refreshes the result rows every time the database changes...
Definition: CBLQuery.h:151
NSUInteger groupLevel
If non-zero, enables grouping of results, in views that have reduce functions.
Definition: CBLQuery.h:115
BOOL inclusiveEnd
If YES (the default) the endKey (or endKeyDocID) comparison uses "<=".
Definition: CBLQuery.h:70
CBLLiveQuery * asLiveQuery()
Returns a live query with the same parameters.
CBLIndexUpdateMode indexUpdateMode
Determines whether or when the view index is updated.
Definition: CBLQuery.h:105
#define nullable
Definition: CBLBase.h:22
id startKey
If non-nil, the key value to start at.
Definition: CBLQuery.h:53
NSUInteger prefixMatchLevel
If nonzero, enables prefix matching of string or array keys.
Definition: CBLQuery.h:84
NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(unsigned, CBLAllDocsMode)
Definition: CBLQuery.h:16
Represents a query of a CouchbaseLite &#39;view&#39;, or of a view-like resource like _all_documents.
Definition: CBLQuery.h:34
NSString * startKeyDocID
If non-nil, the document ID to start at.
Definition: CBLQuery.h:60
A CouchbaseLite document (as opposed to any specific revision of it.)
Definition: CBLDocument.h:16
NSUInteger limit
The maximum number of rows to return.
Definition: CBLQuery.h:43
#define NS_ASSUME_NONNULL_END
Definition: CBLBase.h:21
CBLAllDocsMode allDocsMode
Changes the behavior of a query created by -createAllDocumentsQuery.
Definition: CBLQuery.h:131
A result row from a CouchbaseLite view query.
Definition: CBLQuery.h:229
NSPredicate * postFilter
An optional predicate that filters the resulting query rows.
Definition: CBLQuery.h:98
NSUInteger skip
The number of initial rows to skip.
Definition: CBLQuery.h:47
Enumerator on a CBLQuery&#39;s result rows.
Definition: CBLQuery.h:187
BOOL prefetch
If set to YES, the results will include the entire document contents of the associated rows...
Definition: CBLQuery.h:121
An existing revision of a CBLDocument.
Definition: CBLRevision.h:80
CBLView * view
The view being queried; nil if this is an all-documents query.
Definition: CBLQuery.h:37
BOOL inclusiveStart
If YES (the default) the startKey (or startKeyDocID) comparison uses ">=".
Definition: CBLQuery.h:67
NSString * endKeyDocID
If non-nil, the document ID to end at.
Definition: CBLQuery.h:64
id endKey
If non-nil, the key value to end after.
Definition: CBLQuery.h:56
BOOL mapOnly
If set to YES, disables use of the reduce function.
Definition: CBLQuery.h:112
CBLDatabase * database
The database being queried.
Definition: CBLQuery.h:40