![]() |
Couchbase Lite
Objective-C API for iOS and Mac OS
|
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.)
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... | |
| - (typedef void(^ CBLTimeSeriesEnumerationBlock) (CBLJSONDict *event, CFAbsoluteTime time, BOOL *stop)) |
Callback for single-document enumeration.
| event | The event dictionary. |
| time | The absolute timestamp. |
| stop | Set the pointed-to BOOL to YES to stop enumeration. |
| - (nullable instancetype) initWithDatabase: | (CBLDatabase *) | db | |
| docType: | (NSString *) | docType | |
| error: | (NSError **) | error | |
Initializes a new CBLTimeSeries.
| db | The database to store events in. |
| docType | The document "type" property to use. Must be non-nil, and must not be used by any other documents or time-series in the database. |
| error | On return, the error if any. |
| - (void) addEvent: | (CBLJSONDict *) | event |
Adds an event, timestamped with the current time.
Can be called on any thread.
| - (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.
| - (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.
| - (BOOL) flush |
Writes all pending events to documents before returning.
Must be called on the database's thread.
| - (void) stop |
Stops the CBLTimeSeries, immediately flushing all pending events.
| - (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.
| remoteURL | The URL of the remote database to push to. |
| purgeWhenPushed | If 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. |
| - (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.
| startDate | The starting time (or nil to start from the beginning.) |
| endDate | The ending time (or nil to continue till the end.) |
| outError | On return, any error that occurred starting the enumeration. |
| + (BOOL) enumerateEventsInDocument: | (CBLJSONDict *) | doc | |
| usingBlock: | (CBLTimeSeriesEnumerationBlock) | block | |
Enumerates the events in a single time-series document.
Useful in map blocks.
| doc | The body of the document to enumerate. |
| block | A callback to be invoked on every event. |
|
readatomicassign |
The "type" property that will be added to documents.
|
readwriteatomiccopy |
A prefix for the IDs of documents created by this object.
Defaults to "TS-" + docType + "-".
|
readatomicassign |
The latest error encountered.
Observable. (Note: May be modified on any thread.)