Couchbase Lite
Objective-C API for iOS and Mac OS
CBLDocument Class Reference

Detailed Description

A CouchbaseLite document (as opposed to any specific revision of it.)

Inheritance diagram for CBLDocument:

Instance Methods

(BOOL) - deleteDocument:
 Deletes this document by adding a deletion revision. More...
 
(BOOL) - purgeDocument:
 Purges this document from the database; this is more than deletion, it forgets entirely about it. More...
 
(nullable CBLSavedRevision *) - revisionWithID:
 The revision with the specified ID. More...
 
(nullable CBLArrayOf(CBLSavedRevision *) - getRevisionHistory:
 Returns the document's history as an array of CBLRevisions. More...
 
(nullable CBLArrayOf(CBLSavedRevision *) - getConflictingRevisions:
 Returns all the current conflicting revisions of the document. More...
 
(nullable CBLArrayOf(CBLSavedRevision *) - getLeafRevisions:
 Returns all the leaf revisions in the document's revision tree, including deleted revisions (i.e. More...
 
(CBLUnsavedRevision *) - newRevision
 Creates an unsaved new revision whose parent is the currentRevision, or which will be the first revision if the document doesn't exist yet. More...
 
(nullable id) - propertyForKey:
 Shorthand for [self.properties objectForKey: key]. More...
 
(nullable id) - objectForKeyedSubscript:
 Same as -propertyForKey:. More...
 
(nullable CBLSavedRevision *) - putProperties:error:
 Saves a new revision. More...
 
(nullable CBLSavedRevision *) - update:error:
 Saves a new revision by letting the caller update the existing properties. More...
 
(BOOL) - putExistingRevisionWithProperties:attachments:revisionHistory:fromURL:error:
 Adds an existing revision copied from another database. More...
 
(instancetype) - NS_UNAVAILABLE
 

Properties

CBLDatabasedatabase
 The document's owning database. More...
 
NSString * documentID
 The document's ID. More...
 
NSString * abbreviatedID
 An abbreviated form of the the documentID that looks like "xxxx..xxxx". More...
 
BOOL isDeleted
 Is this document deleted? (That is, does its current revision have the '_deleted' property?) More...
 
BOOL isGone
 Has this document either been deleted or removed from available Sync Gateway channels? (That is, does its current revision have a '_deleted' or '_removed' property?) More...
 
NSDate * expirationDate
 A date/time after which this document will be automatically purged. More...
 
NSString * currentRevisionID
 The ID of the current revision (if known; else nil). More...
 
CBLSavedRevisioncurrentRevision
 The current/latest revision. More...
 
CBLJSONDict * properties
 The contents of the current revision of the document. More...
 
CBLJSONDict * userProperties
 The user-defined properties, without the ones reserved by CouchDB. More...
 
id< CBLDocumentModel > modelObject
 Optional reference to an application-defined model object representing this document. More...
 

Method Documentation

◆ deleteDocument:()

- (BOOL) deleteDocument: (NSError **)  outError

Deletes this document by adding a deletion revision.

This will be replicated to other databases.

◆ purgeDocument:()

- (BOOL) purgeDocument: (NSError **)  outError

Purges this document from the database; this is more than deletion, it forgets entirely about it.

The purge will NOT be replicated to other databases.

◆ revisionWithID:()

- (nullable CBLSavedRevision*) revisionWithID: (NSString *)  revisionID

The revision with the specified ID.

◆ getRevisionHistory:()

- (nullable CBLArrayOf(CBLSavedRevision*) getRevisionHistory: (NSError **)  outError

Returns the document's history as an array of CBLRevisions.

(See CBLRevision's method.)

◆ getConflictingRevisions:()

- (nullable CBLArrayOf(CBLSavedRevision*) getConflictingRevisions: (NSError **)  outError

Returns all the current conflicting revisions of the document.

If the document is not in conflict, only the single current revision will be returned.

◆ getLeafRevisions:()

- (nullable CBLArrayOf(CBLSavedRevision*) getLeafRevisions: (NSError **)  outError

Returns all the leaf revisions in the document's revision tree, including deleted revisions (i.e.

previously-resolved conflicts.)

◆ newRevision()

- (CBLUnsavedRevision*) newRevision

Creates an unsaved new revision whose parent is the currentRevision, or which will be the first revision if the document doesn't exist yet.

You can modify this revision's properties and attachments, then save it. No change is made to the database until/unless you save the new revision.

◆ propertyForKey:()

- (nullable id) propertyForKey: (NSString *)  key

Shorthand for [self.properties objectForKey: key].

◆ objectForKeyedSubscript:()

- (nullable id) objectForKeyedSubscript: (NSString *)  key

Same as -propertyForKey:.

Enables "[]" access in Xcode 4.4+

◆ putProperties:error:()

- (nullable CBLSavedRevision*) putProperties: (CBLJSONDict *)  properties
error: (NSError **)  outError 

Saves a new revision.

The properties dictionary must have a "_rev" property whose ID matches the current revision's (as it will if it's a modified copy of this document's .properties property.)

◆ update:error:()

- (nullable CBLSavedRevision*) update: (BOOL(^)(CBLUnsavedRevision *))  block
error: (NSError **)  outError 

Saves a new revision by letting the caller update the existing properties.

This method handles conflicts by retrying (calling the block again). The block body should modify the properties of the new revision and return YES to save or NO to cancel. Be careful: the block can be called multiple times if there is a conflict!

Parameters
blockWill be called on each attempt to save. Should update the given revision's properties and then return YES, or just return NO to cancel.
outErrorWill point to the error, if the method returns nil. (If the callback block cancels by returning nil, the error will be nil.) If this parameter is NULL, no error will be stored.
Returns
The new saved revision, or nil on error or cancellation.

◆ putExistingRevisionWithProperties:attachments:revisionHistory:fromURL:error:()

- (BOOL) putExistingRevisionWithProperties: (CBLJSONDict *)  properties
attachments: (nullable NSDictionary *)  attachments
revisionHistory: (CBLArrayOf(NSString *) *)  revIDs
fromURL: (nullable NSURL *)  sourceURL
error: (NSError **)  outError 

Adds an existing revision copied from another database.

Unlike a normal insertion, this does not assign a new revision ID; instead the revision's ID must be given. The revision's history (ancestry) must be given, which can put it anywhere in the revision tree. It's not an error if the revision already exists locally; it will just be ignored.

This is not an operation that clients normally perform; it's used by the replicator. You might want to use it if you're pre-loading a database with canned content, or if you're implementing some new kind of replicator that transfers revisions from another database.

Parameters
propertiesThe properties of the revision (_id and _rev will be ignored, but _deleted and _attachments are recognized.)
attachmentsA dictionary providing attachment bodies. The keys are the attachment names (matching the keys in the properties' _attachments dictionary) and the values are the attachment bodies as NSData or NSURL.
revIDsThe revision history in the form of an array of revision-ID strings, in reverse chronological order. The first item must be the new revision's ID. Following items are its parent's ID, etc.
sourceURLThe URL of the database this revision came from, if any. (This value shows up in the CBLDatabaseChange triggered by this insertion, and can help clients decide whether the change is local or not.)
outErrorError information will be stored here if the insertion fails.
Returns
YES on success, NO on failure.

◆ NS_UNAVAILABLE()

- (instancetype) NS_UNAVAILABLE

Property Documentation

◆ database

- (CBLDatabase*) database
readatomicassign

The document's owning database.

◆ documentID

- (NSString*) documentID
readatomicassign

The document's ID.

◆ abbreviatedID

- (NSString*) abbreviatedID
readatomicassign

An abbreviated form of the the documentID that looks like "xxxx..xxxx".

Useful in logging.

◆ isDeleted

- (BOOL) isDeleted
readatomicassign

Is this document deleted? (That is, does its current revision have the '_deleted' property?)

◆ isGone

- (BOOL) isGone
readatomicassign

Has this document either been deleted or removed from available Sync Gateway channels? (That is, does its current revision have a '_deleted' or '_removed' property?)

◆ expirationDate

- (NSDate*) expirationDate
readwriteatomicstrong

A date/time after which this document will be automatically purged.

◆ currentRevisionID

- (NSString*) currentRevisionID
readatomiccopy

The ID of the current revision (if known; else nil).

◆ currentRevision

- (CBLSavedRevision*) currentRevision
readatomicassign

The current/latest revision.

This object is cached.

◆ properties

- (CBLJSONDict*) properties
readatomiccopy

The contents of the current revision of the document.

This is shorthand for self.currentRevision.properties. Any keys in the dictionary that begin with "_", such as "_id" and "_rev", contain CouchbaseLite metadata.

◆ userProperties

- (CBLJSONDict*) userProperties
readatomiccopy

The user-defined properties, without the ones reserved by CouchDB.

This is based on -properties, with every key whose name starts with "_" removed.

◆ modelObject

- (id<CBLDocumentModel>) modelObject
readwriteatomicweak

Optional reference to an application-defined model object representing this document.

Usually this is a CBLModel, but you can implement your own model classes if you want. Note that this is a weak reference.


The documentation for this class was generated from the following file: