LiteCore
Couchbase Lite cross-platform core implementation
Loading...
Searching...
No Matches
c4Document.h File Reference
#include "c4DocumentTypes.h"
#include "c4DocumentStruct.h"

Go to the source code of this file.

Functions

Revisions
CBL_CORE_API bool c4doc_isRevRejected (C4Document *doc)
 
NODISCARD CBL_CORE_API bool c4doc_selectRevision (C4Document *doc, C4String revID, bool withBody, C4Error *outError)
 Selects a specific revision of a document (or no revision, if revID is NULL.)
 
CBL_CORE_API bool c4doc_selectCurrentRevision (C4Document *doc)
 Selects the current revision of a document.
 
NODISCARD CBL_CORE_API bool c4doc_loadRevisionBody (C4Document *doc, C4Error *outError)
 Populates the body field of a doc's selected revision, if it was initially loaded without its body.
 
CBL_CORE_API bool c4doc_hasRevisionBody (C4Document *doc)
 Returns true if the body of the selected revision is available, i.e.
 
CBL_CORE_API C4Slice c4doc_getRevisionBody (C4Document *doc)
 Returns the body (encoded Fleece data) of the selected revision, if available.
 
CBL_CORE_API C4SliceResult c4doc_getRevisionHistory (C4Document *doc, unsigned maxRevs, const C4String backToRevs[], unsigned backToRevsCount)
 Returns a string encoding the selected revision's history, as comma-separate revision/version IDs in reverse chronological order.
 
CBL_CORE_API C4SliceResult c4doc_getSelectedRevIDGlobalForm (C4Document *doc)
 Returns the selected revision's ID in a form that will make sense to another peer/server.
 
NODISCARD CBL_CORE_API bool c4doc_selectParentRevision (C4Document *doc)
 Selects the parent of the selected revision, if it's known, else returns false.
 
NODISCARD CBL_CORE_API bool c4doc_selectNextRevision (C4Document *doc)
 Selects the next revision in priority order.
 
NODISCARD CBL_CORE_API bool c4doc_selectNextLeafRevision (C4Document *doc, bool includeDeleted, bool withBody, C4Error *outError)
 Selects the next leaf revision; like selectNextRevision but skips over non-leaves.
 
NODISCARD CBL_CORE_API bool c4doc_selectCommonAncestorRevision (C4Document *doc, C4String rev1ID, C4String rev2ID)
 Selects the common ancestor of two revisions.
 
CBL_CORE_API C4RemoteID c4db_getRemoteDBID (C4Database *db, C4String remoteAddress, bool canCreate, C4Error *outError)
 Looks up or creates a numeric ID identifying a remote database, for use with c4doc_getRemoteAncestor() and c4doc_setRemoteAncestor().
 
CBL_CORE_API C4SliceResult c4db_getRemoteDBAddress (C4Database *db, C4RemoteID remoteID)
 Given a remote database ID, returns its replication URL / unique identifier.
 
CBL_CORE_API C4SliceResult c4doc_getRemoteAncestor (C4Document *doc, C4RemoteID remoteDatabase)
 Returns the revision ID that has been marked as current for the given remote database.
 
NODISCARD CBL_CORE_API bool c4doc_setRemoteAncestor (C4Document *doc, C4RemoteID remoteDatabase, C4String revID, C4Error *error)
 Marks a revision as current for the given remote database.
 
CBL_CORE_API unsigned c4rev_getGeneration (C4String revID)
 Given a tree-based revision ID, returns its generation number (the decimal number before the hyphen), or zero if it's unparseable.
 
CBL_CORE_API uint64_t c4rev_getTimestamp (C4String revID)
 Given a revision ID that's a Version (of the form time@peer), returns its timestamp.
 
CBL_CORE_API bool c4rev_equal (C4Slice rev1, C4Slice rev2)
 Returns true if two revision IDs are equivalent.
 
NODISCARD CBL_CORE_API int32_t c4doc_purgeRevision (C4Document *doc, C4String revID, C4Error *outError)
 Removes a branch from a document's history.
 
NODISCARD CBL_CORE_API bool c4doc_resolveConflict (C4Document *doc, C4String winningRevID, C4String losingRevID, C4Slice mergedBody, C4RevisionFlags mergedFlags, C4Error *error)
 Resolves a conflict between two leaf revisions, by deleting one of them and optionally adding a new merged revision as a child of the other.
 
Purging and Expiration
CBL_CORE_API bool c4db_purgeDoc (C4Database *database, C4String docID, C4Error *outError)
 Removes all trace of a document and its revisions from the database.
 
CBL_CORE_API bool c4doc_setExpiration (C4Database *db, C4String docID, C4Timestamp timestamp, C4Error *outError)
 Sets an expiration date on a document.
 
CBL_CORE_API C4Timestamp c4doc_getExpiration (C4Database *db, C4String docID, C4Error *outError)
 Returns the expiration time of a document, if one has been set, else 0.
 
Creating and Updating Documents
CBL_CORE_API C4Documentc4doc_put (C4Database *database, const C4DocPutRequest *request, size_t *outCommonAncestorIndex, C4Error *outError)
 A high-level Put operation, to insert a new or downloaded revision.
 
CBL_CORE_API C4Documentc4doc_create (C4Database *db, C4String docID, C4Slice body, C4RevisionFlags revisionFlags, C4Error *error)
 Convenience function to create a new document.
 
CBL_CORE_API C4Documentc4doc_update (C4Document *doc, C4Slice revisionBody, C4RevisionFlags revisionFlags, C4Error *error)
 Adds a revision to a document already in memory as a C4Document.
 

Lifecycle

#define kC4GeneratedIDLength   23
 
CBL_CORE_API char * c4doc_generateID (char *buffer, size_t bufferSize)
 Generates a random 23-byte C string suitable for use as a unique new document ID.
 
NODISCARD CBL_CORE_API C4Documentc4db_getDoc (C4Database *database, C4String docID, bool mustExist, C4DocContentLevel content, C4Error *outError)
 Gets a document from the database given its ID.
 
NODISCARD CBL_CORE_API C4Documentc4doc_get (C4Database *database, C4String docID, bool mustExist, C4Error *outError)
 Gets a document from the database given its ID (semi-deprecated).
 
NODISCARD CBL_CORE_API C4Documentc4doc_getBySequence (C4Database *database, C4SequenceNumber, C4Error *outError)
 Gets a document from the database given its sequence number.
 
NODISCARD CBL_CORE_API bool c4doc_save (C4Document *doc, uint32_t maxRevTreeDepth, C4Error *outError)
 Saves changes to a C4Document.