![]() |
Couchbase Lite
Objective-C API for iOS and Mac OS
|
A "view" in a CouchbaseLite database – essentially a persistent index managed by map/reduce.
The view can be queried using a CBLQuery.
Instance Methods | |
| (BOOL) | - setMapBlock:reduceBlock:version: |
| Defines a view's functions. More... | |
| (BOOL) | - setMapBlock:version: |
| Defines a view that has no reduce function. More... | |
| (void) | - updateIndex |
| Updates the view's index, then returns YES if the index changed or NO if it didn't. More... | |
| (void) | - updateIndexAsync: |
| Asynchronously updates the view's index. More... | |
| (void) | - deleteIndex |
| Deletes the view's persistent index. More... | |
| (void) | - deleteView |
| Deletes the view, persistently. More... | |
| (CBLQuery *) | - createQuery |
| Creates a new query object for this view. More... | |
| (instancetype) | - NS_UNAVAILABLE |
Class Methods | |
| (NSNumber *) | + totalValues: |
| Utility function to use in reduce blocks. More... | |
| (void) | + setCompiler: |
| Registers an object that can compile map/reduce functions from source code. More... | |
| (nullable id< CBLViewCompiler >) | + compiler |
| The registered object, if any, that can compile map/reduce functions from source code. More... | |
Properties | |
| CBLDatabase * | database |
| The database that owns this view. More... | |
| NSString * | name |
| The name of the view. More... | |
| CBLMapBlock | mapBlock |
| The map function that controls how index rows are created from documents. More... | |
| CBLReduceBlock | reduceBlock |
| The optional reduce function, which aggregates together multiple rows. More... | |
| NSString * | documentType |
| If this property is set, only documents whose "type" property is equal to its value will be passed to the map block and indexed. More... | |
| BOOL | stale |
| Is the view's index currently out of date? More... | |
| SInt64 | lastSequenceIndexed |
| The last sequence number indexed so far. More... | |
| NSUInteger | totalRows |
| Total number of rows in the view. More... | |
| - (BOOL) setMapBlock: | (CBLMapBlock) | mapBlock | |
| reduceBlock: | (nullable CBLReduceBlock) | reduceBlock | |
| version: | (NSString *) | version | |
Defines a view's functions.
The view's definition is given as an Objective-C block (or NULL to delete the view). The body of the block should call the 'emit' block (passed in as a paramter) for every key/value pair it wants to write to the view. Since the function itself is obviously not stored in the database (only a unique string identifying it), you must re-define the view on every launch of the app! If the database needs to rebuild the view but the function hasn't been defined yet, it will fail and the view will be empty, causing weird problems later on. It is very important that this block be a law-abiding map function! As in other languages, it must be a "pure" function, with no side effects, that always emits the same values given the same input document. That means that it should not access or change any external state; be careful, since blocks make that so easy that you might do it inadvertently! The block may be called on any thread, or on multiple threads simultaneously. This won't be a problem if the code is "pure" as described above, since it will as a consequence also be thread-safe.
| mapBlock | The map function. The MAPBLOCK macro makes it easier to declare this. |
| reduceBlock | The reduce function, or nil for none. The REDUCEBLOCK macro makes it easier to declare this. |
| version | An arbitrary string that will be stored persistently along with the index. Usually a string literal like "1". If you subsequently change the functionality of the map or reduce function, change this string as well: the call will detect that it's different and will clear the index so it can be rebuilt by the new function. |
| - (BOOL) setMapBlock: | (CBLMapBlock) | mapBlock | |
| version: | (NSString *) | version | |
Defines a view that has no reduce function.
See -setMapBlock:reduceBlock:version: for more details.
| - (void) updateIndex |
Updates the view's index, then returns YES if the index changed or NO if it didn't.
Indexing scans all documents that have changed since the last time the index was updated. The body of each document is passed to the view's map block, and any emitted rows are added to the index. Any existing rows previously emitted by those documents, that weren't re-emitted this time, are removed.
| - (void) updateIndexAsync: | (void(^)()) | onComplete |
Asynchronously updates the view's index.
This method returns immediately, after scheduling a call to -updateIndex on a background thread; the onComplete callback block is called after indexing finishes.
| - (void) deleteIndex |
Deletes the view's persistent index.
It will be regenerated on the next query.
| - (void) deleteView |
Deletes the view, persistently.
| - (CBLQuery*) createQuery |
Creates a new query object for this view.
The query can be customized and then executed.
| + (NSNumber*) totalValues: | (NSArray *) | values |
Utility function to use in reduce blocks.
Totals an array of NSNumbers.
| + (void) setCompiler: | (nullable id< CBLViewCompiler >) | compiler |
Registers an object that can compile map/reduce functions from source code.
| + (nullable id<CBLViewCompiler>) compiler |
The registered object, if any, that can compile map/reduce functions from source code.
| - (instancetype) NS_UNAVAILABLE |
|
readatomicassign |
The database that owns this view.
|
readatomicassign |
The name of the view.
|
readatomicassign |
The map function that controls how index rows are created from documents.
|
readatomicassign |
The optional reduce function, which aggregates together multiple rows.
|
readwriteatomiccopy |
If this property is set, only documents whose "type" property is equal to its value will be passed to the map block and indexed.
This can speed up indexing. Just like the map block, this property is not persistent; it needs to be set at runtime before the view is queried. And if its value changes, the view's version also needs to change.
|
readatomicassign |
Is the view's index currently out of date?
|
readatomicassign |
The last sequence number indexed so far.
|
readatomicassign |
Total number of rows in the view.
The view's index will be updated if needed before returning the totalRows value.