Database

expect class Database(source)

A Couchbase Lite database.

actual class Database : DelegatedClass<<Error class: unknown class>> (source)
actual class Database(source)

Constructors

Link copied to clipboard
expect constructor(name: String)

Construct a Database with a given name and the default config. If the database does not yet exist it will be created.

expect constructor(name: String, config: DatabaseConfiguration)

Construct a Database with a given name and database config. If the database does not yet exist, it will be created, unless the readOnly option is used.

actual constructor(name: String)
actual constructor(name: String, config: DatabaseConfiguration)
actual constructor(name: String)
actual constructor(name: String, config: DatabaseConfiguration)

Types

Link copied to clipboard
expect object Companion
actual object Companion
actual object Companion

Properties

Link copied to clipboard

A READONLY copy of the database configuration.

Link copied to clipboard
expect val count: Long

The number of documents in the database, 0 if database is closed.

actual val count: Long
actual val count: Long
Link copied to clipboard
expect val name: String

The database name

actual val name: String
actual val name: String
Link copied to clipboard
expect val path: String?

The database's absolute path or null if the database is closed.

actual val path: String?
actual val path: String?

Functions

Link copied to clipboard

Adds a change listener for the changes that occur in the database.

Adds a change listener for the changes that occur in the database with a CoroutineContext that will be used to launch coroutines the listener will be called on. Coroutines will be launched in a CoroutineScope that is canceled when the listener is removed.

Adds a change listener for the changes that occur in the database with a CoroutineScope that will be used to launch coroutines the listener will be called on. The listener is removed when the scope is canceled.

Link copied to clipboard

Adds a change listener for the changes that occur to the specified document.

Adds a change listener for the changes that occur to the specified document with a CoroutineContext that will be used to launch coroutines the listener will be called on. Coroutines will be launched in a CoroutineScope that is canceled when the listener is removed.

Adds a change listener for the changes that occur to the specified document with a CoroutineScope that will be used to launch coroutines the listener will be called on. The listener is removed when the scope is canceled.

Link copied to clipboard
expect fun Database.changeEncryptionKey(encryptionKey: EncryptionKey?)

ENTERPRISE EDITION API

actual fun Database.changeEncryptionKey(encryptionKey: EncryptionKey?)
Link copied to clipboard
expect fun close()

Closes a database. Closing a database will stop all replicators, live queries and all listeners attached to it.

actual fun close()
actual fun close()
Link copied to clipboard
expect fun createIndex(name: String, index: Index)
expect fun createIndex(name: String, config: IndexConfiguration)

Add an index to the database.

actual fun createIndex(name: String, index: Index)
actual fun createIndex(name: String, config: IndexConfiguration)
actual fun createIndex(name: String, index: Index)
actual fun createIndex(name: String, config: IndexConfiguration)
Link copied to clipboard
expect fun createQuery(query: String): Query

Create a SQL++ query.

actual fun createQuery(query: String): Query
actual fun createQuery(query: String): Query
Link copied to clipboard

A Flow of database changes.

Link copied to clipboard
expect fun delete()

Deletes a database. Deleting a database will stop all replicators, live queries and all listeners attached to it. Although attempting to close a closed database is not an error, attempting to delete a closed database is.

expect fun delete(document: Document)

Deletes a document from the database. When write operations are executed concurrently, the last writer will overwrite all other written values. Calling this function is the same as calling the delete(Document, ConcurrencyControl) function with LAST_WRITE_WINS concurrency control.

expect fun delete(document: Document, concurrencyControl: ConcurrencyControl): Boolean

Deletes a document from the database. When used with lastWriteWins concurrency control, the last write operation will win if there is a conflict. When used with FAIL_ON_CONFLICT concurrency control, delete will fail with 'false' value returned.

actual fun delete()
actual fun delete(document: Document)
actual fun delete()
actual fun delete(document: Document)
actual fun delete(document: Document, concurrencyControl: ConcurrencyControl): Boolean
Link copied to clipboard
expect fun deleteIndex(name: String)

Delete the named index from the database.

actual fun deleteIndex(name: String)
actual fun deleteIndex(name: String)
Link copied to clipboard
fun Database.documentChangeFlow(documentId: String, coroutineContext: CoroutineContext? = null): Flow<DocumentChange>

A Flow of document changes.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun Database.get(key: String): DocumentFragment

Gets document fragment object by the given document ID.

Link copied to clipboard
expect fun getDocument(id: String): Document?

Gets an existing Document object with the given ID. If the document with the given ID doesn't exist in the database, the value returned will be null.

actual fun getDocument(id: String): Document?
actual fun getDocument(id: String): Document?
Link copied to clipboard

Returns the expiration time of the document. null will be returned if there is no expiration time set

Link copied to clipboard
expect fun getIndexes(): List<String>

Get a list of the names of indices on the database.

actual fun getIndexes(): List<String>
actual fun getIndexes(): List<String>
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
expect fun <R> inBatch(work: Database.() -> R): R

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.

actual fun <R> inBatch(work: Database.() -> R): R
actual fun <R> inBatch(work: Database.() -> R): R
Link copied to clipboard

Performs database maintenance.

Link copied to clipboard
expect fun purge(document: Document)

Purges the given document from the database. This is more drastic than delete(Document), it removes all traces of the document. The purge will NOT be replicated to other databases.

expect fun purge(id: String)

Purges the given document id for the document in database. This is more drastic than delete(Document), it removes all traces of the document. The purge will NOT be replicated to other databases.

actual fun purge(document: Document)
actual fun purge(id: String)
actual fun purge(document: Document)
actual fun purge(id: String)
Link copied to clipboard

Removes the change listener added to the database.

Link copied to clipboard
expect fun save(document: MutableDocument)

Saves a document to the database. When write operations are executed concurrently, the last writer will overwrite all other written values. Calling this method is the same as calling the ave(MutableDocument, ConcurrencyControl) method with LAST_WRITE_WINS concurrency control.

expect fun save(document: MutableDocument, concurrencyControl: ConcurrencyControl): Boolean

Saves a document to the database. When used with LAST_WRITE_WINS concurrency control, the last write operation will win if there is a conflict. When used with FAIL_ON_CONFLICT concurrency control, save will fail with false value

expect fun save(document: MutableDocument, conflictHandler: ConflictHandler): Boolean

Saves a document to the database. Conflicts will be resolved by the passed ConflictHandler. When write operations are executed concurrently and if conflicts occur, the conflict handler will be called. Use the conflict handler to directly edit the document to resolve the conflict. When the conflict handler returns 'true', the save method will save the edited document as the resolved document. If the conflict handler returns 'false', the save operation will be canceled with 'false' value returned as the conflict wasn't resolved.

actual fun save(document: MutableDocument)
actual fun save(document: MutableDocument, conflictHandler: ConflictHandler): Boolean
actual fun save(document: MutableDocument)
actual fun save(document: MutableDocument, concurrencyControl: ConcurrencyControl): Boolean
actual fun save(document: MutableDocument, conflictHandler: ConflictHandler): Boolean
Link copied to clipboard
expect fun setDocumentExpiration(id: String, expiration: Instant?)

Sets an expiration date on a document. After this time, the document will be purged from the database.

actual fun setDocumentExpiration(id: String, expiration: Instant?)
actual fun setDocumentExpiration(id: String, expiration: Instant?)
Link copied to clipboard
open override fun toString(): String