22#include "cbl/CBLDocument.h"
23#include "fleece/Mutable.hh"
82 if (!d && error->
code != 0)
83 internal::check(
false, *error);
94 internal::check(permittedError, error);
128 template <
typename V>
133 template <
typename K,
typename V>
138 fleece::keyref<fleece::MutableDict,fleece::slice>
operator[] (std::string_view key)
165 internal::check(d !=
nullptr || error->
code == 0, *error);
216 &conflictHandler, &error), error);
#define CBL_REFCOUNTED_BOILERPLATE(CLASS, SUPER, C_TYPE)
Definition Base.hh:160
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
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
void saveDocument(MutableDocument &doc)
Saves a (mutable) document to the collection.
Definition Document.hh:197
void purgeDocument(Document &doc)
Purges a document from the collection.
Definition Document.hh:229
Document getDocument(std::string_view docID) const
Reads a document from the collection in an immutable form.
Definition Document.hh:187
void deleteDocument(Document &doc)
Deletes a document from the collection.
Definition Document.hh:219
friend class Document
Definition Collection.hh:370
std::string id() const
A document's ID.
Definition Document.hh:38
Collection collection() const
A document's collection or NULL for the new document that hasn't been saved.
Definition Document.hh:54
const CBLDocument *_Nullable ref() const
Returns a pointer to the underlying C object (const CBLDocument), or NULL if this is a null reference...
Definition Document.hh:99
static bool checkSave(bool saveResult, CBLError &error)
Definition Document.hh:89
fleece::Value operator[](std::string_view key) const
A subscript operator to access a document's property value by key.
Definition Document.hh:65
Document(CBLRefCounted *r)
Definition Document.hh:79
uint64_t sequence() const
A document's current sequence in the local database.
Definition Document.hh:51
friend class Collection
Definition Document.hh:75
friend class Database
Definition Document.hh:76
std::string revisionID() const
A document's revision ID, which is a short opaque string that's guaranteed to be unique to every chan...
Definition Document.hh:42
friend class Replicator
Definition Document.hh:77
static Document adopt(const CBLDocument *_Nullable d, CBLError *error)
Definition Document.hh:81
uint64_t timestamp() const
The hybrid logical timestamp in nanoseconds since epoch that the revision was created.
Definition Document.hh:45
fleece::Dict properties() const
A document's properties as an immutable dictionary.
Definition Document.hh:59
MutableDocument mutableCopy() const
Creates a new mutable Document instance that refers to the same document as the original.
Definition Document.hh:179
alloc_slice propertiesAsJSON() const
A document's properties as JSON.
Definition Document.hh:62
A mutable document, whose properties can be modified and saved to a collection.
Definition Document.hh:104
static MutableDocument adopt(CBLDocument *_Nullable d, CBLError *error)
Definition Document.hh:164
void setProperties(fleece::MutableDict properties)
Sets a mutable document's properties.
Definition Document.hh:144
void set(std::string_view key, const V &val)
Sets a property key and value.
Definition Document.hh:129
friend class Collection
Definition Document.hh:171
friend class Database
Definition Document.hh:172
void setPropertiesAsJSON(std::string_view json)
Sets a mutable document's properties from a JSON Dictionary string.
Definition Document.hh:158
friend class Document
Definition Document.hh:173
fleece::keyref< fleece::MutableDict, fleece::slice > operator[](std::string_view key)
A subscript operator to access a document's property value by key for either getting or setting the v...
Definition Document.hh:138
MutableDocument(std::nullptr_t)
Creates a new, empty document in memory, with a randomly-generated unique ID.
Definition Document.hh:108
MutableDocument(std::string_view docID)
Creates a new, empty document in memory, with the given ID.
Definition Document.hh:116
CBLDocument *_Nullable ref() const
Returns a pointer to the underlying C object (CBLDocument), or NULL if this is a null reference.
Definition Document.hh:174
fleece::MutableDict properties()
Returns a mutable document's properties as a mutable dictionary.
Definition Document.hh:124
void setProperties(fleece::Dict properties)
Sets a mutable document's properties.
Definition Document.hh:151
void set(const K &key, const V &val)
Sets a property key and value.
Definition Document.hh:134
bool CBLCollection_DeleteDocumentWithConcurrencyControl(CBLCollection *collection, const CBLDocument *document, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
bool CBLCollection_PurgeDocument(CBLCollection *collection, const CBLDocument *document, CBLError *_cbl_nullable outError)
_cbl_warn_unused const CBLDocument *_cbl_nullable CBLCollection_GetDocument(const CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError)
_cbl_warn_unused CBLDocument *_cbl_nullable CBLCollection_GetMutableDocument(CBLCollection *collection, FLString docID, CBLError *_cbl_nullable outError)
bool CBLCollection_SaveDocumentWithConflictHandler(CBLCollection *collection, CBLDocument *doc, CBLConflictHandler conflictHandler, void *_cbl_nullable context, CBLError *_cbl_nullable outError)
bool CBLCollection_SaveDocumentWithConcurrencyControl(CBLCollection *collection, CBLDocument *doc, CBLConcurrencyControl concurrency, CBLError *_cbl_nullable outError)
_cbl_warn_unused FLSliceResult CBLDocument_CreateJSON(const CBLDocument *)
_cbl_warn_unused CBLDocument * CBLDocument_MutableCopy(const CBLDocument *original)
FLString CBLDocument_ID(const CBLDocument *)
bool CBLDocument_SetJSON(CBLDocument *, FLSlice json, CBLError *_cbl_nullable outError)
CBLCollection *_cbl_nullable CBLDocument_Collection(const CBLDocument *)
uint64_t CBLDocument_Timestamp(const CBLDocument *)
bool(* CBLConflictHandler)(void *_cbl_nullable context, CBLDocument *_cbl_nullable documentBeingSaved, const CBLDocument *_cbl_nullable conflictingDocument)
struct CBLDocument CBLDocument
uint64_t CBLDocument_Sequence(const CBLDocument *)
FLString CBLDocument_RevisionID(const CBLDocument *)
FLMutableDict CBLDocument_MutableProperties(CBLDocument *)
FLDict CBLDocument_Properties(const CBLDocument *)
_cbl_warn_unused CBLDocument * CBLDocument_CreateWithID(FLString docID)
void CBLDocument_SetProperties(CBLDocument *, FLMutableDict properties)
kCBLConcurrencyControlLastWriteWins
struct CBLRefCounted CBLRefCounted
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
fleece::alloc_slice alloc_slice
Convenience alias for fleece::alloc_slice, an owning byte buffer.
Definition Base.hh:51