Database
public final class DatabaseA 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 readOnlyoption is used.Throws An error when the database cannot be opened.DeclarationSwift public init(name: String, config: DatabaseConfiguration = DatabaseConfiguration()) throwsParametersnameThe name of the database. configThe database options, or nil for the default options. 
- 
                  
                  The database’s name. DeclarationSwift public var name: String
- 
                  
                  The database’s path. If the database is closed or deleted, nil value will be returned. DeclarationSwift public var path: String?
- 
                  
                  The total numbers of documents in the database. DeclarationSwift public var count: UInt64
- 
                  
                  The database configuration. DeclarationSwift public var config: DatabaseConfiguration
- 
                  
                  Gets a Document object with the given ID. DeclarationSwift public func document(withID id: String) -> Document?
- 
                  
                  Gets document fragment object by the given document ID. DeclarationSwift public subscript(key: String) -> DocumentFragment
- 
                  
                  Saves the given mutable 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. Throws An error on a failure.DeclarationSwift @discardableResult public func saveDocument(_ document: MutableDocument) throws -> DocumentParametersdocumentThe document. Return ValueThe saved Document. 
- 
                  
                  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.Throws An error on a failure.DeclarationSwift public func deleteDocument(_ document: Document) throwsParametersdocumentThe document. 
- 
                  
                  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. Throws An error on a failure.DeclarationSwift public func purgeDocument(_ document: Document) throwsParametersdocumentThe document. 
- 
                  
                  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. Throws An error on a failure.DeclarationSwift public func inBatch(using block: () throws -> Void ) throwsParametersblockThe block to be executed as a batch operations. 
- 
                  
                  Adds a database change listener. Changes will be posted on the main queue. DeclarationSwift @discardableResult public func addChangeListener( _ listener: @escaping (DatabaseChange) -> Void) -> ListenerTokenParameterslistenerThe listener to post changes. Return ValueAn opaque listener token object for removing the listener. 
- 
                  
                  Adds a database change listener with the dispatch queue on which changes will be posted. If the dispatch queue is not specified, the changes will be posted on the main queue. DeclarationSwift @discardableResult public func addChangeListener(withQueue queue: DispatchQueue?, listener: @escaping (DatabaseChange) -> Void) -> ListenerTokenParametersqueueThe dispatch queue. listenerThe listener to post changes. Return ValueAn opaque listener token object for removing the listener. 
- 
                  
                  Adds a document change listener block for the given document ID. DeclarationSwift @discardableResult public func addDocumentChangeListener(withID id: String, listener: @escaping (DocumentChange) -> Void) -> ListenerTokenParametersdocumentIDThe document ID. listenerThe listener to post changes. Return ValueAn opaque listener token object for removing the listener. 
- 
                  
                  Adds a document change listener for the document with the given ID and the dispatch queue on which changes will be posted. If the dispatch queue is not specified, the changes will be posted on the main queue. DeclarationSwift @discardableResult public func addDocumentChangeListener(withID id: String, queue: DispatchQueue?, listener: @escaping (DocumentChange) -> Void) -> ListenerTokenParametersidThe document ID. queueThe dispatch queue. listenerThe listener to post changes. Return ValueAn opaque listener token object for removing the listener. 
- 
                  
                  Removes a change listener with the given listener token. DeclarationSwift public func removeChangeListener(withToken token: ListenerToken)ParameterstokenThe listener token. 
- 
                  
                  Closes a database. Throws An error on a failure.DeclarationSwift public func close() throws
- 
                  
                  Deletes a database. Throws An error on a failure.DeclarationSwift public func delete() throws
- 
                  
                  Compacts the database file by deleting unused attachment files and vacuuming the SQLite database. Throws An error on a failureDeclarationSwift public func compact() throws
- 
                  
                  Changes the database’s encryption key, or removes encryption if the new key is nil. Throws An error on a failure.DeclarationSwift public func setEncryptionKey(_ key: EncryptionKey?) throwsParameterskeyThe encryption key. 
- 
                  
                  Deletes a database of the given name in the given directory. Throws An error on a failure.DeclarationSwift public static func delete(withName name: String, inDirectory directory: String? = nil) throwsParametersnameThe database name. directoryThe directory where the database is located at. 
- 
                  
                  Checks whether a database of the given name exists in the given directory or not. DeclarationSwift public static func exists(withName name: String, inDirectory directory: String? = nil) -> BoolParametersnameThe database name. directoryThe directory where the database is located at. Return ValueTrue if the database exists, otherwise false. 
- 
                  
                  Copies a canned databaes from the given path to a new database with the given name and the configuration. The new database will be created at the directory specified in the configuration. Without given the database configuration, the default configuration that is equivalent to setting all properties in the configuration to nil will be used. Throws An error on a failure.DeclarationSwift public static func copy(fromPath path: String, toDatabase name: String, withConfig config: DatabaseConfiguration?) throwsParameterspathThe source database path. nameThe name of the new database to be created. configThe database configuration for the new database name. 
- 
                  
                  All index names. DeclarationSwift public var indexes: Array<String>
- 
                  
                  Creates an index which could be a value index or a full-text search index with the given name. The name can be used for deleting the index. Creating a new different index with an existing index name will replace the old index; creating the same index with the same name will be no-ops. Throws An error on a failure.DeclarationSwift public func createIndex(_ index: Index, withName name: String) throwsParametersindexThe index. nameThe index name. 
- 
                  
                  Deletes the index of the given index name. Throws An error on a failure.DeclarationSwift public func deleteIndex(forName name: String) throwsParametersnameThe index name. 
 Database Class Reference
        Database Class Reference