Database

expect class Database : AutoCloseable(source)

A Couchbase Lite database.

actual class Database : DelegatedClass<<Error class: unknown class>> , AutoCloseable(source)
actual class Database : AutoCloseable(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

Get all collections in the default scope.

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 default collection, 0 if database is closed.

actual val count: Long
actual val count: Long
Link copied to clipboard

Get the default collection.

Link copied to clipboard
expect val defaultScope: Scope

Get the default scope.

actual val defaultScope: Scope
actual val defaultScope: Scope
Link copied to clipboard
expect val indexes: List<String>

Get a list of the names of indices on the default collection.

actual val indexes: List<String>
actual val indexes: List<String>
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?
Link copied to clipboard
expect val scopes: Set<Scope>

Get scope names that have at least one collection. Note: the default scope is exceptional as it will always be listed even though there are no collections under it.

actual val scopes: Set<Scope>
actual val scopes: Set<Scope>

Functions

Link copied to clipboard

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

Adds a change listener for the changes that occur in the database, in the default collection, 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, in the default collection, 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, in the default collection.

Adds a change listener for the changes that occur to the specified document, in the default collection, 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, in the default collection, 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 open override fun close()

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

actual open override fun close()
actual open override fun close()
Link copied to clipboard

Create a named collection in the default scope. If the collection already exists, the existing collection will be returned.

expect fun createCollection(collectionName: String, scopeName: String?): Collection

Create a named collection in the specified scope. If the collection already exists, the existing collection will be returned.

actual fun createCollection(collectionName: String, scopeName: String?): Collection
actual fun createCollection(collectionName: String, scopeName: String?): Collection
Link copied to clipboard
expect fun createIndex(name: String, index: Index)
expect fun createIndex(name: String, config: IndexConfiguration)

Add an index to the default collection.

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 default collection. When write operations are executed concurrently, the last writer will overwrite all other written values. Calling this function is the same as calling delete(Document, ConcurrencyControl.LAST_WRITE_WINS)

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

Deletes a document from the default collection. 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 and the method will return false.

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 deleteCollection(name: String)

Delete a collection by name in the default scope. If the collection doesn't exist, the operation will be no-ops. Note: the default collection cannot be deleted.

expect fun deleteCollection(collectionName: String, scopeName: String?)

Delete a collection by name in the specified scope. If the collection doesn't exist, the operation will be no-ops. Note: the default collection cannot be deleted.

actual fun deleteCollection(name: String)
actual fun deleteCollection(collectionName: String, scopeName: String?)
actual fun deleteCollection(name: String)
actual fun deleteCollection(collectionName: String, scopeName: String?)
Link copied to clipboard
expect fun deleteIndex(name: String)

Delete the named index from the default collection.

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
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 getCollection(name: String): Collection?

Get a collection in the default scope by name. If the collection doesn't exist, the function will return null.

expect fun getCollection(collectionName: String, scopeName: String?): Collection?

Get a collection in the specified scope by name. If the collection doesn't exist, the function will return null.

actual fun getCollection(name: String): Collection?
actual fun getCollection(collectionName: String, scopeName: String?): Collection?
actual fun getCollection(name: String): Collection?
actual fun getCollection(collectionName: String, scopeName: String?): Collection?
Link copied to clipboard
expect fun getCollections(scopeName: String?): Set<Collection>

Get all collections in the named scope.

actual fun getCollections(scopeName: String?): Set<Collection>
actual fun getCollections(scopeName: String?): Set<Collection>
Link copied to clipboard
expect fun getDocument(id: String): Document?

Gets an existing Document with the given ID from the default collection. If the document with the given ID doesn't exist in the default collection, the method will return null. If the database is closed the method will throw an IllegalStateException.

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

Returns the expiration time of the document. If the document has no expiration time set, the method will return null.

Link copied to clipboard
expect fun getScope(name: String): Scope?

Get a scope object by name. As the scope cannot exist by itself without having a collection, the null value will be returned if there are no collections under the given scope’s name. Note: The default scope is exceptional, and it will always be returned.

actual fun getScope(name: String): Scope?
actual fun getScope(name: String): Scope?
Link copied to clipboard
open override fun hashCode(): Int
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

Perform database maintenance.

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

Purges the passed document from the default collection. This is more drastic than delete(Document): it removes all local traces of the document. Purges will NOT be replicated to other databases.

expect fun purge(id: String)

Purges the document with the passed id from default collection. This is more drastic than delete(Document), it removes all local traces of the document. Purges 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 a change listener added to the default collection.

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

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

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

Saves a document to the default collection. 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 when there is a conflict and the method will return false

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

Saves a document to the default collection. Conflicts will be resolved by the passed ConflictHandler

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 for a document in the default collection. The document will be purged from the database at the set time.

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