View

View

A Couchbase Lite View. A View defines a persistent index managed by map/reduce.

Syntax


@interface CBLView : NSObject
class CBLView : NSObject
public class View
public class View
public class View

Summary


Properties
static ViewCompiler
compiler { get; set; }
Gets or sets an object that can compile source code into map and reduce delegates.
Database
database { get; }
Gets the Database that owns the View.
String
documentType { get; set; }
If the document type 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.
boolean
isStale { get; }
Gets if the View's indes is currently out of date.
long
Gets the last sequence number indexed so far.
MapDelegate
map { get; }
Gets the View's MapDelegate.
String
name { get; }
Get s the View's name.
ReduceDelegate
reduce { get; }
long
totalRows { get; }
The total number of rows currently stored in the view's index.
Methods
Query
Creates a new Query for this view.
void
delete()
Deletes the View.
void
Deletes the View's persistent index. The index is regenerated on the next Query execution.
boolean
setMap( MapDelegate map, String version)
Defines the View's MapDelegate and sets its ReduceDelegate to null.
boolean
setMapReduce( MapDelegate map, ReduceDelegate reduce, String version)
Defines the View's MapDelegate and ReduceDelegate.
void
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.
Delegates
void
EmitDelegate(Object key, Object value)
A delegate that can be invoked to add key/values to a View during a MapDelegate call.
void
MapDelegate(Map<String, Object> document, EmitDelegate emit)
A delegate that is invoked when a Documents is being added to a View.
Object
ReduceDelegate(Object[] keys, Object[] values, boolean rereduce)
A delegate that can be invoked to summarize the results of a View.

Properties


static ViewCompiler compiler { get; set; }
Gets or sets an object that can compile source code into map and reduce delegates.

Syntax

+(id<CBLViewCompiler>)compiler
+(void)setCompiler:(id<CBLViewCompiler>)compiler
class func compiler() -> CBLViewCompiler!
class func setCompiler(compiler: CBLViewCompiler!)
public static ViewCompiler getCompiler()
public static void setCompiler(ViewCompiler compiler)
public static ViewCompiler getCompiler()
public static void setCompiler(ViewCompiler compiler)
public static IViewCompiler Compiler { get; set; }
Database database { get; }
Gets the Database that owns the View.

Syntax

@property (readonly) CBLDatabase * database
var database: CBLDatabase! { get }
public Database getDatabase()
public Database getDatabase()
public Database Database { get; }
String documentType { get; set; }
If the document type 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.

Syntax

@property (copy) NSString* documentType;
var documentType: String
public String getDocumentType()
public void setDocumentType()
public String getDocumentType()
public void setDocumentType()
public string DocumentType { get; set; }
boolean isStale { get; }
Gets if the View's indes is currently out of date.

Syntax

@property (readonly) BOOL stale
var stale: Bool { get }
public boolean isStale()
public boolean isStale()
public Boolean IsStale { get; }
long lastSequenceIndexed { get; }
Gets the last sequence number indexed so far.

Syntax

@property (readonly) SInt64 lastSequenceIndexed
var lastSequenceIndexed: Int64 { get }
public long getLastSequenceIndexed()
public long getLastSequenceIndexed()
public long LastSequenceIndexed { get; }
MapDelegate map { get; }
Gets the View's MapDelegate.

Syntax

@property (readonly) CBLMapBlock * mapBlock
var mapBlock: CBLMapBlock! { get }
public Mapper getMap()
public Mapper getMap()
public MapDelegate Map { get; }
String name { get; }
Get s the View's name.

Syntax

@property (readonly) NSString * name
name: String! { get }
public String getName()
public String getName()
public String Name { get; }
ReduceDelegate reduce { get; }

Syntax

@property (readonly) CBLReduceBlock * reduceBlock
var reduceBlock: CBLReduceBlock! { get }
public ReduceDelegate getReduce()
public ReduceDelegate getReduce()
public ReduceDelegate Reduce { get; }
long totalRows { get; }
The total number of rows currently stored in the view's index.

Syntax

@property (readonly) NSUInteger totalRows
var totalRows: UInt { get }
public int getTotalRows()
public int getTotalRows()
public int totalRows { get; }

Methods


Query createQuery()
Creates a new Query for this view.

Returns

A new Query for this view.

Syntax

-(CBLQuery *)createQuery
func createQuery() -> CBLQuery!
public Query createQuery()
public Query createQuery()
public Query CreateQuery()
void delete()
Deletes the View.

Syntax

