|
Couchbase Lite C++
Couchbase Lite C++ API
|
A Collection is a container for documents within a database. More...
#include <cbl++/Collection.hh>
Public Types | |
| using | CollectionChangeListener = cbl::ListenerToken<CollectionChange*> |
| Collection Change Listener Token. | |
| using | CollectionDocumentChangeListener = cbl::ListenerToken<DocumentChange*> |
| Document Change Listener Token. | |
Public Member Functions | |
| std::string | name () const |
| The collection's name. | |
| std::string | fullName () const |
| The collection's fully qualified name in the '<scope-name>. | |
| std::string | scopeName () const |
| The scope's name. | |
| Database | database () const |
| The collection's database. | |
| uint64_t | count () const |
| The number of documents in the collection. | |
| Document | getDocument (std::string_view docID) const |
| Reads a document from the collection in an immutable form. | |
| MutableDocument | getMutableDocument (std::string_view docID) const |
| Reads a document from the collection in mutable form that can be updated and saved. | |
| void | saveDocument (MutableDocument &doc) |
| Saves a (mutable) document to the collection. | |
| bool | saveDocument (MutableDocument &doc, CBLConcurrencyControl concurrency) |
| Saves a (mutable) document to the collection. | |
| bool | saveDocument (MutableDocument &doc, CollectionConflictHandler handler) |
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. | |
| void | deleteDocument (Document &doc) |
| Deletes a document from the collection. | |
| bool | deleteDocument (Document &doc, CBLConcurrencyControl concurrency) |
| Deletes a document from the collection. | |
| void | purgeDocument (Document &doc) |
| Purges a document from the collection. | |
| bool | purgeDocument (std::string_view docID) |
| Purges a document by its ID from the collection. | |
| time_t | getDocumentExpiration (std::string_view docID) const |
| Returns the time, if any, at which a given document in the collection will expire and be purged. | |
| void | setDocumentExpiration (std::string_view docID, time_t expiration) |
| Sets or clears the expiration time of a document in the collection. | |
| void | createValueIndex (std::string_view name, ValueIndexConfiguration config) |
| Creates a value index in the collection. | |
| void | createFullTextIndex (std::string_view name, FullTextIndexConfiguration config) |
| Creates a full-text index in the collection. | |
| void | createArrayIndex (std::string_view name, ArrayIndexConfiguration config) |
| Creates an array index for use with UNNEST queries in the collection. | |
| void | createVectorIndex (std::string_view name, VectorIndexConfiguration config) |
| Creates a vector index in the collection. | |
| void | deleteIndex (std::string_view name) |
| Deletes an index given its name from the collection. | |
| fleece::RetainedArray | getIndexNames () |
| Returns the names of the indexes in the collection, as a Fleece array of strings. | |
| QueryIndex | getIndex (std::string_view name) |
| Get an index by name. | |
| CollectionChangeListener | addChangeListener (CollectionChangeListener::Callback callback) |
| Registers a collection change listener callback. | |
| CollectionDocumentChangeListener | addDocumentChangeListener (std::string_view docID, CollectionDocumentChangeListener::Callback callback) |
| Registers a document change listener callback. | |
| Collection () noexcept | |
| Constructs a null reference (one that points to no object). | |
| Collection & | operator= (std::nullptr_t) |
| Releases the underlying object and resets this to a null reference. | |
| bool | valid () const |
| Returns true if this references an object, or false if it is a null reference. | |
| operator bool () const | |
| Returns true if this references an object (same as valid). | |
| bool | operator== (const Collection &other) const |
| Returns true if both sides reference the same object, or are both null references. | |
| bool | operator!= (const Collection &other) const |
| Returns true if the two sides reference different objects. | |
| CBLCollection *_Nullable | ref () const |
| Returns a pointer to the underlying C object (CBLCollection), or NULL if this is a null reference. | |
| Collection (const Collection &other) noexcept | |
Copy constructor: creates another reference to the same object as other. | |
| Collection (Collection &&other) noexcept | |
Move constructor: takes over the reference from other, leaving it a null reference. | |
| Collection & | operator= (const Collection &other) noexcept |
Copy assignment: replaces this reference with a reference to other's object. | |
| Collection & | operator= (Collection &&other) noexcept |
Move assignment: replaces this reference with other's, leaving other a null reference. | |
Protected Member Functions | |
| Collection (CBLCollection *_Nullable ref) | |
| (Internal) Constructs a reference wrapping, and retaining, a C object pointer. | |
Static Protected Member Functions | |
| static Collection | adopt (const CBLCollection *_Nullable d, CBLError *error) |
Friends | |
| class | Database |
| class | Document |
| class | QueryIndex |
A Collection is a container for documents within a database.
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". You may decide to delete the default collection, but noted that the default collection cannot be re-created. 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:
Collection Change Listener Token.
Document Change Listener Token.
|
inlinenoexcept |
Constructs a null reference (one that points to no object).
|
inlineexplicitprotected |
(Internal) Constructs a reference wrapping, and retaining, a C object pointer.
|
inlinenoexcept |
Copy constructor: creates another reference to the same object as other.
|
inlinenoexcept |
Move constructor: takes over the reference from other, leaving it a null reference.
|
inlinenodiscard |
Registers a collection change listener callback.
It will be called after one or more documents in the collection are changed on disk.
| callback | The callback to be invoked. |
|
inlinenodiscard |
Registers a document change listener callback.
It will be called after a specific document in the collection is changed on disk.
| docID | The ID of the document to observe. |
| callback | The callback to be invoked. |
|
inlinestaticprotected |
|
inline |
The number of documents in the collection.
|
inline |
Creates an array index for use with UNNEST queries in the collection.
Indexes are persistent. 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.
| name | The index name. |
| config | The array index config. |
|
inline |
Creates a full-text index in the collection.
Indexes are persistent. 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.
| name | The index name. |
| config | The full-text index config. |
|
inline |
Creates a value index in the collection.
Indexes are persistent. 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.
| name | The index name. |
| config | The value index config. |
|
inline |
Creates 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.
| name | The index name. |
| config | The vector index config. |
|
inline |
The collection's database.
|
inline |
Deletes a document from the collection.
Deletions are replicated.
| doc | The document to delete. |
|
inline |
Deletes a document from the collection.
Deletions are replicated.
| doc | The document to delete. |
| concurrency | Conflict-handling strategy. |
|
inline |
Deletes an index given its name from the collection.
|
inline |
The collection's fully qualified name in the '<scope-name>.
<collection-name>' format.
|
inline |
Reads a document from the collection in an immutable form.
| docID | The ID of the document. |
| cbl::Error | On a database error. Note a non-existent document is not an error — that returns a falsy Document rather than throwing. |
|
inline |
Returns the time, if any, at which a given document in the collection will expire and be purged.
Documents don't normally expire; you have to call Collection::setDocumentExpiration(std::string_view docID, time_t expiration) to set a document's expiration time.
| docID | The ID of the document. |
|
inline |
Get an index by name.
If the index doesn't exist, a falsy QueryIndex object will be returned.
|
inline |
Returns the names of the indexes in the collection, as a Fleece array of strings.
|
inline |
Reads a document from the collection in mutable form that can be updated and saved.
(This function is otherwise identical to Collection::getDocument.)
| docID | The ID of the document. |
| cbl::Error | On a database error. Note a non-existent document is not an error — that returns a falsy Document rather than throwing. |
|
inline |
The collection's name.
|
inlineexplicit |
Returns true if this references an object (same as valid).
|
inline |
Returns true if the two sides reference different objects.
|
inlinenoexcept |
Move assignment: replaces this reference with other's, leaving other a null reference.
|
inlinenoexcept |
Copy assignment: replaces this reference with a reference to other's object.
|
inline |
Releases the underlying object and resets this to a null reference.
|
inline |
Returns true if both sides reference the same object, or are both null references.
|
inline |
Purges a document from the 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.
| doc | The document to purge. |
|
inline |
Purges a document by its ID from the collection.
| docID | The document ID to purge. |
|
inline |
Returns a pointer to the underlying C object (CBLCollection), or NULL if this is a null reference.
|
inline |
Saves a (mutable) document to the collection.
doc was loaded, it will be overwritten by this one. This can lead to data loss! To avoid this, call Collection::saveDocument(MutableDocument &doc, CBLConcurrencyControl concurrency) Collection::saveDocument(MutableDocument &doc, ConflictHandler handler) instead. | doc | The mutable document to save. |
|
inline |
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 Collection::saveDocument(MutableDocument &doc, ConflictHandler handler) instead.
| doc | The mutable document to save. |
| concurrency | Conflict-handling strategy (fail or overwrite). |
|
inline |
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.
| doc | The mutable document to save. |
| handler | The callback to be invoked if there is a conflict. |
|
inline |
The scope's name.
|
inline |
Sets or clears the expiration time of a document in 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. |
|
inline |
Returns true if this references an object, or false if it is a null reference.
|
friend |
|
friend |
|
friend |