Database

public final class Database

A Couchbase Lite database.

  • Initializes a Couchbase Lite database with a given name and database options. If the database does not yet exist, it will be created, unless the readOnly option is used. @param name The name of the database. May NOT contain capital letters! @param options The database options, or nil for the default options.

    Declaration

    Swift

    public init(name: String, config: DatabaseConfiguration? = nil) throws
  • The database’s name.

    Declaration

    Swift

    public var name: String
  • The database’s path. If the database is closed or deleted, nil value will be returned.

    Declaration

    Swift

    public var path: String?
  • Undocumented

    Declaration

    Swift

    public final class Database
  • Undocumented

    Declaration

    Swift

    public final class Database
  • Gets a Document object with the given ID.

    Declaration

    Swift

    public func getDocument(_ id: String) -> Document?
  • Checks whether the document of the given ID exists in the database or not.

    Declaration

    Swift

    public func contains(_ docID: String) -> Bool
  • Gets document fragment object by the given document ID.

    Declaration

    Swift

    public subscript(id: String) -> DocumentFragment
  • Saves the given document to the database. If the document in the database has been updated since it was read by this Document, a conflict occurs, which will be resolved by invoking the conflict handler. This can happen if multiple application threads are writing to the database, or a pull replication is copying changes from a server.

    Declaration

    Swift

    public func save(_ document: Document) throws
  • Deletes the given document. All properties are removed, and subsequent calls to the getDocument(id) method will return nil. Deletion adds a special tombstone revision to the database, as bookkeeping so that the change can be replicated to other databases. Thus, it does not free up all of the disk space occupied by the document. To delete a document entirely (but without the ability to replicate this), use purge(document) method

    Declaration

    Swift

    public func delete(_ document: Document) throws
  • Purges the given document from the database. This is more drastic than deletion: it removes all traces of the document. The purge will NOT be replicated to other databases.

    Declaration

    Swift

    public func purge(_ document: Document) throws
  • Runs a group of database operations in a batch. Use this when performing bulk write operations like multiple inserts/updates; it saves the overhead of multiple database commits, greatly improving performance.

    Declaration

    Swift

    public func inBatch(_ block: () throws -> Void ) throws
  • Add a document change listener to the document.

    Declaration

    Swift

    public func addChangeListener(_ listener: DocumentChangeListener, forDocumentID id: String)
  • Remove the document change listener from the document.

    Declaration

    Swift

    public func removeChangeListener(_ listener: DocumentChangeListener, forDocumentID id: String)
  • Closes a database.

    Declaration

    Swift

    public func close() throws
  • Deletes a database.

    Declaration

    Swift

    public func delete() throws
  • Compacts the database file by deleting unused attachment files and vacuuming the SQLite database

    Declaration

    Swift

    public func compact() throws
  • Changes the database’s encryption key, or removes encryption if the new key is nil. @param key The encryption key in the form of an NSString (a password) or an NSData object exactly 32 bytes in length (a raw AES key.) If a string is given, it will be internally converted to a raw key using 64,000 rounds of PBKDF2 hashing. A nil value will decrypt the database.

    Declaration

    Swift

    public func changeEncryptionKey(_ key: EncryptionKey?) throws
  • Deletes a database of the given name in the given directory.

    Declaration

    Swift

    public class func delete(_ name: String, inDirectory directory: String? = nil) throws
  • Checks whether a database of the given name exists in the given directory or not.

    Declaration

    Swift

    public class func exists(_ name: String, inDirectory directory: String? = nil) -> Bool
  • An iterator over all documents in the database, ordered by document ID.

    Declaration

    Swift

    public var allDocuments: DocumentIterator
  • Compiles a database query, from any of several input formats. Once compiled, the query can be run many times with different parameter values.

    Declaration

    Swift

    public func createQuery(where wher: Predicate? = nil,
                                groupBy: [PredicateExpression]? = nil,
                                having: Predicate? = nil,
                                returning: [PredicateExpression]? = nil,
                                distinct: Bool = false,
                                orderBy: [SortDescriptor]? = nil) -> PredicateQuery
  • Creates a value index (type kValueIndex) on a given document property. This will speed up queries that test that property, at the expense of making database writes a little bit slower. @param expressions Expressions to index, typically key-paths. Can be NSExpression objects, or NSStrings that are expression format strings. @param error If an error occurs, it will be stored here if this parameter is non-NULL. @return True on success, false on failure.

    Declaration

    Swift

    public func createIndex(_ expressions: [PredicateExpression]) throws
  • Creates an index on a given document property. This will speed up queries that test that property, at the expense of making database writes a little bit slower. @param expressions Expressions to index, typically key-paths. Can be NSExpression objects, or NSStrings that are expression format strings. @param type Type of index to create (value, full-text or geospatial.) @param options Options affecting the index, or NULL for default settings. @param error If an error occurs, it will be stored here if this parameter is non-NULL. @return True on success, false on failure.

    Declaration

    Swift

    public func createIndex(_ expressions: [PredicateExpression], options: IndexOptions) throws
  • Deletes an existing index. Returns NO if the index did not exist. @param expressions Expressions indexed (same parameter given to -createIndexOn:.) @param type Type of index. @param error If an error occurs, it will be stored here if this parameter is non-NULL. @return True if the index existed and was deleted, false if it did not exist.

    Declaration

    Swift

    public func deleteIndex(on expressions: [PredicateExpression], type: IndexType) throws