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, options: DatabaseOptions? = nil) throws
  • Same as document(withID:)

    Declaration

    Swift

    public subscript(docID: String) -> Document
  • Closes a database.

    Declaration

    Swift

    public func close() 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?
  • 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.

    Declaration

    Swift

    public func delete() 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
  • 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
  • Creates a new Document object with no properties and a new (random) UUID. The document will be saved to the database when you call -save: on it.

    Declaration

    Swift

    public func document() -> Document
  • Gets or creates a Document object with the given ID. The existence of the Document in the database can be checked by checking its .exists. Documents are cached, so there will never be more than one instance in this Database object at a time with the same documentID.

    Declaration

    Swift

    public func document(withID docID: String) -> Document
  • Checks whether the document of the given ID exists in the database or not.

    Declaration

    Swift

    public func contains(_ docID: String) -> Bool
  • The conflict resolver for this database. If nil, a default algorithm will be used, where the revision with more history wins. An individual document can override this for itself by setting its own property.

    Declaration

    Swift

    public var conflictResolver: ConflictResolver?
  • 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: [Expression]? = nil,
                                having: Predicate? = nil,
                                returning: [Expression]? = nil,
                                distinct: Bool = false,
                                orderBy: [SortDescriptor]? = nil) -> Query
  • 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: [Expression]) 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: [Expression], 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: [Expression], type: IndexType) throws