Couchbase Lite
Objective-C API for iOS and Mac OS
Instance Methods | Class Methods | Properties | List of all members
CBLView Class Reference

A "view" in a CouchbaseLite database – essentially a persistent index managed by map/reduce. More...

#import <CBLView.h>

Inheritance diagram for CBLView:

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) - 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...
 

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...
 
(id< CBLViewCompiler >) + compiler
 The registered object, if any, that can compile map/reduce functions from source code. More...
 

Properties

CBLDatabasedatabase
 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...
 
BOOL stale
 Is the view's index currently out of date? More...
 
SInt64 lastSequenceIndexed
 The last sequence number indexed so far. More...
 

Detailed Description

A "view" in a CouchbaseLite database – essentially a persistent index managed by map/reduce.

The view can be queried using a CBLQuery.

Method Documentation

- (BOOL) setMapBlock: (CBLMapBlock mapBlock
reduceBlock: (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 idenfitying 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.

Parameters
mapBlockThe map function. The MAPBLOCK macro makes it easier to declare this.
reduceBlockThe reduce function, or nil for none. The REDUCEBLOCK macro makes it easier to declare this.
versionAn 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.
Returns
YES if the view was updated and the index cleared; NO if the version stayed the same.
- (BOOL) setMapBlock: (CBLMapBlock mapBlock
version: (NSString *)  version 

Defines a view that has no reduce function.

See -setMapBlock:reduceBlock:version: for more details.

- (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: (id< CBLViewCompiler >)  compiler

Registers an object that can compile map/reduce functions from source code.

+ (id<CBLViewCompiler>) compiler

The registered object, if any, that can compile map/reduce functions from source code.

Property Documentation

- (CBLDatabase*) database
readatomicassign

The database that owns this view.

- (NSString*) name
readatomicassign

The name of the view.

- (CBLMapBlock) mapBlock
readatomicassign

The map function that controls how index rows are created from documents.

- (CBLReduceBlock) reduceBlock
readatomicassign

The optional reduce function, which aggregates together multiple rows.

- (BOOL) stale
readatomicassign

Is the view's index currently out of date?

- (SInt64) lastSequenceIndexed
readatomicassign

The last sequence number indexed so far.


The documentation for this class was generated from the following file: