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
154 CBLError* _cbl_nullable outError) CBLAPI;
155
164 CBLError* _cbl_nullable outError) CBLAPI;
165
178
183
187uint64_t CBLCollection_Count(const CBLCollection* collection) CBLAPI;
188
205 FLString docID,
206 CBLError* _cbl_nullable outError) CBLAPI;
207
218 CBLDocument* doc,
219 CBLError* _cbl_nullable outError) CBLAPI;
220
232 CBLDocument* doc,
233 CBLConcurrencyControl concurrency,
234 CBLError* _cbl_nullable outError) CBLAPI;
235
245 CBLDocument* doc,
246 CBLConflictHandler conflictHandler,
247 void* _cbl_nullable context,
248 CBLError* _cbl_nullable outError) CBLAPI;
249
257 const CBLDocument* document,
258 CBLError* _cbl_nullable outError) CBLAPI;
259
268 const CBLDocument* document,
269 CBLConcurrencyControl concurrency,
270 CBLError* _cbl_nullable outError) CBLAPI;
271
283 const CBLDocument* document,
284 CBLError* _cbl_nullable outError) CBLAPI;
285
294 FLString docID,
295 CBLError* _cbl_nullable outError) CBLAPI;
296
307 FLSlice docID,
308 CBLError* _cbl_nullable outError) CBLAPI;
309
318 FLSlice docID,
319 CBLTimestamp expiration,
320 CBLError* _cbl_nullable outError) CBLAPI;
340 FLString docID,
341 CBLError* _cbl_nullable outError) CBLAPI;
357 FLString name,
359 CBLError* _cbl_nullable outError) CBLAPI;
360
370 FLString name,
372 CBLError* _cbl_nullable outError) CBLAPI;
373
380 FLString name,
381 CBLError* _cbl_nullable outError) CBLAPI;
382
390 CBLError* _cbl_nullable outError) CBLAPI;
391
402typedef struct {
404 unsigned numDocs;
407
414typedef void (*CBLCollectionChangeListener)(void* _cbl_nullable context,
415 const CBLCollectionChange* change);
416
425 void* _cbl_nullable context) CBLAPI;
426
438typedef struct {
442
449typedef void (*CBLCollectionDocumentChangeListener)(void *context, const CBLDocumentChange* change);
450
459 FLString docID,
461 void* _cbl_nullable context) CBLAPI;
462 // end of outer \defgroup
465
#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:414
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:449
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:402
FLString * docIDs
The IDs of the documents that changed.
Definition: CBLCollection.h:405
unsigned numDocs
The number of documents that changed (size of the docIDs array).
Definition: CBLCollection.h:404
const CBLCollection * collection
The collection that changed.
Definition: CBLCollection.h:403
Definition: CBLCollection.h:438
const CBLCollection * collection
The collection that changed.
Definition: CBLCollection.h:439
FLString docID
The document's ID.
Definition: CBLCollection.h:440
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