|
Couchbase Lite C
Couchbase Lite C API
|
A CBLDocument is essentially a JSON object with an ID string that's unique in its database. More...
Typedefs | |
| typedef struct CBLDocument | CBLDocument |
| An in-memory copy of a document. | |
Variables | |
| CBL_PUBLIC const FLSlice | kCBLTypeProperty |
| "@type" | |
Document lifecycle | |
| enum | CBLConcurrencyControl : uint8_t { kCBLConcurrencyControlLastWriteWins , kCBLConcurrencyControlFailOnConflict } |
| typedef bool(* | CBLConflictHandler) (void *_cbl_nullable context, CBLDocument *_cbl_nullable documentBeingSaved, const CBLDocument *_cbl_nullable conflictingDocument) |
| Custom conflict handler for use when saving or deleting a document. | |
| _cbl_warn_unused const CBLDocument *_cbl_nullable | CBLDatabase_GetDocument (const CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError) |
| Reads a document from the default collection in an immutable form. | |
| CBLINLINE const CBLDocument * | CBLDocument_Retain (const CBLDocument *_cbl_nullable t) |
| CBLINLINE void | CBLDocument_Release (const CBLDocument *_cbl_nullable t) |
| bool | CBLDatabase_SaveDocument (CBLDatabase *db, CBLDocument *doc, CBLError *_cbl_nullable outError) |
| Saves a (mutable) document to the default collection. | |
| bool | CBLDatabase_SaveDocumentWithConcurrencyControl (CBLDatabase *db, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError) |
| Saves a (mutable) document to the default collection. | |
| bool | CBLDatabase_SaveDocumentWithConflictHandler (CBLDatabase *db, CBLDocument *doc, CBLConflictHandler conflictHandler, void *_cbl_nullable context, CBLError *_cbl_nullable outError) |
Saves a (mutable) document to the default collection, allowing for custom conflict handling in the event that the document has been updated since doc was loaded. | |
| bool | CBLDatabase_DeleteDocument (CBLDatabase *db, const CBLDocument *document, CBLError *_cbl_nullable outError) |
| Deletes a document from the default collection. | |
| bool | CBLDatabase_DeleteDocumentWithConcurrencyControl (CBLDatabase *db, const CBLDocument *document, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError) |
| Deletes a document from the default collection. | |
| bool | CBLDatabase_PurgeDocument (CBLDatabase *db, const CBLDocument *document, CBLError *_cbl_nullable outError) |
| Purges a document from the default collection. | |
| bool | CBLDatabase_PurgeDocumentByID (CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError) |
| Purges a document by its ID from the default collection. | |
Document listeners | |
A document change listener lets you detect changes made to a specific document after they are persisted to the database.
| |
| typedef void(* | CBLDocumentChangeListener) (void *context, const CBLDatabase *db, FLString docID) |
| A document change listener callback, invoked after a specific document is changed on disk. | |
| _cbl_warn_unused CBLListenerToken * | CBLDatabase_AddDocumentChangeListener (const CBLDatabase *db, FLString docID, CBLDocumentChangeListener listener, void *_cbl_nullable context) |
| Registers a document change listener callback. | |
Mutable documents | |
The type CBLDocument* without a const qualifier refers to a mutable document instance. A mutable document exposes its properties as a mutable dictionary, so you can change them in place and then call CBLCollection_SaveDocument to persist the changes. | |
| _cbl_warn_unused CBLDocument *_cbl_nullable | CBLDatabase_GetMutableDocument (CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError) |
| Reads a document from the default collection in mutable form that can be updated and saved. | |
| _cbl_warn_unused CBLDocument * | CBLDocument_Create (void) |
| Creates a new, empty document in memory, with a randomly-generated unique ID. | |
| _cbl_warn_unused CBLDocument * | CBLDocument_CreateWithID (FLString docID) |
| Creates a new, empty document in memory, with the given ID. | |
| _cbl_warn_unused CBLDocument * | CBLDocument_MutableCopy (const CBLDocument *original) |
| Creates a new mutable CBLDocument instance that refers to the same document as the original. | |
Document properties and metadata | |
A document's body is essentially a JSON object. The properties are accessed in memory using the Fleece API, with the body itself being a dictionary). | |
| FLString | CBLDocument_ID (const CBLDocument *) |
| Returns a document's ID. | |
| FLString | CBLDocument_RevisionID (const CBLDocument *) |
| Returns a document's revision ID, which is a short opaque string that's guaranteed to be unique to every change made to the document. | |
| uint64_t | CBLDocument_Sequence (const CBLDocument *) |
| Returns a document's current sequence in the local database. | |
| CBLCollection *_cbl_nullable | CBLDocument_Collection (const CBLDocument *) |
| Returns a document's collection or NULL for the new document that hasn't been saved. | |
| FLDict | CBLDocument_Properties (const CBLDocument *) |
| Returns a document's properties as a dictionary. | |
| FLMutableDict | CBLDocument_MutableProperties (CBLDocument *) |
| Returns a mutable document's properties as a mutable dictionary. | |
| void | CBLDocument_SetProperties (CBLDocument *, FLMutableDict properties) |
| Sets a mutable document's properties. | |
| _cbl_warn_unused FLSliceResult | CBLDocument_CreateJSON (const CBLDocument *) |
| Returns a document's properties as JSON. | |
| bool | CBLDocument_SetJSON (CBLDocument *, FLSlice json, CBLError *_cbl_nullable outError) |
| Sets a mutable document's properties from a JSON string. | |
| CBLTimestamp | CBLDatabase_GetDocumentExpiration (CBLDatabase *db, FLSlice docID, CBLError *_cbl_nullable outError) |
| Returns the time, if any, at which a given document will expire and be purged. | |
| bool | CBLDatabase_SetDocumentExpiration (CBLDatabase *db, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError) |
| Sets or clears the expiration time of a document. | |
A CBLDocument is essentially a JSON object with an ID string that's unique in its database.
| typedef bool(* CBLConflictHandler) (void *_cbl_nullable context, CBLDocument *_cbl_nullable documentBeingSaved, const CBLDocument *_cbl_nullable conflictingDocument) |
Custom conflict handler for use when saving or deleting a document.
This handler is called if the save would cause a conflict, i.e. if the document in the database has been updated (probably by a pull replicator, or by application code on another thread) since it was loaded into the CBLDocument being saved.
| context | The value of the context parameter you passed to CBLCollection_SaveDocumentWithConflictHandler. |
| documentBeingSaved | The document being saved (same as the parameter you passed to CBLCollection_SaveDocumentWithConflictHandler.) The callback may modify this document's properties as necessary to resolve the conflict. |
| conflictingDocument | The revision of the document currently in the database, which has been changed since documentBeingSaved was loaded. May be NULL, meaning that the document has been deleted. |
| typedef struct CBLDocument CBLDocument |
An in-memory copy of a document.
CBLDocument objects can be mutable or immutable. Immutable objects are referenced by const pointers; mutable ones by non-const pointers. This prevents you from accidentally calling a mutable-document function on an immutable document.
| typedef void(* CBLDocumentChangeListener) (void *context, const CBLDatabase *db, FLString docID) |
A document change listener callback, invoked after a specific document is changed on disk.
| context | An arbitrary value given when the callback was registered. |
| db | The database containing the document. |
| docID | The document's ID. |
| enum CBLConcurrencyControl : uint8_t |
| _cbl_warn_unused CBLListenerToken * CBLDatabase_AddDocumentChangeListener | ( | const CBLDatabase * | db, |
| FLString | docID, | ||
| CBLDocumentChangeListener | listener, | ||
| void *_cbl_nullable | context ) |
Registers a document change listener callback.
It will be called after a specific document is changed on disk.
| db | The database to observe. |
| docID | The ID of the document to observe. |
| listener | The callback to be invoked. |
| context | An opaque value that will be passed to the callback. |
| bool CBLDatabase_DeleteDocument | ( | CBLDatabase * | db, |
| const CBLDocument * | document, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes a document from the default collection.
Deletions are replicated.
| db | The database. |
| document | The document to delete. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_DeleteDocumentWithConcurrencyControl | ( | CBLDatabase * | db, |
| const CBLDocument * | document, | ||
| CBLConcurrencyControl | concurrency, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes a document from the default collection.
Deletions are replicated.
| db | The database. |
| document | The document to delete. |
| concurrency | Conflict-handling strategy. |
| outError | On failure, the error will be written here. |
| _cbl_warn_unused const CBLDocument *_cbl_nullable CBLDatabase_GetDocument | ( | const CBLDatabase * | database, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Reads a document from the default collection in an immutable form.
Each call to this function creates a new object (which must later be released.)
| database | The database. |
| docID | The ID of the document. |
| outError | On failure, the error will be written here. (A nonexistent document is not considered a failure; in that event the error code will be zero.) |
| CBLTimestamp CBLDatabase_GetDocumentExpiration | ( | CBLDatabase * | db, |
| FLSlice | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Returns the time, if any, at which a given document will expire and be purged.
Documents don't normally expire; you have to call CBLDatabase_SetDocumentExpiration to set a document's expiration time.
| db | The database. |
| docID | The ID of the document. |
| outError | On failure, an error is written here. |
| _cbl_warn_unused CBLDocument *_cbl_nullable CBLDatabase_GetMutableDocument | ( | CBLDatabase * | database, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Reads a document from the default collection in mutable form that can be updated and saved.
(This function is otherwise identical to CBLDatabase_GetDocument.)
| database | The database. |
| docID | The ID of the document. |
| outError | On failure, the error will be written here. (A nonexistent document is not considered a failure; in that event the error code will be zero.) |
| bool CBLDatabase_PurgeDocument | ( | CBLDatabase * | db, |
| const CBLDocument * | document, | ||
| CBLError *_cbl_nullable | outError ) |
Purges a document from the default collection.
This removes all traces of the document. Purges are not replicated. If the document is changed on a server, it will be re-created when pulled.
| db | The database. |
| document | The document to purge. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_PurgeDocumentByID | ( | CBLDatabase * | database, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Purges a document by its ID from the default collection.
| database | The database. |
| docID | The document ID to purge. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_SaveDocument | ( | CBLDatabase * | db, |
| CBLDocument * | doc, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the default collection.
doc was loaded, it will be overwritten by this one. This can lead to data loss! To avoid this, call CBLDatabase_SaveDocumentWithConcurrencyControl or CBLDatabase_SaveDocumentWithConflictHandler instead. | db | The database. |
| doc | The mutable document to save. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_SaveDocumentWithConcurrencyControl | ( | CBLDatabase * | db, |
| CBLDocument * | doc, | ||
| CBLConcurrencyControl | concurrency, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the default collection.
If a conflicting revision has been saved since doc was loaded, the concurrency parameter specifies whether the save should fail, or the conflicting revision should be overwritten with the revision being saved. If you need finer-grained control, call CBLDatabase_SaveDocumentWithConflictHandler instead.
| db | The database. |
| doc | The mutable document to save. |
| concurrency | Conflict-handling strategy (fail or overwrite). |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_SaveDocumentWithConflictHandler | ( | CBLDatabase * | db, |
| CBLDocument * | doc, | ||
| CBLConflictHandler | conflictHandler, | ||
| void *_cbl_nullable | context, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the default collection, allowing for custom conflict handling in the event that the document has been updated since doc was loaded.
| db | The database. |
| doc | The mutable document to save. |
| conflictHandler | The callback to be invoked if there is a conflict. |
| context | An arbitrary value to be passed to the conflictHandler. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_SetDocumentExpiration | ( | CBLDatabase * | db, |
| FLSlice | docID, | ||
| CBLTimestamp | expiration, | ||
| CBLError *_cbl_nullable | outError ) |
Sets or clears the expiration time of a document.
| db | The database. |
| docID | The ID of the document. |
| expiration | The expiration time as a CBLTimestamp (milliseconds since Unix epoch), or 0 if the document should never expire. |
| outError | On failure, an error is written here. |
| CBLCollection *_cbl_nullable CBLDocument_Collection | ( | const CBLDocument * | ) |
Returns a document's collection or NULL for the new document that hasn't been saved.
| _cbl_warn_unused CBLDocument * CBLDocument_Create | ( | void | ) |
Creates a new, empty document in memory, with a randomly-generated unique ID.
It will not be added to a database until saved.
| _cbl_warn_unused FLSliceResult CBLDocument_CreateJSON | ( | const CBLDocument * | ) |
Returns a document's properties as JSON.
| _cbl_warn_unused CBLDocument * CBLDocument_CreateWithID | ( | FLString | docID | ) |
Creates a new, empty document in memory, with the given ID.
It will not be added to a database until saved.
| docID | The ID of the new document, or NULL to assign a new unique ID. |
| FLString CBLDocument_ID | ( | const CBLDocument * | ) |
Returns a document's ID.
| _cbl_warn_unused CBLDocument * CBLDocument_MutableCopy | ( | const CBLDocument * | original | ) |
Creates a new mutable CBLDocument instance that refers to the same document as the original.
If the original document has unsaved changes, the new one will also start out with the same changes; but mutating one document thereafter will not affect the other.
| FLMutableDict CBLDocument_MutableProperties | ( | CBLDocument * | ) |
Returns a mutable document's properties as a mutable dictionary.
You may modify this dictionary and then call CBLCollection_SaveDocument to persist the changes.
| FLDict CBLDocument_Properties | ( | const CBLDocument * | ) |
Returns a document's properties as a dictionary.
| CBLINLINE void CBLDocument_Release | ( | const CBLDocument *_cbl_nullable | t | ) |
| CBLINLINE const CBLDocument * CBLDocument_Retain | ( | const CBLDocument *_cbl_nullable | t | ) |
| FLString CBLDocument_RevisionID | ( | const CBLDocument * | ) |
Returns a document's revision ID, which is a short opaque string that's guaranteed to be unique to every change made to the document.
If the document doesn't exist yet, this function returns NULL.
| uint64_t CBLDocument_Sequence | ( | const CBLDocument * | ) |
Returns a document's current sequence in the local database.
This number increases every time the document is saved, and a more recently saved document will have a greater sequence number than one saved earlier, so sequences may be used as an abstract 'clock' to tell relative modification times.
| bool CBLDocument_SetJSON | ( | CBLDocument * | , |
| FLSlice | json, | ||
| CBLError *_cbl_nullable | outError ) |
Sets a mutable document's properties from a JSON string.
| void CBLDocument_SetProperties | ( | CBLDocument * | , |
| FLMutableDict | properties ) |
Sets a mutable document's properties.
Call CBLCollection_SaveDocument to persist the changes.
|
extern |
"@type"