-(void)deleteView
func deleteView()
public void delete()
public void delete()
public void Delete()
void deleteIndex()
Deletes the View's persistent index. The index is regenerated on the next Query execution.

Syntax

-(void)deleteIndex
func deleteIndex()
public void deleteIndex()
public void deleteIndex()
public void DeleteIndex()
boolean setMap( MapDelegate map, String version)
Defines the View's MapDelegate and sets its ReduceDelegate to null.

Parameters

map The MapDelegate to set.
version The key of the property value to return. The value of this parameter must change when the MapDelegate is changed in a way that will cause it to produce different results.

Returns

True if the MapDelegate was set, otherwise false. If the values provided are identical to the values that are already set, then the values will not be updated and false will be returned. In addition, if true is returned, the index was deleted and will be rebuilt on the next Query execution.

Syntax

-(BOOL)setMapBlock:(CBLMapBlock)mapBlock version:(NSString *)version
func setMapBlock(mapBlock: CBLMapBlock!, version: String!) -> Bool
public boolean setMap(Mapper map, String version)
public boolean setMap(Mapper map, String version)
public Boolean SetMap(MapDelegate map, String version)
boolean setMapReduce( MapDelegate map, ReduceDelegate reduce, String version)
Defines the View's MapDelegate and ReduceDelegate.

Parameters

map The MapDelegate to set.
reduce The ReduceDelegate to set.
version The key of the property value to return. The value of this parameter must change when the MapDelegate and/or ReduceDelegate are changed in a way that will cause them to produce different results.

Returns

True if the MapDelegate and ReduceDelegate were set, otherwise false. If the values provided are identical to the values that are already set, then the values will not be updated and false will be returned. In addition, if true is returned, the index was deleted and will be rebuilt on the next Query execution.

Syntax

-(BOOL)setMapBlock:(CBLMapBlock)mapBlock reduceBlock:(CBLReduceBlock)reduceBlock version:(NSString *)version
func setMapBlock(mapBlock: CBLMapBlock!, reduceBlock: CBLReduceBlock!, version: String!) -> Bool
public boolean setMapReduce(Mapper map, Reducer reduce, String version)
public boolean setMapReduce(Mapper map, Reducer reduce, String version)
public Boolean SetMapReduce(MapDelegate map, ReduceDelegate reduce, String version)
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.

Syntax

-(void) updateIndex
func updateIndex()
public Status updateIndex()
public Status updateIndex()
public void UpdateIndex()

Delegates


void EmitDelegate(Object key, Object value)
A delegate that can be invoked to add key/values to a View during a MapDelegate call.

Parameters

key The key.
value The value.

Syntax

typedef void (^CBLMapEmitBlock)(id key, id value)
typealias CBLMapEmitBlock = (AnyObject!, AnyObject!) -> Void
public interface Emitter {
    void emit(Object key, Object value);
}
public interface Emitter {
    void emit(Object key, Object value);
}
public delegate void EmitDelegate(Object key, Object value);
void MapDelegate(Map<String, Object> document, EmitDelegate emit)
A delegate that is invoked when a Documents is being added to a View.

Parameters

document The Document being mapped.
emit The delegate to use to add key/values to the View.

Syntax

typedef void (^CBLMapBlock)(NSDictionary * doc, CBLMapEmitBlock emit)
typealias CBLMapBlock = ([NSObject : AnyObject]!, CBLMapEmitBlock!) -> Void
public interface Mapper {
    void map(Map<String, Object> document, Emitter emitter);
}
public interface Mapper {
    void map(Map<String, Object> document, Emitter emitter);
}
public delegate void MapDelegate(Dictionary<String, Object> document, EmitDelegate emit);
Object ReduceDelegate(Object[] keys, Object[] values, boolean rereduce)
A delegate that can be invoked to summarize the results of a View.

Parameters

keys A list of keys to be reduced, or null if this is a rereduce.
values A parallel array of values to be reduced, corresponding 1-to-1 with the keys.
rereduce True if the input values are the results of previous reductions, otherwise false.

Returns

The reduced value.

Syntax

typedef id (^CBLReduceBlock)(NSArray * keys, NSArray * values, BOOL rereduce)
typealias CBLReduceBlock = ([AnyObject]!, [AnyObject]!, Bool) -> AnyObject!
public interface Reducer {
    Object reduce(List<Object> keys, List<Object> values, boolean rereduce);
}
public interface Reducer {
    Object reduce(List<Object> keys, List<Object> values, boolean rereduce);
}
public delegate Object ReduceDelegate(IEnumerable<Object> keys, IEnumerable<Object> values, Boolean rereduce);