|
Couchbase Lite C
Couchbase Lite C API
|
A CBLCollection represent a collection which is a container for documents. More...
Data Structures | |
| struct | CBLCollectionChange |
| struct | CBLDocumentChange |
Typedefs | |
| typedef struct CBLCollection | CBLCollection |
| A collection, a document container. | |
Functions | |
| static const CBLCollection * | CBLCollection_Retain (const CBLCollection *_cbl_nullable t) |
| static void | CBLCollection_Release (const CBLCollection *_cbl_nullable t) |
Change Listeners | |
A collection change listener lets you detect changes made to all documents in a collection. (If you want to observe specific documents, use a CBLCollectionDocumentChangeListener instead.)
| |
| typedef void(* | CBLCollectionChangeListener) (void *_cbl_nullable context, const CBLCollectionChange *change) |
| A collection change listener callback, invoked after one or more documents are changed on disk. | |
| _cbl_warn_unused CBLListenerToken * | CBLCollection_AddChangeListener (const CBLCollection *collection, CBLCollectionChangeListener listener, void *_cbl_nullable context) |
| Registers a collection change listener callback. | |
Document listeners | |
A document change listener lets you detect changes made to a specific document after they are persisted to the collection.
| |
| typedef void(* | CBLCollectionDocumentChangeListener) (void *context, const CBLDocumentChange *change) |
| A document change listener callback, invoked after a specific document is changed on disk. | |
| _cbl_warn_unused CBLListenerToken * | CBLCollection_AddDocumentChangeListener (const CBLCollection *collection, FLString docID, CBLCollectionDocumentChangeListener listener, void *_cbl_nullable context) |
| Registers a document change listener callback. | |
Collection Management | |
| CBL_PUBLIC const FLString | kCBLDefaultCollectionName |
| The default collection's name. | |
| FLMutableArray _cbl_nullable | CBLDatabase_ScopeNames (const CBLDatabase *db, CBLError *_cbl_nullable outError) |
| Returns the names of all existing scopes in the database. | |
| FLMutableArray _cbl_nullable | CBLDatabase_CollectionNames (const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError) |
| Returns the names of all collections in the scope. | |
| CBLScope *_cbl_nullable | CBLDatabase_Scope (const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError) |
| Returns an existing scope with the given name. | |
| CBLCollection *_cbl_nullable | CBLDatabase_Collection (const CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError) |
| Returns the existing collection with the given name and scope. | |
| CBLCollection *_cbl_nullable | CBLDatabase_CreateCollection (CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError) |
| Create a new collection. | |
| bool | CBLDatabase_DeleteCollection (CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError) |
| Delete an existing collection. | |
| CBLScope * | CBLDatabase_DefaultScope (const CBLDatabase *db, CBLError *_cbl_nullable outError) |
| Returns the default scope. | |
| CBLCollection *_cbl_nullable | CBLDatabase_DefaultCollection (const CBLDatabase *db, CBLError *_cbl_nullable outError) |
| Returns the default collection. | |
Collection Accessors | |
Getting information about a collection. | |
| CBLScope * | CBLCollection_Scope (const CBLCollection *collection) |
| Returns the collection's scope. | |
| FLString | CBLCollection_Name (const CBLCollection *collection) |
| Returns the collection's name. | |
| FLString | CBLCollection_FullName (const CBLCollection *collection) |
| Returns the collection's fully qualified name in the '<scope-name>. | |
| CBLDatabase * | CBLCollection_Database (const CBLCollection *collection) |
| Returns the collection's database. | |
| uint64_t | CBLCollection_Count (const CBLCollection *collection) |
| Returns the number of documents in the collection. | |
Document lifecycle | |
| _cbl_warn_unused const CBLDocument *_cbl_nullable | CBLCollection_GetDocument (const CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError) |
| Reads a document from the collection, creating a new (immutable) CBLDocument object. | |
| bool | CBLCollection_SaveDocument (CBLCollection *collection, CBLDocument *doc, CBLError *_cbl_nullable outError) |
| Saves a (mutable) document to the collection. | |
| bool | CBLCollection_SaveDocumentWithConcurrencyControl (CBLCollection *collection, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError) |
| Saves a (mutable) document to the collection. | |
| bool | CBLCollection_SaveDocumentWithConflictHandler (CBLCollection *collection, CBLDocument *doc, CBLConflictHandler conflictHandler, void *_cbl_nullable context, CBLError *_cbl_nullable outError) |
Saves a (mutable) document to the collection, allowing for custom conflict handling in the event that the document has been updated since doc was loaded. | |
| bool | CBLCollection_DeleteDocument (CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError) |
| Deletes a document from the collection. | |
| bool | CBLCollection_DeleteDocumentWithConcurrencyControl (CBLCollection *collection, const CBLDocument *document, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError) |
| Deletes a document from the collection. | |
| bool | CBLCollection_PurgeDocument (CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError) |
| Purges a document. | |
| bool | CBLCollection_PurgeDocumentByID (CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError) |
| Purges a document, given only its ID. | |
| CBLTimestamp | CBLCollection_GetDocumentExpiration (CBLCollection *collection, FLSlice docID, CBLError *_cbl_nullable outError) |
| Returns the time, if any, at which a given document will expire and be purged. | |
| bool | CBLCollection_SetDocumentExpiration (CBLCollection *collection, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError) |
| Sets or clears the expiration time of a document. | |
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 | CBLCollection_GetMutableDocument (CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError) |
| Reads a document from the collection, in mutable form that can be updated and saved. | |
Query Indexes | |
| bool | CBLCollection_CreateValueIndex (CBLCollection *collection, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError) |
| Creates a value index in the collection. | |
| bool | CBLCollection_CreateFullTextIndex (CBLCollection *collection, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError) |
| Creates a full-text index in the collection. | |
| bool | CBLCollection_CreateArrayIndex (CBLCollection *collection, FLString name, CBLArrayIndexConfiguration config, CBLError *_cbl_nullable outError) |
| Creates an array index for use with UNNEST queries in the collection. | |
| bool | CBLCollection_CreateVectorIndex (CBLCollection *collection, FLString name, CBLVectorIndexConfiguration config, CBLError *_cbl_nullable outError) |
| ENTERPRISE EDITION ONLY. | |
| bool | CBLCollection_DeleteIndex (CBLCollection *collection, FLString name, CBLError *_cbl_nullable outError) |
| Deletes an index in the collection by name. | |
| _cbl_warn_unused FLMutableArray _cbl_nullable | CBLCollection_GetIndexNames (CBLCollection *collection, CBLError *_cbl_nullable outError) |
| Returns the names of the indexes in the collection, as a Fleece array of strings. | |
| _cbl_warn_unused CBLQueryIndex *_cbl_nullable | CBLCollection_GetIndex (CBLCollection *collection, FLString name, CBLError *_cbl_nullable outError) |
| Returns an index object representing an existing index in the collection. | |
A CBLCollection represent a collection which is a container for documents.
A collection can be thought as a table in the relational database. Each collection belongs to a scope which is simply a namespce, and has a name which is unique within its scope.
When a new database is created, a default collection named "_default" will be automatically created. The default collection is created under the default scope named "_default". The name of the default collection and scope can be referenced by using kCBLDefaultCollectionName and kCBLDefaultScopeName constant.
When creating a new collection, the collection name, and the scope name are required. The naming rules of the collections and scopes are as follows:
CBLCollection is ref-counted. Same as the CBLDocument, the CBLCollection objects created or retrieved from the database must be released after you are done using them. When the database is closed or released, the collection objects will become invalid, most operations on the invalid CBLCollection object will fail with either the kCBLErrorNotOpen error or null/zero/empty result.
When using the legacy database, the existing documents and indexes in the database will be automatically migrated to the default collection.
Any pre-existing database functions that refer to documents, listeners, and indexes without specifying a collection such as CBLDatabase_GetDocument will implicitly operate on the default collection. In other words, they behave exactly the way they used to, but collection-aware code should avoid them and use the new Collection API instead. These legacy functions are deprecated and will be removed eventually.
| typedef struct CBLCollection CBLCollection |
A collection, a document container.
| typedef void(* CBLCollectionChangeListener) (void *_cbl_nullable context, const CBLCollectionChange *change) |
A collection change listener callback, invoked after one or more documents are changed on disk.
| context | An arbitrary value given when the callback was registered. |
| change | The collection change information. |
| typedef void(* CBLCollectionDocumentChangeListener) (void *context, const CBLDocumentChange *change) |
A document change listener callback, invoked after a specific document is changed on disk.
| context | An arbitrary value given when the callback was registered. |
| change | The document change info. |
| _cbl_warn_unused CBLListenerToken * CBLCollection_AddChangeListener | ( | const CBLCollection * | collection, |
| CBLCollectionChangeListener | listener, | ||
| void *_cbl_nullable | context ) |
Registers a collection change listener callback.
It will be called after one or more documents are changed on disk.
| Collection | The collection to observe. |
| listener | The callback to be invoked. |
| context | An opaque value that will be passed to the callback. |
| _cbl_warn_unused CBLListenerToken * CBLCollection_AddDocumentChangeListener | ( | const CBLCollection * | collection, |
| FLString | docID, | ||
| CBLCollectionDocumentChangeListener | listener, | ||
| void *_cbl_nullable | context ) |
Registers a document change listener callback.
It will be called after a specific document is changed on disk.
| Collection | The collection 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. |
| uint64_t CBLCollection_Count | ( | const CBLCollection * | collection | ) |
Returns the number of documents in the collection.
| Collection | The collection. |
| bool CBLCollection_CreateArrayIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLArrayIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
Creates an array index for use with UNNEST queries in the collection.
If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| Collection | The collection. |
| name | The name of the index. |
| config | The index configuration. |
| outError | On failure, an error is written here. |
| bool CBLCollection_CreateFullTextIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLFullTextIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
Creates a full-text index in the collection.
If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| Collection | The collection. |
| name | The name of the index. |
| config | The index configuration. |
| outError | On failure, an error is written here. |
| bool CBLCollection_CreateValueIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLValueIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
Creates a value index in the collection.
If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| Collection | The collection. |
| name | The name of the index. |
| config | The index configuration. |
| outError | On failure, an error is written here. |
| bool CBLCollection_CreateVectorIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLVectorIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
ENTERPRISE EDITION ONLY.
Creatres a vector index in the collection. If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| CBLDatabase * CBLCollection_Database | ( | const CBLCollection * | collection | ) |
Returns the collection's database.
| Collection | The collection. |
| bool CBLCollection_DeleteDocument | ( | CBLCollection * | collection, |
| const CBLDocument * | document, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes a document from the collection.
Deletions are replicated.
| Collection | The collection containing the document. |
| document | The document to delete. |
| outError | On failure, the error will be written here. |
| bool CBLCollection_DeleteDocumentWithConcurrencyControl | ( | CBLCollection * | collection, |
| const CBLDocument * | document, | ||
| CBLConcurrencyControl | concurrency, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes a document from the collection.
Deletions are replicated.
| Collection | The collection containing the document. |
| document | The document to delete. |
| concurrency | Conflict-handling strategy. |
| outError | On failure, the error will be written here. |
| bool CBLCollection_DeleteIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes an index in the collection by name.
| Collection | The collection. |
| name | The name of the index. |
| outError | On failure, an error is written here. |
| FLString CBLCollection_FullName | ( | const CBLCollection * | collection | ) |
Returns the collection's fully qualified name in the '<scope-name>.
<collection-name>' format.
| Collection | The collection. |
| _cbl_warn_unused const CBLDocument *_cbl_nullable CBLCollection_GetDocument | ( | const CBLCollection * | collection, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Reads a document from the collection, creating a new (immutable) CBLDocument object.
Each call to this function creates a new object (which must later be released.)
| Collection | The collection. |
| 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 CBLCollection_GetDocumentExpiration | ( | CBLCollection * | collection, |
| 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 CBLCollection_SetDocumentExpiration to set a document's expiration time.
| Collection | The collection. |
| docID | The ID of the document. |
| outError | On failure, an error is written here. |
| _cbl_warn_unused CBLQueryIndex *_cbl_nullable CBLCollection_GetIndex | ( | CBLCollection * | collection, |
| FLString | name, | ||
| CBLError *_cbl_nullable | outError ) |
Returns an index object representing an existing index in the collection.
| Collection | The collection. |
| name | The name of the index. |
| outError | On failure, an error is written here. |
| _cbl_warn_unused FLMutableArray _cbl_nullable CBLCollection_GetIndexNames | ( | CBLCollection * | collection, |
| CBLError *_cbl_nullable | outError ) |
Returns the names of the indexes in the collection, as a Fleece array of strings.
| Collection | The collection. |
| outError | On failure, an error is written here. |
| _cbl_warn_unused CBLDocument *_cbl_nullable CBLCollection_GetMutableDocument | ( | CBLCollection * | collection, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Reads a document from the collection, in mutable form that can be updated and saved.
(This function is otherwise identical to CBLCollection_GetDocument.)
| Collection | The collection. |
| 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.) |
| FLString CBLCollection_Name | ( | const CBLCollection * | collection | ) |
Returns the collection's name.
| Collection | The collection. |
| bool CBLCollection_PurgeDocument | ( | CBLCollection * | collection, |
| const CBLDocument * | document, | ||
| CBLError *_cbl_nullable | outError ) |
Purges a document.
This removes all traces of the document from the collection. Purges are not replicated. If the document is changed on a server, it will be re-created when pulled.
| Collection | The collection containing the document. |
| document | The document to delete. |
| outError | On failure, the error will be written here. |
| bool CBLCollection_PurgeDocumentByID | ( | CBLCollection * | collection, |
| FLString | docID, | ||
| CBLError *_cbl_nullable | outError ) |
Purges a document, given only its ID.
| Collection | The collection. |
| docID | The document ID to purge. |
| outError | On failure, the error will be written here. |
|
inlinestatic |
|
inlinestatic |
| bool CBLCollection_SaveDocument | ( | CBLCollection * | collection, |
| CBLDocument * | doc, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the collection.
| Collection | The collection to save to. |
| doc | The mutable document to save. |
| outError | On failure, the error will be written here. |
| bool CBLCollection_SaveDocumentWithConcurrencyControl | ( | CBLCollection * | collection, |
| CBLDocument * | doc, | ||
| CBLConcurrencyControl | concurrency, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the 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 CBLCollection_SaveDocumentWithConflictHandler instead.
| Collection | The collection to save to. |
| doc | The mutable document to save. |
| concurrency | Conflict-handling strategy (fail or overwrite). |
| outError | On failure, the error will be written here. |
| bool CBLCollection_SaveDocumentWithConflictHandler | ( | CBLCollection * | collection, |
| CBLDocument * | doc, | ||
| CBLConflictHandler | conflictHandler, | ||
| void *_cbl_nullable | context, | ||
| CBLError *_cbl_nullable | outError ) |
Saves a (mutable) document to the collection, allowing for custom conflict handling in the event that the document has been updated since doc was loaded.
| Collection | The collection to save to. |
| 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. |
| CBLScope * CBLCollection_Scope | ( | const CBLCollection * | collection | ) |
Returns the collection's scope.
| Collection | The collection. |
| bool CBLCollection_SetDocumentExpiration | ( | CBLCollection * | collection, |
| FLSlice | docID, | ||
| CBLTimestamp | expiration, | ||
| CBLError *_cbl_nullable | outError ) |
Sets or clears the expiration time of a document.
| Collection | The collection. |
| 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 CBLDatabase_Collection | ( | const CBLDatabase * | db, |
| FLString | collectionName, | ||
| FLString | scopeName, | ||
| CBLError *_cbl_nullable | outError ) |
Returns the existing collection with the given name and scope.
| db | The database. |
| collectionName | The name of the collection. |
| scopeName | The name of the scope. |
| outError | On failure, the error will be written here. |
| FLMutableArray _cbl_nullable CBLDatabase_CollectionNames | ( | const CBLDatabase * | db, |
| FLString | scopeName, | ||
| CBLError *_cbl_nullable | outError ) |
Returns the names of all collections in the scope.
| db | The database. |
| scopeName | The name of the scope. |
| outError | On failure, the error will be written here. |
| CBLCollection *_cbl_nullable CBLDatabase_CreateCollection | ( | CBLDatabase * | db, |
| FLString | collectionName, | ||
| FLString | scopeName, | ||
| CBLError *_cbl_nullable | outError ) |
Create a new collection.
The naming rules of the collections and scopes are as follows:
| db | The database. |
| collectionName | The name of the collection. |
| scopeName | The name of the scope. |
| outError | On failure, the error will be written here. |
| CBLCollection *_cbl_nullable CBLDatabase_DefaultCollection | ( | const CBLDatabase * | db, |
| CBLError *_cbl_nullable | outError ) |
Returns the default collection.
| db | The database. |
| outError | On failure, the error will be written here. |
| CBLScope * CBLDatabase_DefaultScope | ( | const CBLDatabase * | db, |
| CBLError *_cbl_nullable | outError ) |
Returns the default scope.
| db | The database. |
| outError | On failure, the error will be written here. |
| bool CBLDatabase_DeleteCollection | ( | CBLDatabase * | db, |
| FLString | collectionName, | ||
| FLString | scopeName, | ||
| CBLError *_cbl_nullable | outError ) |
Delete an existing collection.
| db | The database. |
| collectionName | The name of the collection. |
| scopeName | The name of the scope. |
| outError | On failure, the error will be written here. |
| CBLScope *_cbl_nullable CBLDatabase_Scope | ( | const CBLDatabase * | db, |
| FLString | scopeName, | ||
| CBLError *_cbl_nullable | outError ) |
Returns an existing scope with the given name.
The scope exists when there is at least one collection created under the scope.
| db | The database. |
| scopeName | The name of the scope. |
| outError | On failure, the error will be written here. |
| FLMutableArray _cbl_nullable CBLDatabase_ScopeNames | ( | const CBLDatabase * | db, |
| CBLError *_cbl_nullable | outError ) |
Returns the names of all existing scopes in the database.
The scope exists when there is at least one collection created under the scope.
| db | The database. |
| outError | On failure, the error will be written here. |
|
extern |
The default collection's name.