Couchbase Lite C
Couchbase Lite C API
CBLDocument.h
Go to the documentation of this file.
1//
2// CBLDocument.h
3//
4// Copyright (c) 2018 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 "fleece/Fleece.h"
22
24
31
41};
42
43
57typedef bool (*CBLConflictHandler)(void* _cbl_nullable context,
58 CBLDocument* _cbl_nullable documentBeingSaved,
59 const CBLDocument* _cbl_nullable conflictingDocument);
60
61
73 FLString docID,
74 CBLError* _cbl_nullable outError) CBLAPI;
75
77
88 CBLDocument* doc,
89 CBLError* _cbl_nullable outError) CBLAPI;
90
102 CBLDocument* doc,
103 CBLConcurrencyControl concurrency,
104 CBLError* _cbl_nullable outError) CBLAPI;
105
115 CBLDocument* doc,
116 CBLConflictHandler conflictHandler,
117 void* _cbl_nullable context,
118 CBLError* _cbl_nullable outError) CBLAPI;
119
127 const CBLDocument* document,
128 CBLError* _cbl_nullable outError) CBLAPI;
129
138 const CBLDocument* document,
139 CBLConcurrencyControl concurrency,
140 CBLError* _cbl_nullable outError) CBLAPI;
141
153 const CBLDocument* document,
154 CBLError* _cbl_nullable outError) CBLAPI;
155
165 FLString docID,
166 CBLError* _cbl_nullable outError) CBLAPI;
167
189 FLString docID,
190 CBLError* _cbl_nullable outError) CBLAPI;
191
197
207
215
228
233
239
250
262
268 FLMutableDict properties) CBLAPI;
269
274
277 FLSlice json,
278 CBLError* _cbl_nullable outError) CBLAPI;
279
290 FLSlice docID,
291 CBLError* _cbl_nullable outError) CBLAPI;
292
301 FLSlice docID,
302 CBLTimestamp expiration,
303 CBLError* _cbl_nullable outError) CBLAPI;
304
324typedef void (*CBLDocumentChangeListener)(void *context,
325 const CBLDatabase* db,
326 FLString docID);
327
338 FLString docID,
340 void* _cbl_nullable context) CBLAPI;
341
#define CBLAPI
Definition: CBL_Compat.h:98
#define _cbl_nullable
Definition: CBL_Compat.h:86
#define CBL_CAPI_BEGIN
Definition: CBL_Compat.h:99
#define CBL_CAPI_END
Definition: CBL_Compat.h:100
#define CBL_PUBLIC
Definition: CBL_Compat.h:117
#define CBL_ENUM(_type, _name)
Definition: CBL_Compat.h:56
#define _cbl_warn_unused
Definition: CBL_Compat.h:41
struct CBLDatabase CBLDatabase
A connection to an open database.
Definition: CBLBase.h:182
_cbl_warn_unused FLSliceResult CBLDocument_CreateJSON(const CBLDocument *)
Returns a document's properties as JSON.
bool CBLDatabase_DeleteDocumentWithConcurrencyControl(CBLDatabase *db, const CBLDocument *document, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
Deletes a document from the database.
_cbl_warn_unused CBLDocument * CBLDocument_MutableCopy(const CBLDocument *original)
Creates a new mutable CBLDocument instance that refers to the same document as the original.
_cbl_warn_unused const CBLDocument *_cbl_nullable CBLDatabase_GetDocument(const CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError)
Reads a document from the database, creating a new (immutable) CBLDocument object.
_cbl_warn_unused CBLDocument * CBLDocument_Create(void)
Creates a new, empty document in memory, with a randomly-generated unique ID.
CBLConcurrencyControl
Conflict-handling options when saving or deleting a document.
Definition: CBLDocument.h:36
CBLTimestamp CBLDatabase_GetDocumentExpiration(CBLDatabase *db, FLSlice docID, CBLError *_cbl_nullable outError)
Returns the time, if any, at which a given document will expire and be purged.
FLString CBLDocument_ID(const CBLDocument *)
Returns a document's ID.
bool CBLDocument_SetJSON(CBLDocument *, FLSlice json, CBLError *_cbl_nullable outError)
Sets a mutable document's properties from a JSON string.
CBL_PUBLIC const FLSlice kCBLTypeProperty
"@type"
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:57
bool CBLDatabase_PurgeDocumentByID(CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError)
Purges a document, given only its ID.
struct CBLDocument CBLDocument
An in-memory copy of a document.
Definition: CBLBase.h:191
bool CBLDatabase_SaveDocumentWithConflictHandler(CBLDatabase *db, CBLDocument *doc, CBLConflictHandler conflictHandler, void *_cbl_nullable context, CBLError *_cbl_nullable outError)
Saves a (mutable) document to the database, allowing for custom conflict handling in the event that t...
void(* CBLDocumentChangeListener)(void *context, const CBLDatabase *db, FLString docID)
A document change listener callback, invoked after a specific document is changed on disk.
Definition: CBLDocument.h:324
uint64_t CBLDocument_Sequence(const CBLDocument *)
Returns a document's current sequence in the local database.
FLString CBLDocument_RevisionID(const CBLDocument *)
Returns a document's revision ID, which is a short opaque string that's guaranteed to be unique to ev...
FLMutableDict CBLDocument_MutableProperties(CBLDocument *)
Returns a mutable document's properties as a mutable dictionary.
_cbl_warn_unused CBLDocument *_cbl_nullable CBLDatabase_GetMutableDocument(CBLDatabase *database, FLString docID, CBLError *_cbl_nullable outError)
Reads a document from the database, in mutable form that can be updated and saved.
bool CBLDatabase_SetDocumentExpiration(CBLDatabase *db, FLSlice docID, CBLTimestamp expiration, CBLError *_cbl_nullable outError)
Sets or clears the expiration time of a document.
_cbl_warn_unused CBLListenerToken * CBLDatabase_AddDocumentChangeListener(const CBLDatabase *db, FLString docID, CBLDocumentChangeListener listener, void *_cbl_nullable context)
Registers a document change listener callback.
bool CBLDatabase_DeleteDocument(CBLDatabase *db, const CBLDocument *document, CBLError *_cbl_nullable outError)
Deletes a document from the database.
FLDict CBLDocument_Properties(const CBLDocument *)
Returns a document's properties as a dictionary.
bool CBLDatabase_SaveDocumentWithConcurrencyControl(CBLDatabase *db, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
Saves a (mutable) document to the database.
_cbl_warn_unused CBLDocument * CBLDocument_CreateWithID(FLString docID)
Creates a new, empty document in memory, with the given ID.
void CBLDocument_SetProperties(CBLDocument *, FLMutableDict properties)
Sets a mutable document's properties.
bool CBLDatabase_SaveDocument(CBLDatabase *db, CBLDocument *doc, CBLError *_cbl_nullable outError)
Saves a (mutable) document to the database.
bool CBLDatabase_PurgeDocument(CBLDatabase *db, const CBLDocument *document, CBLError *_cbl_nullable outError)
Purges a document.
@ kCBLConcurrencyControlLastWriteWins
The current save/delete will overwrite a conflicting revision if there is a conflict.
Definition: CBLDocument.h:38
@ kCBLConcurrencyControlFailOnConflict
The current save/delete will fail if there is a conflict.
Definition: CBLDocument.h:40
struct CBLListenerToken CBLListenerToken
An opaque 'cookie' representing a registered listener callback.
Definition: CBLBase.h:259
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 _FLDict * FLMutableDict
A reference to a mutable dictionary.
Definition: Fleece.h:54
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition: Fleece.h:51
A struct holding information about an error.
Definition: CBLBase.h:104
A simple reference to a block of memory.
Definition: FLSlice.h:46
A heap-allocated block of memory returned from an API call.
Definition: FLSlice.h:64