Live Query

Live Query

extends Query

A Couchbase Lite View Query that automatically refreshes every time the Database changes in a way that would affect the results.

Syntax


@interface CBLLiveQuery : CBLQuery
class CBLLiveQuery : CBLQuery
public class LiveQuery extends Query
public class LiveQuery extends Query
public class LiveQuery : Query

Summary


Constants
String
The name of the event raised by a LiveQuery in response to result set changes.
Events
The type of event raised when a LiveQuery result set changes.
Properties
Error
lastError { get; }
Returns the last error, if any, that occured while executing the Query, otherwise null.
QueryEnumerator
rows { get; }
Gets the results of the Query. The value will be null until the initial Query completes.
TimeSpan
updateInterval { get; set; }
The shortest interval at which the query will update, regardless of how often the database changes. Defaults to 0.2 sec. Increase this if the query is expensive and the database updates frequently, to limit CPU consumption.
Methods
void
Adds a LiveQuery change delegate that will be called whenever the Database changes in a way that would affect the results of the Query.
void
Removes the specified delegate as a listener for the LiveQuery change event.
void
start()
Starts the LiveQuery and begins observing Database changes. When the Database changes in a way that would affect the results of the Query, the rows property will be updated and any ChangeEvent listeners will be notified. Accessing the rows property or adding an ChangeEvent listener will automatically start the LiveQuery.
void
stop()
Stops the LiveQuery and stops observing Database changes and sending ChangeEvents.
void
Blocks until the intial Query completes.
Delegates
void
ChangeDelegate(ChangeEvent event)
A delegate that can be used to listen for LiveQuery result set changes.

Constants


String Change
The name of the event raised by a LiveQuery in response to result set changes.

Syntax

Not applicable.
Not applicable.
Not applicable.
Not applicable.
Not applicable.

Events


event ChangeEvent
The type of event raised when a LiveQuery result set changes.

Syntax

ChangeDelegate
ChangeDelegate
public interface ChangeEvent
public interface ChangeEvent
public class QueryChangeEventArgs : EventArgs

Properties


Error lastError { get; }
Returns the last error, if any, that occured while executing the Query, otherwise null.

Syntax

@property (readonly) NSError * lastError
var lastError: NSError! { get }
public Throwable getLastError()
public Throwable getLastError()
public Exception LastError { get; }
QueryEnumerator rows { get; }
Gets the results of the Query. The value will be null until the initial Query completes.

Syntax

@property (readonly) CBLQueryEnumerator * rows
var rows: CBLQueryEnumerator! { get }
public QueryEnumerator getRows()
public QueryEnumerator getRows()
public QueryEnumerator Rows { get; }
TimeSpan updateInterval { get; set; }
The shortest interval at which the query will update, regardless of how often the database changes. Defaults to 0.2 sec. Increase this if the query is expensive and the database updates frequently, to limit CPU consumption.

Syntax

@property NSTimeInterval updateInterval
var updateInterval: NSTimeInterval
Not applicable.
Not applicable.
public TimeSpan updateInterval { get; set; }

Methods


void addChangeListener( ChangeDelegate delegate)
Adds a LiveQuery change delegate that will be called whenever the Database changes in a way that would affect the results of the Query.

Parameters

delegate The Database change delegate to add.

Syntax

-(void)addObserver:(NSObject *)observer forKeyPath:@"rows" options:(NSKeyValueObservingOptions)options context:(void *)context
func addObserver(observer: NSObject, forKeyPath: String, options: NSKeyValueObservingOptions, context: UnsafeMutablePointer<Void>)
public void addChangeListener(ChangeListener listener)
public void addChangeListener(ChangeListener listener)
public event EventHandler<QueryChangeEventArgs> Change
void removeChangeListener( ChangeDelegate delegate)
Removes the specified delegate as a listener for the LiveQuery change event.

Parameters

delegate The Database change delegate to remove.

Syntax

-(void)removeObserver:(NSObject *)observer forKeyPath:@"rows"
func removeObserver(observer: NSObject, forKeyPath: String)
public void removeChangeListener(ChangeListener listener)
public void removeChangeListener(ChangeListener listener)
public event EventHandler<QueryChangeEventArgs> Change
void start()
Starts the LiveQuery and begins observing Database changes. When the Database changes in a way that would affect the results of the Query, the rows property will be updated and any ChangeEvent listeners will be notified. Accessing the rows property or adding an ChangeEvent listener will automatically start the LiveQuery.

Syntax

-(void)start
func start()
public void start()
public void start()
public void Start()
void stop()
Stops the LiveQuery and stops observing Database changes and sending ChangeEvents.

Syntax

-(void)stop
func stop()
public void stop()
public void stop()
public void Stop()
void waitForRows()
Blocks until the intial Query completes.

Errors

Returns an error if an issue occurs while executing the Query.

Syntax

-(BOOL)waitForRows:(NSError **)outError
func waitForRows(outError: NSErrorPointer) -> Bool
public void waitForRows() throws InterruptedException, ExecutionException
public void waitForRows() throws InterruptedException, ExecutionException
public void WaitForRows()

Delegates


void ChangeDelegate(ChangeEvent event)
A delegate that can be used to listen for LiveQuery result set changes.

Parameters

event The LiveQuery change event.

Syntax

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
func override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>)
public interface ChangeListener {
    void changed(ChangeEvent event);
}
public interface ChangeListener {
    void changed(ChangeEvent event);
}
Not applicable.