Couchbase Lite
Objective-C API for iOS and Mac OS
CBLTimeSeries Class Reference

Detailed Description

Efficiently stores small time-stamped JSON values into a database, and can replicate them to a server (purging them as soon as they're pushed.)

Inheritance diagram for CBLTimeSeries:
CBLRemoteLogging

Public Types

typedef void(^ CBLTimeSeriesEnumerationBlock) (CBLJSONDict *event, CFAbsoluteTime time, BOOL *stop)
 Callback for single-document enumeration. More...
 

Instance Methods

(nullable instancetype) - initWithDatabase:docType:error:
 Initializes a new CBLTimeSeries. More...
 
(void) - addEvent:
 Adds an event, timestamped with the current time. More...
 
(void) - addEvent:atTime:
 Adds an event with a custom timestamp (which must be greater than the last timestamp.) Can be called on any thread. More...
 
(void) - flushAsync:
 Writes all pending events to documents asynchronously, then calls the onFlushed block (with parameter YES on success, NO if there were any errors.) Can be called on any thread. More...
 
(BOOL) - flush
 Writes all pending events to documents before returning. More...
 
(void) - stop
 Stops the CBLTimeSeries, immediately flushing all pending events. More...
 
(CBLReplication *) - createPushReplication:purgeWhenPushed:
 Creates, but does not start, a new CBLReplication to push the events to a remote database. More...
 
(NSEnumerator< CBLJSONDict * > *) - eventsFromDate:toDate:error:
 Enumerates the events stored in the database from time t0 to t1, inclusive. More...
 

Class Methods

(BOOL) + enumerateEventsInDocument:usingBlock:
 Enumerates the events in a single time-series document. More...
 

Properties

NSString * docType
 The "type" property that will be added to documents. More...
 
NSString * docIDPrefix
 A prefix for the IDs of documents created by this object. More...
 
NSError * lastError
 The latest error encountered. More...
 

Member Typedef Documentation

◆ CBLTimeSeriesEnumerationBlock

- (typedef void(^ CBLTimeSeriesEnumerationBlock) (CBLJSONDict *event, CFAbsoluteTime time, BOOL *stop))

Callback for single-document enumeration.

Parameters
eventThe event dictionary.
timeThe absolute timestamp.
stopSet the pointed-to BOOL to YES to stop enumeration.

Method Documentation

◆ initWithDatabase:docType:error:()

- (nullable instancetype) initWithDatabase: (CBLDatabase *)  db
docType: (NSString *)  docType
error: (NSError **)  error 

Initializes a new CBLTimeSeries.

Parameters
dbThe database to store events in.
docTypeThe document "type" property to use. Must be non-nil, and must not be used by any other documents or time-series in the database.
errorOn return, the error if any.

◆ addEvent:()

- (void) addEvent: (CBLJSONDict *)  event

Adds an event, timestamped with the current time.

Can be called on any thread.

◆ addEvent:atTime:()

- (void) addEvent: (CBLJSONDict *)  event
atTime: (CFAbsoluteTime)  time 

Adds an event with a custom timestamp (which must be greater than the last timestamp.) Can be called on any thread.

◆ flushAsync:()

- (void) flushAsync: (void(^)(BOOL))  onFlushed

Writes all pending events to documents asynchronously, then calls the onFlushed block (with parameter YES on success, NO if there were any errors.) Can be called on any thread.

◆ flush()

- (BOOL) flush

Writes all pending events to documents before returning.

Must be called on the database's thread.

Returns
YES on success, NO if there were any errors.

◆ stop()

- (void) stop

Stops the CBLTimeSeries, immediately flushing all pending events.

◆ createPushReplication:purgeWhenPushed:()

- (CBLReplication*) createPushReplication: (NSURL *)  remoteURL
purgeWhenPushed: (BOOL)  purgeWhenPushed 

Creates, but does not start, a new CBLReplication to push the events to a remote database.

You can customize the replication's properties before starting it, but don't alter the filter or remove the existing customProperties.

Parameters
remoteURLThe URL of the remote database to push to.
purgeWhenPushedIf YES, time-series documents will be purged from the local database immediately after they've been pushed. Use this if you don't need them anymore.
Returns
The CBLReplication instance.

◆ eventsFromDate:toDate:error:()

- (NSEnumerator<CBLJSONDict*>*) eventsFromDate: (nullable NSDate *)  startDate
toDate: (nullable NSDate *)  endDate
error: (NSError **)  outError 

Enumerates the events stored in the database from time t0 to t1, inclusive.

Each event returned from the NSEnumerator is an NSDictionary, as provided to -addEvent, with a key "t" whose value is the absolute time as an NSDate.

Parameters
startDateThe starting time (or nil to start from the beginning.)
endDateThe ending time (or nil to continue till the end.)
outErrorOn return, any error that occurred starting the enumeration.
Returns
An enumerator of NSDictionaries, one per event.

◆ enumerateEventsInDocument:usingBlock:()

+ (BOOL) enumerateEventsInDocument: (CBLJSONDict *)  doc
usingBlock: (CBLTimeSeriesEnumerationBlock block 

Enumerates the events in a single time-series document.

Useful in map blocks.

Parameters
docThe body of the document to enumerate.
blockA callback to be invoked on every event.
Returns
NO if the document is not a valid time-series, otherwise YES.

Property Documentation

◆ docType

- (NSString*) docType
readatomicassign

The "type" property that will be added to documents.

◆ docIDPrefix

- (NSString*) docIDPrefix
readwriteatomiccopy

A prefix for the IDs of documents created by this object.

Defaults to "TS-" + docType + "-".

◆ lastError

- (NSError*) lastError
readatomicassign

The latest error encountered.

Observable. (Note: May be modified on any thread.)


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