Couchbase Lite C
Couchbase Lite C API
CBLCollection.h
Go to the documentation of this file.
1//
2// CBLCollection.h
3//
4// Copyright (c) 2022 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20#include "CBLBase.h"
21#include "CBLDocument.h"
22#include "CBLQuery.h"
23
25
66
73
82 CBLError* _cbl_nullable outError) CBLAPI;
83
91 FLString scopeName,
92 CBLError* _cbl_nullable outError) CBLAPI;
93
103 FLString scopeName,
104 CBLError* _cbl_nullable outError) CBLAPI;
105
114 FLString collectionName,
115 FLString scopeName,
116 CBLError* _cbl_nullable outError) CBLAPI;
117
132 FLString collectionName,
133 FLString scopeName,
134 CBLError* _cbl_nullable outError) CBLAPI;
135
144 FLString collectionName,
145 FLString scopeName,
146 CBLError* _cbl_nullable outError) CBLAPI;
147
155 CBLError* _cbl_nullable outError) CBLAPI;
156
165 CBLError* _cbl_nullable outError) CBLAPI;
166
179
184
188uint64_t CBLCollection_Count(const CBLCollection* collection) CBLAPI;
189
206 FLString docID,
207 CBLError* _cbl_nullable outError) CBLAPI;
208
219 CBLDocument* doc,
220 CBLError* _cbl_nullable outError) CBLAPI;
221
233 CBLDocument* doc,
234 CBLConcurrencyControl concurrency,
235 CBLError* _cbl_nullable outError) CBLAPI;
236
246 CBLDocument* doc,
247 CBLConflictHandler conflictHandler,
248 void* _cbl_nullable context,
249 CBLError* _cbl_nullable outError) CBLAPI;
250
258 const CBLDocument* document,
259 CBLError* _cbl_nullable outError) CBLAPI;
260
269 const CBLDocument* document,
270 CBLConcurrencyControl concurrency,
271 CBLError* _cbl_nullable outError) CBLAPI;
272
284 const CBLDocument* document,
285 CBLError* _cbl_nullable outError) CBLAPI;
286
295 FLString docID,
296 CBLError* _cbl_nullable outError) CBLAPI;
297
308 FLSlice docID,
309 CBLError* _cbl_nullable outError) CBLAPI;
310
319 FLSlice docID,
320 CBLTimestamp expiration,
321 CBLError* _cbl_nullable outError) CBLAPI;
341 FLString docID,
342 CBLError* _cbl_nullable outError) CBLAPI;
358 FLString name,
360 CBLError* _cbl_nullable outError) CBLAPI;
361
371 FLString name,
373 CBLError* _cbl_nullable outError) CBLAPI;
374
381 FLString name,
382 CBLError* _cbl_nullable outError) CBLAPI;
383
391 CBLError* _cbl_nullable outError) CBLAPI;
392
403typedef struct {
405 unsigned numDocs;
408
415typedef void (*CBLCollectionChangeListener)(void* _cbl_nullable context,
416 const CBLCollectionChange* change);
417
426 void* _cbl_nullable context) CBLAPI;
427
439typedef struct {
443
450typedef void (*CBLCollectionDocumentChangeListener)(void *context, const CBLDocumentChange* change);
451
460 FLString docID,
462 void* _cbl_nullable context) CBLAPI;
463 // end of outer \defgroup
466
#define CBLAPI
Definition: CBL_Compat.h:104
#define _cbl_nullable
Definition: CBL_Compat.h:92
#define CBL_CAPI_BEGIN
Definition: CBL_Compat.h:105
#define CBL_CAPI_END
Definition: CBL_Compat.h:106
#define CBL_PUBLIC
Definition: CBL_Compat.h:123
#define _cbl_warn_unused
Definition: CBL_Compat.h:40
CBLCollection *_cbl_nullable CBLDatabase_DefaultCollection(const CBLDatabase *db, CBLError *_cbl_nullable outError)
Returns the default collection.
_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.
void(* CBLCollectionChangeListener)(void *_cbl_nullable context, const CBLCollectionChange *change)
A collection change listener callback, invoked after one or more documents are changed on disk.
Definition: CBLCollection.h:415
bool CBLCollection_SetDocumentExpiration(CBLCollection *collection, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError)
Sets or clears the expiration time of a document.
uint64_t CBLCollection_Count(const CBLCollection *collection)
Returns the number of documents in 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.
CBL_PUBLIC const FLString kCBLDefaultCollectionName
The default collection's name.
bool CBLCollection_DeleteIndex(CBLCollection *collection, FLString name, CBLError *_cbl_nullable outError)
Deletes an index in the collection by name.
bool CBLDatabase_DeleteCollection(CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
Delete an existing collection.
bool CBLCollection_CreateValueIndex(CBLCollection *collection, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError)
Creates a value index in the collection.
bool CBLCollection_SaveDocument(CBLCollection *collection, CBLDocument *doc, CBLError *_cbl_nullable outError)
Saves a (mutable) document to the collection.
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.
bool CBLCollection_CreateFullTextIndex(CBLCollection *collection, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError)
Creates a full-text index in the collection.
bool CBLCollection_DeleteDocument(CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError)
Deletes a document from the collection.
bool CBLCollection_PurgeDocumentByID(CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError)
Purges a document, given only its ID.
_cbl_warn_unused CBLListenerToken * CBLCollection_AddChangeListener(const CBLCollection *collection, CBLCollectionChangeListener listener, void *_cbl_nullable context)
Registers a collection change listener callback.
_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.
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_CreateCollection(CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
Create a new collection.
FLMutableArray _cbl_nullable CBLDatabase_CollectionNames(const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError)
Returns the names of all collections in the scope.
CBLScope * CBLDatabase_DefaultScope(const CBLDatabase *db, CBLError *_cbl_nullable outError)
Returns the default scope.
_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.
_cbl_warn_unused CBLListenerToken * CBLCollection_AddDocumentChangeListener(const CBLCollection *collection, FLString docID, CBLCollectionDocumentChangeListener listener, void *_cbl_nullable context)
Registers a document change listener callback.
FLString CBLCollection_Name(const CBLCollection *collection)
Returns the collection name.
FLMutableArray _cbl_nullable CBLDatabase_ScopeNames(const CBLDatabase *db, CBLError *_cbl_nullable outError)
Returns the names of all existing scopes in the database.
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...
CBLScope * CBLCollection_Scope(const CBLCollection *collection)
Returns the scope of the collection.
bool CBLCollection_SaveDocumentWithConcurrencyControl(CBLCollection *collection, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
Saves a (mutable) document to the collection.
struct CBLCollection CBLCollection
A collection, a document container.
Definition: CBLBase.h:194
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.
void(* CBLCollectionDocumentChangeListener)(void *context, const CBLDocumentChange *change)
A document change listener callback, invoked after a specific document is changed on disk.
Definition: CBLCollection.h:450
struct CBLDatabase CBLDatabase
A connection to an open database.
Definition: CBLBase.h:182
CBLConcurrencyControl
Conflict-handling options when saving or deleting a document.
Definition: CBLDocument.h:35
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.
Definition: CBLDocument.h:56
struct CBLDocument CBLDocument
An in-memory copy of a document.
Definition: CBLBase.h:203
struct CBLListenerToken CBLListenerToken
An opaque 'cookie' representing a registered listener callback.
Definition: CBLBase.h:271
int64_t CBLTimestamp
A date/time representation used for document expiration (and in date/time queries....
Definition: CBLBase.h:123
#define CBL_REFCOUNTED(TYPE, NAME)
Definition: CBLBase.h:170
struct CBLScope CBLScope
A collection's scope.
Definition: CBLBase.h:188
struct _FLArray * FLMutableArray
A reference to a mutable array.
Definition: FLBase.h:39
Definition: CBLCollection.h:403
FLString * docIDs
The IDs of the documents that changed.
Definition: CBLCollection.h:406
unsigned numDocs
The number of documents that changed (size of the docIDs array).
Definition: CBLCollection.h:405
const CBLCollection * collection
The collection that changed.
Definition: CBLCollection.h:404
Definition: CBLCollection.h:439
const CBLCollection * collection
The collection that changed.
Definition: CBLCollection.h:440
FLString docID
The document's ID.
Definition: CBLCollection.h:441
A struct holding information about an error.
Definition: CBLBase.h:104
Full-Text Index Configuration.
Definition: CBLQuery.h:286
Value Index Configuration.
Definition: CBLQuery.h:265
A simple reference to a block of memory.
Definition: FLSlice.h:45