Couchbase Lite C
Couchbase Lite C API
Data Structures | Functions
CBLCollection.h File Reference
#include "CBLBase.h"
#include "CBLDocument.h"
#include "CBLQueryIndexTypes.h"
#include "CBLQueryTypes.h"

Go to the source code of this file.

Data Structures

struct  CBLCollectionChange
 
struct  CBLDocumentChange
 

Functions

static const CBLCollectionCBLCollection_Retain (const CBLCollection *t)
 
static void CBLCollection_Release (const CBLCollection *t)
 
Collection Accessors

Getting information about a collection.

CBLScopeCBLCollection_Scope (const CBLCollection *collection)
 Returns the collection's scope. More...
 
FLString CBLCollection_Name (const CBLCollection *collection)
 Returns the collection's name. More...
 
FLString CBLCollection_FullName (const CBLCollection *collection)
 Returns the collection's fully qualified name in the '<scope-name>. More...
 
CBLDatabaseCBLCollection_Database (const CBLCollection *collection)
 Returns the collection's database. More...
 
uint64_t CBLCollection_Count (const CBLCollection *collection)
 Returns the number of documents in the collection. More...
 
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. More...
 
bool CBLCollection_SaveDocument (CBLCollection *collection, CBLDocument *doc, CBLError *_cbl_nullable outError)
 Saves a (mutable) document to the collection. More...
 
bool CBLCollection_SaveDocumentWithConcurrencyControl (CBLCollection *collection, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
 Saves a (mutable) document to the collection. More...
 
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. More...
 
bool CBLCollection_DeleteDocument (CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError)
 Deletes a document from the collection. More...
 
bool CBLCollection_DeleteDocumentWithConcurrencyControl (CBLCollection *collection, const CBLDocument *document, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
 Deletes a document from the collection. More...
 
bool CBLCollection_PurgeDocument (CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError)
 Purges a document. More...
 
bool CBLCollection_PurgeDocumentByID (CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError)
 Purges a document, given only its ID. More...
 
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. More...
 
bool CBLCollection_SetDocumentExpiration (CBLCollection *collection, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError)
 Sets or clears the expiration time of a document. More...
 
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. More...
 
Query Indexes
bool CBLCollection_CreateValueIndex (CBLCollection *collection, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError)
 Creates a value index in the collection. More...
 
bool CBLCollection_CreateFullTextIndex (CBLCollection *collection, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError)
 Creates a full-text index in the collection. More...
 
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. More...
 
bool CBLCollection_CreateVectorIndex (CBLCollection *collection, FLString name, CBLVectorIndexConfiguration config, CBLError *_cbl_nullable outError)
 ENTERPRISE EDITION ONLY. More...
 
bool CBLCollection_DeleteIndex (CBLCollection *collection, FLString name, CBLError *_cbl_nullable outError)
 Deletes an index in the collection by name. More...
 
_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. More...
 
_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. More...
 

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.)

Note
If there are multiple CBLCollection instances on the same database file, each one's listeners will be notified of changes made by other collection instances.
Warning
Changes made to the database file by other processes will not be notified.
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. More...
 
_cbl_warn_unused CBLListenerTokenCBLCollection_AddChangeListener (const CBLCollection *collection, CBLCollectionChangeListener listener, void *_cbl_nullable context)
 Registers a collection change listener callback. More...
 

Document listeners

A document change listener lets you detect changes made to a specific document after they are persisted to the collection.

Note
If there are multiple CBLCollection instances on the same database file, each one's document listeners will be notified of changes made by other collection instances.
typedef void(* CBLCollectionDocumentChangeListener) (void *context, const CBLDocumentChange *change)
 A document change listener callback, invoked after a specific document is changed on disk. More...
 
_cbl_warn_unused CBLListenerTokenCBLCollection_AddDocumentChangeListener (const CBLCollection *collection, FLString docID, CBLCollectionDocumentChangeListener listener, void *_cbl_nullable context)
 Registers a document change listener callback. More...
 

Collection Management

CBL_PUBLIC const FLString kCBLDefaultCollectionName
 The default collection's name. More...
 
FLMutableArray _cbl_nullable CBLDatabase_ScopeNames (const CBLDatabase *db, CBLError *_cbl_nullable outError)
 Returns the names of all existing scopes in the database. More...
 
FLMutableArray _cbl_nullable CBLDatabase_CollectionNames (const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError)
 Returns the names of all collections in the scope. More...
 
CBLScope *_cbl_nullable CBLDatabase_Scope (const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError)
 Returns an existing scope with the given name. More...
 
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. More...
 
CBLCollection *_cbl_nullable CBLDatabase_CreateCollection (CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
 Create a new collection. More...
 
bool CBLDatabase_DeleteCollection (CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
 Delete an existing collection. More...
 
CBLScopeCBLDatabase_DefaultScope (const CBLDatabase *db, CBLError *_cbl_nullable outError)
 Returns the default scope. More...
 
CBLCollection *_cbl_nullable CBLDatabase_DefaultCollection (const CBLDatabase *db, CBLError *_cbl_nullable outError)
 Returns the default collection. More...