Couchbase Lite
Objective-C API for iOS and Mac OS
CBLView.h
Go to the documentation of this file.
1 //
2 // CBLView.h
3 // CouchbaseLite
4 //
5 // Created by Jens Alfke on 6/19/12.
6 // Copyright (c) 2012-2013 Couchbase, Inc. All rights reserved.
7 //
8 
9 #import <Foundation/Foundation.h>
10 @class CBLDatabase, CBLQuery;
11 
13 
14 
15 typedef enum {
20 
21 
22 typedef void (^CBLMapEmitBlock)(id key, __nullable id value);
23 
24 
28 typedef void (^CBLMapBlock)(CBLJSONDict* doc, CBLMapEmitBlock emit);
29 
35 typedef __nonnull id (^CBLReduceBlock)(NSArray* __nonnull keys,
36  NSArray* __nonnull values,
37  BOOL rereduce);
38 
39 
40 #define MAPBLOCK(BLOCK) ^(CBLJSONDict* doc, void (^emit)(id key, id value)){BLOCK}
41 #define REDUCEBLOCK(BLOCK) ^id(NSArray* keys, NSArray* values, BOOL rereduce){BLOCK}
42 
43 
46 FOUNDATION_EXTERN id CBLTextKey(NSString* text);
47 
49 @protocol CBLViewCompiler <NSObject>
50 - (nullable CBLMapBlock) compileMapFunction: (NSString*)mapSource language: (NSString*)language;
51 - (nullable CBLReduceBlock) compileReduceFunction: (NSString*)reduceSource
52  language: (NSString*)language;
53 @end
54 
55 
58 @interface CBLView : NSObject
59 
61 @property (readonly) CBLDatabase* database;
62 
64 @property (readonly) NSString* name;
65 
67 @property (readonly, nullable) CBLMapBlock mapBlock;
68 
70 @property (readonly, nullable) CBLReduceBlock reduceBlock;
71 
81 - (BOOL) setMapBlock: (CBLMapBlock)mapBlock
82  reduceBlock: (nullable CBLReduceBlock)reduceBlock
83  version: (NSString*)version;
84 
87 - (BOOL) setMapBlock: (CBLMapBlock)mapBlock
88  version: (NSString*)version;
89 
94 @property (copy) NSString* documentType;
95 
97 @property (readonly) BOOL stale;
98 
100 @property (readonly) SInt64 lastSequenceIndexed;
101 
104 @property (readonly) NSUInteger totalRows;
105 
111 - (void) updateIndex;
112 
116 - (void) updateIndexAsync: (void (^)())onComplete;
117 
119 - (void) deleteIndex;
120 
122 - (void) deleteView;
123 
125 - (CBLQuery*) createQuery;
126 
128 + (NSNumber*) totalValues: (NSArray*)values;
129 
131 + (void) setCompiler: (nullable id<CBLViewCompiler>)compiler;
132 
134 + (nullable id<CBLViewCompiler>) compiler;
135 
136 - (instancetype) init NS_UNAVAILABLE;
137 
138 @end
139 
140 
#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
SInt64 lastSequenceIndexed
The last sequence number indexed so far.
Definition: CBLView.h:100
A CouchbaseLite database.
Definition: CBLDatabase.h:38
#define __nullable
Definition: CBLBase.h:23
CBLViewIndexType
Definition: CBLView.h:15
__nonnull id(^ CBLReduceBlock)(NSArray *__nonnull keys, NSArray *__nonnull values, BOOL rereduce)
A "reduce" function called to summarize the results of a view.
Definition: CBLView.h:35
#define nullable
Definition: CBLBase.h:22
Keys must be strings and will be indexed by the words they contain.
Definition: CBLView.h:17
Represents a query of a CouchbaseLite &#39;view&#39;, or of a view-like resource like _all_documents.
Definition: CBLQuery.h:34
BOOL stale
Is the view&#39;s index currently out of date?
Definition: CBLView.h:97
NSUInteger totalRows
Total number of rows in the view.
Definition: CBLView.h:104
CBLMapBlock mapBlock
The map function that controls how index rows are created from documents.
Definition: CBLView.h:67
NSString * name
The name of the view.
Definition: CBLView.h:64
FOUNDATION_EXTERN id CBLTextKey(NSString *text)
Returns a special value that, when emitted as a key, causes the given text to be indexed with the ful...
Regular map/reduce index with JSON keys.
Definition: CBLView.h:16
#define NS_ASSUME_NONNULL_END
Definition: CBLBase.h:21
nullable id< CBLViewCompiler > compiler()
The registered object, if any, that can compile map/reduce functions from source code.
void deleteIndex()
Deletes the view&#39;s persistent index.
void(^ CBLMapBlock)(CBLJSONDict *doc, CBLMapEmitBlock emit)
A "map" function called when a document is to be added to a view.
Definition: CBLView.h:28
CBLQuery * createQuery()
Creates a new query object for this view.
void(^ CBLMapEmitBlock)(id key, __nullable id value)
Definition: CBLView.h:22
void deleteView()
Deletes the view, persistently.
instancetype NS_UNAVAILABLE()
CBLReduceBlock reduceBlock
The optional reduce function, which aggregates together multiple rows.
Definition: CBLView.h:70
void updateIndex()
Updates the view&#39;s index, then returns YES if the index changed or NO if it didn&#39;t.
CBLDatabase * database
The database that owns this view.
Definition: CBLView.h:61
NSString * documentType
If this property is set, only documents whose "type" property is equal to its value will be passed to...
Definition: CBLView.h:94
Geo-query index; not supported yet.
Definition: CBLView.h:18