22#include "cbl/CBLCollection.h"
23#include "cbl/CBLScope.h"
24#include "fleece/Mutable.hh"
225 internal::check(
false, error);
238 internal::check(exp >= 0, error);
300#ifdef COUCHBASE_ENTERPRISE
320 internal::check(error.
code == 0, error);
321 fleece::RetainedArray names(flNames);
363 internal::check(d !=
nullptr || error->
code == 0, *error);
389 std::vector<slice>&
docIDs() {
return _docIDs;}
394 ,_docIDs(std::move(
docIDs))
400 std::vector<slice> _docIDs;
448 auto ch = std::make_unique<CollectionChange>(col, docIDs);
455 auto ch = std::make_unique<DocumentChange>(col, docID);
461template<>
struct std::hash<
cbl::Collection> {
465 std::size_t hash = fleece::slice(name).hash() ^ fleece::slice(
CBLScope_Name(scope)).hash();
#define CBL_REFCOUNTED_BOILERPLATE(CLASS, SUPER, C_TYPE)
Definition Base.hh:160
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
Collection change info notified to the collection change listener's callback.
Definition Collection.hh:383
Collection & collection()
The collection.
Definition Collection.hh:386
CollectionChange(Collection collection, std::vector< slice > docIDs)
Internal API.
Definition Collection.hh:392
std::vector< slice > & docIDs()
The IDs of the changed documents.
Definition Collection.hh:389
A Collection is a container for documents within a database.
Definition Collection.hh:131
MutableDocument getMutableDocument(std::string_view docID) const
Reads a document from the collection in mutable form that can be updated and saved.
Definition Document.hh:192
CBLCollection *_Nullable ref() const
Returns a pointer to the underlying C object (CBLCollection), or NULL if this is a null reference.
Definition Collection.hh:373
CollectionChangeListener addChangeListener(CollectionChangeListener::Callback callback)
Registers a collection change listener callback.
Definition Collection.hh:338
Collection() noexcept
Constructs a null reference (one that points to no object).
Definition Collection.hh:373
std::string name() const
The collection's name.
Definition Collection.hh:136
CollectionDocumentChangeListener addDocumentChangeListener(std::string_view docID, CollectionDocumentChangeListener::Callback callback)
Registers a document change listener callback.
Definition Collection.hh:352
void setDocumentExpiration(std::string_view docID, time_t expiration)
Sets or clears the expiration time of a document in the collection.
Definition Collection.hh:246
fleece::RetainedArray getIndexNames()
Returns the names of the indexes in the collection, as a Fleece array of strings.
Definition Collection.hh:317
void saveDocument(MutableDocument &doc)
Saves a (mutable) document to the collection.
Definition Document.hh:197
void deleteIndex(std::string_view name)
Deletes an index given its name from the collection.
Definition Collection.hh:311
void purgeDocument(Document &doc)
Purges a document from the collection.
Definition Document.hh:229
static Collection adopt(const CBLCollection *_Nullable d, CBLError *error)
Definition Collection.hh:362
QueryIndex getIndex(std::string_view name)
Get an index by name.
Definition QueryIndex.hh:134
void createArrayIndex(std::string_view name, ArrayIndexConfiguration config)
Creates an array index for use with UNNEST queries in the collection.
Definition Collection.hh:291
cbl::ListenerToken< CollectionChange * > CollectionChangeListener
Collection Change Listener Token.
Definition Collection.hh:332
bool purgeDocument(std::string_view docID)
Purges a document by its ID from the collection.
Definition Collection.hh:221
std::string fullName() const
The collection's fully qualified name in the '<scope-name>.
Definition Collection.hh:139
Document getDocument(std::string_view docID) const
Reads a document from the collection in an immutable form.
Definition Document.hh:187
Database database() const
The collection's database.
Definition Collection.hh:150
friend class Database
Definition Collection.hh:369
friend class QueryIndex
Definition Collection.hh:371
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.
Definition Collection.hh:235
void deleteDocument(Document &doc)
Deletes a document from the collection.
Definition Document.hh:219
friend class Document
Definition Collection.hh:370
void createVectorIndex(std::string_view name, VectorIndexConfiguration config)
Creates a vector index in the collection.
Definition VectorIndex.hh:189
cbl::ListenerToken< DocumentChange * > CollectionDocumentChangeListener
Document Change Listener Token.
Definition Collection.hh:345
uint64_t count() const
The number of documents in the collection.
Definition Collection.hh:153
void createFullTextIndex(std::string_view name, FullTextIndexConfiguration config)
Creates a full-text index in the collection.
Definition Collection.hh:274
void createValueIndex(std::string_view name, ValueIndexConfiguration config)
Creates a value index in the collection.
Definition Collection.hh:259
std::string scopeName() const
The scope's name.
Definition Collection.hh:142
CBLDatabase *_Nullable ref() const
Returns a pointer to the underlying C object (CBLDatabase), or NULL if this is a null reference.
Definition Database.hh:411
Collection getDefaultCollection() const
Returns the default collection.
Definition Collection.hh:438
Collection getCollection(std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt) const
Returns the existing collection with the given name and scope.
Definition Collection.hh:426
Collection createCollection(std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt)
Create a new collection.
Definition Collection.hh:432
friend class Collection
Definition Database.hh:408
Document change info notified to the document change listener's callback.
Definition Collection.hh:404
slice & docID()
The ID of the changed document.
Definition Collection.hh:410
DocumentChange(Collection collection, std::string_view docID)
Internal API.
Definition Collection.hh:413
Collection & collection()
The collection.
Definition Collection.hh:407
An immutable, in-memory copy of a document read from a collection.
Definition Document.hh:33
A token representing a registered listener; instances are returned from the various methods that regi...
Definition Base.hh:177
static void call(void *_Nullable context, Args... args)
Definition Base.hh:228
std::function< void(Args...)> Callback
Definition Base.hh:180
A mutable document, whose properties can be modified and saved to a collection.
Definition Document.hh:104
Represents an existing index in a collection.
Definition QueryIndex.hh:33
Configuration for creating a vector index, which enables searching documents by vector similarity.
Definition VectorIndex.hh:82
void FLArray_Release(FLArray FL_NULLABLE v)
CBLCollection *_cbl_nullable CBLDatabase_DefaultCollection(const CBLDatabase *db, CBLError *_cbl_nullable outError)
_cbl_warn_unused FLMutableArray _cbl_nullable CBLCollection_GetIndexNames(CBLCollection *collection, CBLError *_cbl_nullable outError)
bool CBLCollection_SetDocumentExpiration(CBLCollection *collection, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError)
uint64_t CBLCollection_Count(const CBLCollection *collection)
bool CBLCollection_DeleteIndex(CBLCollection *collection, FLString name, CBLError *_cbl_nullable outError)
bool CBLCollection_CreateValueIndex(CBLCollection *collection, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError)
CBLDatabase * CBLCollection_Database(const CBLCollection *collection)
CBLCollection *_cbl_nullable CBLDatabase_Collection(const CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
bool CBLCollection_CreateFullTextIndex(CBLCollection *collection, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError)
bool CBLCollection_PurgeDocumentByID(CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError)
_cbl_warn_unused CBLListenerToken * CBLCollection_AddChangeListener(const CBLCollection *collection, CBLCollectionChangeListener listener, void *_cbl_nullable context)
CBLCollection *_cbl_nullable CBLDatabase_CreateCollection(CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
_cbl_warn_unused CBLListenerToken * CBLCollection_AddDocumentChangeListener(const CBLCollection *collection, FLString docID, CBLCollectionDocumentChangeListener listener, void *_cbl_nullable context)
bool CBLCollection_CreateArrayIndex(CBLCollection *collection, FLString name, CBLArrayIndexConfiguration config, CBLError *_cbl_nullable outError)
FLString CBLCollection_Name(const CBLCollection *collection)
CBLScope * CBLCollection_Scope(const CBLCollection *collection)
struct CBLCollection CBLCollection
CBLTimestamp CBLCollection_GetDocumentExpiration(CBLCollection *collection, FLSlice docID, CBLError *_cbl_nullable outError)
FLString CBLCollection_FullName(const CBLCollection *collection)
struct CBLRefCounted CBLRefCounted
FLString CBLScope_Name(const CBLScope *scope)
CBLINLINE void CBLScope_Release(const CBLScope *_cbl_nullable t)
CBL_PUBLIC const FLString kCBLDefaultScopeName
struct _FLArray * FLMutableArray
fleece::slice slice
Convenience alias for fleece::slice, a non-owning view of a byte range.
Definition Base.hh:49
std::function< bool(MutableDocument documentBeingSaved, Document conflictingDocument)> CollectionConflictHandler
Conflict handler used when saving a document.
Definition Collection.hh:41
CBLQueryLanguage QueryLanguage
Definition Base.hh:53
const CBLCollection * collection
const CBLCollection * collection
Array Index Configuration for indexing property values within arrays in documents,...
Definition Collection.hh:96
std::string path
Path to the array, which can be nested to be indexed (Required).
Definition Collection.hh:104
QueryLanguage expressionLanguage
The language used in the expressions (Required).
Definition Collection.hh:98
std::string expressions
Optional expressions representing the values within the array to be indexed.
Definition Collection.hh:111
Configuration for creating a full-text index, which enables full-text search in queries.
Definition Collection.hh:61
std::string where
A predicate expression defining conditions for indexing documents.
Definition Collection.hh:91
std::string expressions
The expressions describing each coloumn of the index (Required).
Definition Collection.hh:68
QueryLanguage expressionLanguage
The language used in the expressions (Required).
Definition Collection.hh:63
bool ignoreAccents
Should diacritical marks (accents) be ignored?
Definition Collection.hh:73
std::string language
The dominant language.
Definition Collection.hh:86
Configuration for creating a value index, which indexes the values of one or more document properties...
Definition Collection.hh:45
std::string where
A predicate expression defining conditions for indexing documents.
Definition Collection.hh:57
QueryLanguage expressionLanguage
The language used in the expressions (Required).
Definition Collection.hh:47
std::string expressions
The expressions describing each column of the index (Required).
Definition Collection.hh:52