### Initialize and Run Replicator Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/active-peer.md Initialize and start a replicator with a `ReplicatorConfiguration`. This example demonstrates setting the endpoint, collections, replication type, continuous mode, auto-purge, self-signed certificate acceptance, and basic client authentication. ```kotlin // Create replicator // Consider holding a reference somewhere // to prevent the Replicator from being GCed val repl = Replicator( // initialize the replicator configuration ReplicatorConfiguration(URLEndpoint("wss://listener.com:8954")) .addCollections(collections) .apply { // Set replicator type type = ReplicatorType.PUSH_AND_PULL // Configure Sync Mode isContinuous = false // default value // set auto-purge behavior // (here we override default) isAutoPurgeEnabled = false // Configure Server Authentication -- // only accept self-signed certs isAcceptOnlySelfSignedServerCertificate = true // Configure the credentials the // client will provide if prompted authenticator = BasicAuthenticator("PRIVUSER", "let me in".toCharArray()) } ) // Start replicator repl.start(false) this.replicator = repl this.token = token ``` -------------------------------- ### start Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-replicator/index.html Starts the replicator instance. ```APIDOC ## start ### Description Start the replicator. ### Parameters #### Parameters - **resetCheckpoint** (Boolean) - Optional - Whether to reset the checkpoint before starting. ``` -------------------------------- ### Start Android App with ADB Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/getting-started.md Use this command to start the main activity of the Android application after installation. ```shell adb shell am start -n dev.kotbase.gettingstarted.compose/.MainActivity ``` -------------------------------- ### Initialize and start listener Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/passive-peer.md Configures the listener with network settings, TLS, and authentication, then starts the service. ```kotlin // Initialize the listener val listener = URLEndpointListener( URLEndpointListenerConfiguration( collections = collections, port = 55990, networkInterface = "wlan0", enableDeltaSync = false, // Configure server security disableTls = false, // Use an Anonymous Self-Signed Cert identity = null, // Configure Client Security using an Authenticator // For example, Basic Authentication authenticator = ListenerPasswordAuthenticator { usr, pwd -> (usr === validUser) && (pwd.concatToString() == validPass) } ) ) // Start the listener listener.start() ``` -------------------------------- ### Configure and Start Replicator Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/integrate-custom-listener.md Creates a Replicator instance using the initialized MessageEndpoint and starts the replication process. ```kotlin // Create the replicator object. val repl = Replicator( ReplicatorConfiguration(messageEndpoint) .addCollections(collections) ) // Start the replication. repl.start() this.replicator = repl ``` -------------------------------- ### URLEndpointListener - start() Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-u-r-l-endpoint-listener/start.html Starts the URLEndpointListener. This function has platform-specific implementations. ```APIDOC ## URLEndpointListener start() ### Description Starts the listener. ### Method N/A (This is a function call, not an HTTP endpoint) ### Endpoint N/A ### Parameters None ### Request Example None ### Response None ### Platform Specific Implementations: #### Apple ```kotlin actual fun start(): Unit ``` #### Common ```kotlin expect fun start(): Unit ``` #### JVM Common ```kotlin actual fun start(): Unit ``` #### Linux Mingw ```kotlin actual fun start(): Unit ``` ``` -------------------------------- ### Install Couchbase Lite Runtime (Community) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the Couchbase Lite C SDK runtime for Community Edition. ```bash sudo apt install libcblite-community ``` -------------------------------- ### Installation Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/index.html Instructions on how to add Kotbase as a dependency to your Kotlin project. ```APIDOC ## Installation ### Description Add the Kotbase dependency to your project's `build.gradle` file. ### Method Gradle Dependency Declaration ### Endpoint N/A ### Parameters N/A ### Request Example ```kotlin kotlin { sourceSets { commonMain.dependencies { implementation("dev.kotbase:couchbase-lite:3.2.4-1.2.0") } } } repositories { mavenCentral() } ``` ### Response N/A ``` -------------------------------- ### Replicator Start API Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-replicator/start.html This section details the various 'start' methods for the Kotbase Replicator across different platforms. These methods initiate the replication process asynchronously. ```APIDOC ## Replicator Start API ### Description Provides methods to start the replicator. ### Method GET ### Endpoint /replicator/start ### Parameters #### Query Parameters - **resetCheckpoint** (Boolean) - Optional - If true, resets the replicator's checkpoint. ### Request Example ```json { "resetCheckpoint": true } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "started" } ``` ### Notes - Replicators run asynchronously. - Replicators cannot be started from within a `Database.inBatch()` block. ``` -------------------------------- ### Initialize and Start Replicator Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/remote-sync-gateway.md Initialize a replicator with a specific configuration, including endpoints, collections, replication type, sync mode, and authentication. Start the replicator to begin synchronization. Consider holding a reference to the replicator to prevent garbage collection. ```kotlin val repl = Replicator( ReplicatorConfiguration(URLEndpoint("wss://listener.com:8954")) .addCollections(collections) .apply { type = ReplicatorType.PUSH_AND_PULL isContinuous = false isAutoPurgeEnabled = false isAcceptOnlySelfSignedServerCertificate = true authenticator = BasicAuthenticator("PRIVUSER", "let me in".toCharArray()) } ) repl.start(false) this.replicator = repl this.token = token ``` -------------------------------- ### Install Couchbase Lite Meta Package (dpkg) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the downloaded Couchbase Lite meta package using dpkg. ```bash sudo dpkg -i ./couchbase-release-1.0-noarch.deb ``` -------------------------------- ### Install Couchbase Lite Meta Package (apt) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the downloaded Couchbase Lite meta package using apt. ```bash sudo apt install ./couchbase-release-1.0-noarch.deb ``` -------------------------------- ### Install Android App with Gradle Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/getting-started.md Use this command to install the debug version of the Android application. ```gradle ./gradlew :composeApp:installDebug ``` -------------------------------- ### Install Couchbase Lite Runtime (Enterprise) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the Couchbase Lite C SDK runtime for Enterprise Edition. ```bash sudo apt install libcblite ``` -------------------------------- ### Install Couchbase Lite Development (Community) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the Couchbase Lite C SDK development files for Community Edition. ```bash sudo apt install libcblite-dev-community ``` -------------------------------- ### Install Couchbase Lite Development (Enterprise) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Install the Couchbase Lite C SDK development files for Enterprise Edition. ```bash sudo apt install libcblite-dev ``` -------------------------------- ### Conditional Operator Examples Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/n1ql-query-strings.md Examples of Simple and Searched CASE expressions for conditional logic. ```sql SELECT CASE state WHEN ‘CA’ THEN ‘Local’ ELSE ‘Non-Local’ END FROM DB ``` ```sql SELECT CASE WHEN shippedOn IS NOT NULL THEN ‘SHIPPED’ ELSE "NOT-SHIPPED" END FROM db ``` -------------------------------- ### Usage Guide Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/index.html Information on how to use the Kotbase library in your application. ```APIDOC ## Usage Guide ### Description Refer to the official Kotbase documentation for detailed usage instructions and examples. ### Method N/A ### Endpoint [https://kotbase.dev/](https://kotbase.dev/) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### GET /dependencies Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase.internal/-couchbase-lite-initializer/dependencies.html Retrieves the list of initializers required for Couchbase Lite. ```APIDOC ## GET /dependencies ### Description Retrieves the list of initializers required for Couchbase Lite. ### Method GET ### Endpoint /dependencies ### Parameters #### Query Parameters - **platform** (string) - Required - Filter by platform (e.g., 'android'). ### Response #### Success Response (200) - **dependencies** (List>>) - A list of initializer classes. ### Response Example { "dependencies": [ "com.couchbase.lite.internal.CouchbaseLiteInitializer" ] } ``` -------------------------------- ### Example app output Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/getting-started.md Log output showing database, collection, and document operations performed by the starter application. ```text 01-13 11:35:03.733 I/SHARED_KOTLIN: Database created: Database{@@0x9645222: 'desktopApp-db'} 01-13 11:35:03.742 I/SHARED_KOTLIN: Collection created: desktopApp-db@@x7fba7630dcb0._default.example-coll 01-13 11:35:03.764 I/DESKTOP_APP: Created document :: 83b6acb4-21ba-4834-aee4-2419dcea1114 01-13 11:35:03.767 I/SHARED_KOTLIN: Retrieved document: 01-13 11:35:03.767 I/SHARED_KOTLIN: Document ID :: 83b6acb4-21ba-4834-aee4-2419dcea1114 01-13 11:35:03.767 I/SHARED_KOTLIN: Learning :: Kotlin 01-13 11:35:03.768 I/DESKTOP_APP: Updated document :: 83b6acb4-21ba-4834-aee4-2419dcea1114 01-13 11:35:03.785 I/SHARED_KOTLIN: Number of rows :: 1 01-13 11:35:03.789 I/SHARED_KOTLIN: Document ID :: 83b6acb4-21ba-4834-aee4-2419dcea1114 01-13 11:35:03.790 I/SHARED_KOTLIN: Document :: {"language":"Kotlin","version":2.0,"platform":"JVM 21.0.1","input":"Hello, Kotbase!"} ``` -------------------------------- ### Case-Insensitive LIKE with Wildcards Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/query-builder.md Perform case-insensitive string matching using the LIKE operator combined with Function.lower(). This example finds documents where the 'name' property starts with 'eng', followed by any characters, then 'e', then any characters. Ensure the 'type' is 'landmark'. ```kotlin val query = QueryBuilder .select( SelectResult.expression(Meta.id), SelectResult.property("country"), SelectResult.property("name") ) .from(DataSource.collection(collection)) .where( Expression.property("type").equalTo(Expression.string("landmark")) .and( Function.lower(Expression.property("name")) .like(Expression.string("eng%e%")) ) ) query.execute().use { rs -> rs.forEach { println("name -> ${it.getString("name")}") } } ``` -------------------------------- ### Open or create a database Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/databases.md Initializes a database instance with a specified name and configuration. Always specify the directory path explicitly to ensure the database is created in the intended location. ```kotlin val database = Database( "my-db", DatabaseConfiguration() .setDirectory("path/to/database") ) ``` -------------------------------- ### Initialize and Configure URLEndpointListener Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/passive-peer.md Configures the listener with collections, network settings, and authentication, then starts the service. ```kotlin val listener = URLEndpointListener( URLEndpointListenerConfiguration( collections = collections, port = 55990, networkInterface = "wlan0", enableDeltaSync = false, // Configure server security disableTls = false, // Use an Anonymous Self-Signed Cert identity = null, // Configure Client Security using an Authenticator // For example, Basic Authentication authenticator = ListenerPasswordAuthenticator { usr, pwd -> (usr === validUser) && (pwd.concatToString() == validPass) } ) ) // Start the listener listener.start() ``` -------------------------------- ### Copy Database Using API Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/prebuilt-database.md This example demonstrates how to copy a pre-built database to a specified location using the `Database.copy()` method. It includes a check to prevent copying if the database already exists. Note that obtaining the path to the database and package resources is platform-specific. ```kotlin if (Database.exists("travel-sample") { return } val pathToPrebuiltDb = getPrebuiltDbPathFromResources() Database.copy( pathToPrebuiltDb, "travel-sample", DatabaseConfiguration() ) ``` -------------------------------- ### Collation Operator Examples Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/n1ql-query-strings.md Examples demonstrating the use of COLLATE with various options in SELECT and ORDER BY clauses. ```sql SELECT department FROM db WHERE (name = "fred") COLLATE UNICODE ``` ```sql SELECT department FROM db WHERE (name = "fred") COLLATE (UNICODE) ``` ```sql SELECT department FROM db WHERE (name = "fred") COLLATE (UNICODE CASE) ``` ```sql SELECT name FROM db ORDER BY name COLLATE (UNICODE DIAC) ``` -------------------------------- ### fun explain() Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-order-by/explain.html Returns a string describing the implementation of the compiled query, including the SQLite SELECT statement and the EXPLAIN QUERY PLAN output. ```APIDOC ## fun explain() ### Description Returns a string describing the implementation of the compiled query. This is intended to be read by a developer for purposes of optimizing the query, especially to add database indexes. It is not machine-readable and its format may change. ### Method Kotlin Function ### Returns - **String** - A string describing the implementation of the compiled query, consisting of the SQLite SELECT statement followed by the output of SQLite's "EXPLAIN QUERY PLAN" command. ### Throws - **CouchbaseLiteException** - If an error occurs during the generation of the explanation. ``` -------------------------------- ### Configuration and Settings Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-paging/navigation.html Information on configuring databases, collections, and replicators. ```APIDOC ## DatabaseConfiguration ### Description Configuration options for a database. ### Endpoint N/A (Class definition) ## CollectionConfiguration ### Description Configuration options for a collection. ### Endpoint N/A (Class definition) ## Replicator Defaults ### Description Default settings for replicators. ### Endpoint N/A (Object definition) ``` -------------------------------- ### Initialize CouchbaseLite with Custom Directories Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/[android]-couchbase-lite/init.html Initializes the library with custom root database and scratch directories. Use this method with caution. ```kotlin fun init(ctxt: Context, debug: Boolean, rootDbDir: File, scratchDir: File) ``` -------------------------------- ### Data Model for GroupBy Example Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/query-builder.md This JSON object represents a sample data model for an airport document, used in the GroupBy example. ```json { "_id": "airport123", "type": "airport", "country": "United States", "geo": { "alt": 456 }, "tz": "America/Anchorage" } ``` -------------------------------- ### SQLite query plan example Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/query-troubleshooting.md A breakdown of the execution plan showing retrieval, grouping, and ordering methods. ```text 7|0|0| SCAN TABLE kv_default AS _doc 12|0|0| USE TEMP B-TREE FOR GROUP BY 52|0|0| USE TEMP B-TREE FOR ORDER BY ``` -------------------------------- ### Get Float Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-dictionary/index.html Gets a property's value as a float. Integers will be converted to float. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the value doesn't exist or does not have a numeric value. ```APIDOC ## GET /float ### Description Gets a property's value as a float. Integers will be converted to float. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the value doesn't exist or does not have a numeric value. ### Method GET ### Endpoint /float #### Query Parameters - **key** (String) - Required - The key of the property to retrieve. ### Response #### Success Response (200) - **Float** - The float value associated with the key. ``` -------------------------------- ### Database Constructor Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-database/-database.html Initializes a new Database instance with a specified name and optional configuration. ```APIDOC ## Database Constructor ### Description Constructs a Database instance. If the database does not exist, it will be created. ### Parameters #### Path Parameters - **name** (String) - Required - The name of the database. May NOT contain capital letters. - **config** (DatabaseConfiguration) - Optional - The database configuration settings. ### Throws - **CouchbaseLiteException** - Thrown if any error occurs during the open operation. ``` -------------------------------- ### Get Double Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-dictionary/index.html Gets a property's value as a double. Integers will be converted to double. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the property doesn't exist or does not have a numeric value. ```APIDOC ## GET /double ### Description Gets a property's value as a double. Integers will be converted to double. The value `true` is returned as 1.0, `false` as 0.0. Returns 0.0 if the property doesn't exist or does not have a numeric value. ### Method GET ### Endpoint /double #### Query Parameters - **key** (String) - Required - The key of the property to retrieve. ### Response #### Success Response (200) - **Double** - The double value associated with the key. ``` -------------------------------- ### explain() Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-from/explain.html Returns a string describing the implementation of the compiled query, including the SQLite SELECT statement and the EXPLAIN QUERY PLAN output. ```APIDOC ## explain() ### Description Returns a string describing the implementation of the compiled query. This is intended to be read by a developer for purposes of optimizing the query, especially to add database indexes. It is not machine-readable and its format may change. ### Method Kotlin Function ### Returns - **String** - A string describing the implementation of the compiled query, consisting of the SQLite SELECT statement followed by the output of SQLite's "EXPLAIN QUERY PLAN" command. ### Throws - **CouchbaseLiteException** - If an error occurs during the process. ``` -------------------------------- ### Get Integer Property Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-mutable-dictionary/index.html Gets a property's value as an int. Floating point values will be rounded. `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value. ```APIDOC ## GET /api/dictionary/getInt ### Description Gets a property's value as an int. Floating point values will be rounded. `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value. ### Method GET ### Endpoint /api/dictionary/getInt #### Query Parameters - **key** (String) - Required - The key of the property to retrieve. ### Response #### Success Response (200) - **intValue** (Int) - The property's value as an int. #### Response Example { "intValue": 123 } ``` -------------------------------- ### Get Int Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-dictionary/index.html Gets a property's value as an int. Floating point values will be rounded. The value `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value. ```APIDOC ## GET /int ### Description Gets a property's value as an int. Floating point values will be rounded. The value `true` is returned as 1, `false` as 0. Returns 0 if the value doesn't exist or does not have a numeric value. ### Method GET ### Endpoint /int #### Query Parameters - **key** (String) - Required - The key of the property to retrieve. ### Response #### Success Response (200) - **Int** - The integer value associated with the key. ``` -------------------------------- ### Get Values Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ktx/kotbase.ktx/-document-builder/index.html Retrieve values from the dictionary by key. ```APIDOC ## GET /dictionary ### Description Retrieves values from the mutable dictionary. ### Method GET ### Endpoint Not applicable (methods are called on an instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (Any?) - The value associated with the key, or null if not found. #### Response Example ```json { "example": "value" } ``` ## GET /dictionary/long ### Description Retrieves a Long value from the dictionary by key. ### Method GET ### Endpoint Not applicable (methods are called on an instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (Long) - The Long value associated with the key. #### Response Example ```json { "example": 1234567890 } ``` ## GET /dictionary/number ### Description Retrieves a Number value from the dictionary by key. ### Method GET ### Endpoint Not applicable (methods are called on an instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (Number?) - The Number value associated with the key, or null if not found. #### Response Example ```json { "example": 123.45 } ``` ## GET /dictionary/string ### Description Retrieves a String value from the dictionary by key. ### Method GET ### Endpoint Not applicable (methods are called on an instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (String?) - The String value associated with the key, or null if not found. #### Response Example ```json { "example": "hello world" } ``` ``` -------------------------------- ### Configure and Initialize Replicator Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/remote-sync-gateway.md Use this example to configure and initialize a replicator for Couchbase Lite. Ensure you have Couchbase Lite 3.1+ and Sync Gateway 3.1+ for custom scopes and collections. This snippet demonstrates setting the endpoint, adding collections, defining replication type, continuous mode, auto-purge, server authentication (self-signed certificates), and client authentication (Basic Auth). ```kotlin val repl = Replicator( // initialize the replicator configuration ReplicatorConfiguration(URLEndpoint("wss://listener.com:8954")) .addCollections(collections).apply { // Set replicator type type = ReplicatorType.PUSH_AND_PULL // Configure Sync Mode isContinuous = false // default value // set auto-purge behavior // (here we override default) isAutoPurgeEnabled = false // Configure Server Authentication -- // only accept self-signed certs isAcceptOnlySelfSignedServerCertificate = true // Configure the credentials the // client will provide if prompted authenticator = BasicAuthenticator("PRIVUSER", "let me in".toCharArray()) } ) // Optionally add a change listener val token = repl.addChangeListener { change -> val err: CouchbaseLiteException? = change.status.error if (err != null) { println("Error code :: ${err.code}\n$err") } } // Start replicator repl.start(false) this.replicator = repl this.token = token ``` -------------------------------- ### Get Document Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-collection/index.html Retrieves a document from the collection by its ID. ```APIDOC ## GET /document/{id} ### Description Gets an existing Document object with the given ID. If the document with the given ID doesn't exist in the collection, the value returned will be null. ### Method GET ### Endpoint `/document/{id}` ### Parameters #### Path Parameters - **id** (String) - Required - The ID of the document to retrieve. ### Response #### Success Response (200) - **Document?** - The Document object if found, otherwise null. ### Request Example ```json { "id": "doc1" } ``` ### Response Example ```json { "_id": "doc1", "_rev": "1-abc", "content": "some data" } ``` ``` -------------------------------- ### Run JVM Desktop App with Gradle Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/getting-started.md Execute this command to run the JVM desktop version of the application. ```gradle ./gradlew :composeApp:run ``` -------------------------------- ### GET /getDocument Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-collection/index.html Retrieves an existing document by its ID. ```APIDOC ## GET /getDocument ### Description Gets an existing Document object with the given ID. Returns null if the document does not exist. ### Parameters #### Query Parameters - **id** (String) - Required - The ID of the document to retrieve. ``` -------------------------------- ### GET Collection Name Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-collection/name.html Retrieves the name of the collection. ```APIDOC ## GET Collection.name ### Description Returns the name of the collection as a String. ### Method GET ### Response - **name** (String) - The name of the collection. ``` -------------------------------- ### SELECT Wildcard Examples Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/n1ql-query-strings.md Use the '*' wildcard to select all properties. You can also select all properties from a specific data source and alias the result. ```sql SELECT * SELECT db.* AS data SELECT name fullName SELECT db.name fullName SELECT DISTINCT address.city ``` -------------------------------- ### Get Collection Configuration Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-replicator-configuration/index.html Retrieves the configuration for a given collection. ```APIDOC ## GET /api/collections/{collectionId}/configuration ### Description Retrieves the configuration for a given collection. ### Method GET ### Endpoint /api/collections/{collectionId}/configuration ### Parameters #### Path Parameters - **collectionId** (string) - Required - The ID of the collection to retrieve the configuration for. ### Response #### Success Response (200) - **CollectionConfiguration** (object) - The configuration of the collection. - **name** (string) - The name of the collection. - **documentKeys** (array) - An array of document keys. - ** 0** (string) - A document key. #### Response Example ```json { "name": "myCollection", "documentKeys": [ "key1", "key2" ] } ``` ``` -------------------------------- ### explain() Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-select/index.html Returns a human-readable string describing the implementation of a compiled query for optimization purposes. ```APIDOC ## explain() ### Description Returns a string describing the implementation of the compiled query. This is intended to be read by a developer for purposes of optimizing the query, especially to add database indexes. It's not machine-readable and its format may change. ### Response - **String** - A multi-line string describing the query execution plan. ``` -------------------------------- ### GET URLEndpointListener.config Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-u-r-l-endpoint-listener/config.html Retrieves the read-only configuration object for the URLEndpointListener. ```APIDOC ## GET URLEndpointListener.config ### Description Returns the read-only configuration associated with the URLEndpointListener instance. ### Method GET ### Endpoint URLEndpointListener.config ### Response #### Success Response (200) - **config** (URLEndpointListenerConfiguration) - The configuration object containing settings for the listener. ``` -------------------------------- ### GET /api/users/{userId} Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-from/where.html Retrieves details for a specific user. ```APIDOC ## GET /api/users/{userId} ### Description Fetches the profile information for a given user ID. ### Method GET ### Endpoint /api/users/{userId} ### Parameters #### Path Parameters - **userId** (string) - Required - The unique identifier of the user to retrieve. ### Response #### Success Response (200) - **userId** (string) - The user's unique identifier. - **username** (string) - The user's username. - **email** (string) - The user's email address. - **createdAt** (string) - The timestamp when the user account was created. #### Response Example { "userId": "usr_12345abcde", "username": "johndoe", "email": "john.doe@example.com", "createdAt": "2023-10-27T10:00:00Z" } ``` -------------------------------- ### Configure Basic Authentication Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/active-peer.md Use `BasicAuthenticator` to provide username and password credentials when the client is prompted by the server. ```kotlin // Configure the credentials the // client will provide if prompted authenticator = BasicAuthenticator("PRIVUSER", "let me in".toCharArray()) ``` -------------------------------- ### Example JSON Document Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/n1ql-query-strings.md Sample JSON structure used for demonstrating query operations. ```json { "Name": "Sam", "contacts": [ { "type": "primary", "address": { "street": "1 St", "city": "San Pedro", "state": "CA" }, "phones": [ { "type": "home", "number": "310-123-4567" }, { "type": "mobile", "number": "310-123-6789" } ] }, { "type": "secondary", "address": { "street": "5 St", "city": "Seattle", "state": "WA" }, "phones": [ { "type": "home", "number": "206-123-4567" }, { "type": "mobile", "number": "206-123-6789" } ] } ], "likes": ["soccer", "travel"] } ``` -------------------------------- ### GET /collections Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-database/index.html Retrieves all collections within the default scope. ```APIDOC ## GET /collections ### Description Get all collections in the default scope. ### Method GET ### Endpoint /collections ### Response #### Success Response (200) - **collections** (Set) - A set of all collections in the default scope. ``` -------------------------------- ### Create Collection DataSource (Linux/Mingw) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-data-source/-companion/collection.html Creates a DataSource from a Collection for Linux and Mingw platforms. Requires a Collection object. ```kotlin actual fun collection(collection: Collection): DataSource.As([source](https://github.com/jeffdgr8/kotbase/tree/main/couchbase-lite-ee/src/linuxMingwMain/kotlin/kotbase/DataSource.linuxMingw.kt#L53)) ``` -------------------------------- ### Get Document Expiration Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-collection/index.html Retrieves the expiration date of a document. ```APIDOC ## GET /document/{id}/expiration ### Description Gets the expiration date set to the document of the given ID. ### Method GET ### Endpoint `/document/{id}/expiration` ### Parameters #### Path Parameters - **id** (String) - Required - The ID of the document whose expiration date to retrieve. ### Response #### Success Response (200) - **Instant?** - The expiration date as an Instant object if set, otherwise null. ### Request Example ```json { "id": "doc1" } ``` ### Response Example ```json { "expirationDate": "2023-12-31T23:59:59Z" } ``` ``` -------------------------------- ### GET CouchbaseLiteException.domain Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/domain.html Retrieves the domain code associated with a CouchbaseLiteException. ```APIDOC ## GET CouchbaseLiteException.domain ### Description Returns the domain code for the specific CouchbaseLiteException instance. ### Property - **domain** (String) - The domain code for this error. ### See also - CBLError.Domain ``` -------------------------------- ### Document Builder DSL for Kotbase Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/documents.md Demonstrates using the Kotbase KTX extensions for a more concise document creation syntax. This approach uses a DSL to define document properties before saving. ```kotlin val doc = MutableDocument { "type" to "task" "owner" to "todo" "createdAt" to Clock.System.now() } database.save(doc) ``` -------------------------------- ### GET /api/document/getFloat Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-document/index.html Retrieves a property's value as a float. ```APIDOC ## GET /api/document/getFloat ### Description Retrieves a property's value as a float. ### Method GET ### Endpoint /api/document/getFloat ### Parameters #### Query Parameters - **key** (String) - Required - The key of the property to retrieve. ### Response #### Success Response (200) - **floatValue** (Float) - The retrieved float value. #### Response Example { "floatValue": 123.45 } ``` -------------------------------- ### Initialize Replicator Configuration with Target Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/active-peer.md Initialize the replicator configuration with the remote database endpoint. Use 'ws://' for non-TLS or 'wss://' for SSL/TLS connections. Ensure the correct port and database name are included. ```kotlin val config = ReplicatorConfiguration(URLEndpoint("wss://10.0.2.2:8954/travel-sample")) .addCollections(collections) ``` -------------------------------- ### GET /Array/getBoolean Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-array/index.html Retrieves a value at the given index as a boolean. ```APIDOC ## GET /Array/getBoolean ### Description Gets value at the given index as a boolean. ### Parameters #### Path Parameters - **index** (Int) - Required - The index of the element to retrieve. ### Response #### Success Response (200) - **Boolean** (Boolean) - The boolean value at the specified index. ``` -------------------------------- ### Get Query Plan Explanation Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-group-by/explain.html Call this function to obtain a developer-facing string that explains the compiled query's implementation. This is primarily for optimizing queries by identifying potential performance bottlenecks like 'SCAN TABLE'. The format is not guaranteed to be stable. ```kotlin expect open override fun explain(): String ``` -------------------------------- ### GET /Array/getBlob Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-array/index.html Retrieves a value at the given index as a Blob. ```APIDOC ## GET /Array/getBlob ### Description Gets value at the given index as a Blob. Returns null if the value doesn't exist, or its value is not a Blob. ### Parameters #### Path Parameters - **index** (Int) - Required - The index of the element to retrieve. ### Response #### Success Response (200) - **Blob** (Object) - The blob at the specified index or null. ``` -------------------------------- ### GET /Array/getArray Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-array/index.html Retrieves a value at the given index as an Array. ```APIDOC ## GET /Array/getArray ### Description Gets value at the given index as an Array. Returns null if the value doesn't exist, or its value is not an Array. ### Parameters #### Path Parameters - **index** (Int) - Required - The index of the element to retrieve. ### Response #### Success Response (200) - **MutableArray** (Object) - The array at the specified index or null. ``` -------------------------------- ### MutableArray Get Functions Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-mutable-array-interface/index.html Functions to retrieve elements from the MutableArray. ```APIDOC ### get Link copied to clipboard operator fun ArrayInterface.get(index: Int): Fragment Subscript access to a Fragment object of the projecting result value at the given index. ### getArray Link copied to clipboard abstract override fun getArray(index: Int): MutableArray? Gets an Array at the given index. Return null if the value is not an array. ### getBlob Link copied to clipboard abstract fun getBlob(index: Int): Blob? Gets value at the given index as a Blob. Returns null if the value doesn't exist, or its value is not a Blob. ### getBoolean Link copied to clipboard abstract fun getBoolean(index: Int): Boolean Gets value at the given index as a boolean. ### getDate Link copied to clipboard abstract fun getDate(index: Int): Instant? Gets value at the given index as an Instant date object. ``` -------------------------------- ### Initialize and configure a replicator Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/active-peer.md Configures a replicator with a WebSocket endpoint, collection settings, authentication, and a change listener. Must be executed on a background thread. ```kotlin val repl = Replicator( // initialize the replicator configuration ReplicatorConfiguration(URLEndpoint("wss://listener.com:8954")) .addCollections( collections, CollectionConfiguration( conflictResolver = ReplicatorConfiguration.DEFAULT_CONFLICT_RESOLVER ) ).apply { // Set replicator type type = ReplicatorType.PUSH_AND_PULL // Configure Sync Mode isContinuous = false // default value // Configure Server Authentication -- // only accept self-signed certs isAcceptOnlySelfSignedServerCertificate = true // Configure the credentials the // client will provide if prompted authenticator = BasicAuthenticator("PRIVUSER", "let me in".toCharArray()) } ) // Optionally add a change listener val token = repl.addChangeListener { change -> val err: CouchbaseLiteException? = change.status.error if (err != null) { println("Error code :: ${err.code}\n$err") } } // Start replicator repl.start(false) this.replicator = repl this.token = token ``` -------------------------------- ### Install Kotbase Paging Source: https://github.com/jeffdgr8/kotbase/blob/main/README.md Incorporate the Kotbase Paging extension library for efficient data handling with AndroidX Paging. Available for both Community and Enterprise Editions. ```kotlin implementation("dev.kotbase:couchbase-lite-paging:3.2.4-1.2.0") // or Enterprise Edition implementation("dev.kotbase:couchbase-lite-ee-paging:3.2.4-1.2.0") ``` -------------------------------- ### GET Document.collection Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-document/collection.html Retrieves the collection to which a specific document belongs. ```APIDOC ## GET Document.collection ### Description Returns the Collection object that the current Document instance belongs to. This property is available across multiple platforms including Apple, JVM, and Linux/Mingw. ### Return Value - **collection** (Collection?) - The collection instance or null if the document is not associated with a collection. ``` -------------------------------- ### GET /getDocumentExpiration Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-collection/index.html Retrieves the expiration date for a specific document. ```APIDOC ## GET /getDocumentExpiration ### Description Get the expiration date set to the document of the given id. ### Parameters #### Query Parameters - **id** (String) - Required - The ID of the document. ``` -------------------------------- ### Initialize CouchbaseLite Library (Custom Directories) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/[jvm]-couchbase-lite/init.html Initializes the CouchbaseLite library, allowing specification of root and scratch directories. Both directories must be writable. ```APIDOC ## fun init(debug: Boolean, rootDir: File, scratchDir: File) ### Description Initializes the CouchbaseLite library, allowing specification of a default root directory for database files, and the scratch directory used for temporary files (the native library, etc.). Both directories must be writable by this process. This method is optional to call before using CouchbaseLite. The no-parameter `CouchbaseLite.init()` will be called automatically by default. Debugging mode is not supported for client code. Please use it only when advised to do so by Couchbase Support Engineering. ### Method `fun` ### Endpoint N/A (Library initialization function) ### Parameters #### Query Parameters - **debug** (Boolean) - Required - `true` if debugging (Unsupported) - **rootDir** (File) - Required - default directory for databases - **scratchDir** (File) - Required - scratch directory for SQLite ### Throws `CouchbaseLiteError` on initialization failure. ``` -------------------------------- ### Get Blob Properties Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite/kotbase/-blob/index.html Retrieves the metadata associated with the blob. ```APIDOC ## GET /blob/properties ### Description The blob metadata. ### Method GET ### Endpoint /blob/properties ### Response #### Success Response (200) - **properties** (Map) - A map containing the blob's metadata. #### Response Example { "properties": { "key1": "value1", "key2": 123 } } ``` -------------------------------- ### Initialize QueryPagingSource Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee-paging/index.html Configure a QueryPagingSource using a mapper and query provider to handle paginated database results. ```kotlin // Uses kotlinx-serialization JSON processor@Serializabledata class Hotel(val id: String, val type: String, val name: String)val select = select(Meta.id, "type", "name")val mapper = { json: String -> Json.decodeFromString(json)}val queryProvider: QueryProvider = { where { ("type" equalTo "hotel") and ("state" equalTo "California") } .orderBy { "name".ascending() }}val pagingSource = QueryPagingSource( EmptyCoroutineContext, select, collection, mapper, queryProvider) ``` -------------------------------- ### Initialize QueryPagingSource Source: https://github.com/jeffdgr8/kotbase/blob/main/couchbase-lite-ee-paging/README.md Configure a QueryPagingSource by providing a database query, a mapper function, and a query provider. ```kotlin // Uses kotlinx-serialization JSON processor @Serializable data class Hotel(val id: String, val type: String, val name: String) val select = select(Meta.id, "type", "name") val mapper = { json: String -> Json.decodeFromString(json) } val queryProvider: QueryProvider = { where { ("type" equalTo "hotel") and ("state" equalTo "California") } .orderBy { "name".ascending() } } val pagingSource = QueryPagingSource( EmptyCoroutineContext, select, collection, mapper, queryProvider ) ``` -------------------------------- ### Dictionary Get Value Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-result/index.html Retrieve a value from the dictionary using a key. ```APIDOC ## GET /get ### Description Subscript access to a Fragment object of the projecting result value for the given key. ### Method GET ### Endpoint /get ### Parameters #### Query Parameters - **key** (String) - Required - The key of the value to retrieve. ### Response #### Success Response (200) - **value** (Fragment) - The value associated with the key. ``` -------------------------------- ### Run Android App via Command Line Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/getting-started.md Commands to install and launch the Android application from the terminal. ```bash ./gradlew :androidApp:installDebug ``` ```bash adb shell am start -n dev.kotbase.gettingstarted/.MainActivity ``` -------------------------------- ### URLEndpointListenerConfiguration Constructors Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-u-r-l-endpoint-listener-configuration/-u-r-l-endpoint-listener-configuration.html Constructors for initializing the URLEndpointListenerConfiguration object. ```APIDOC ## Constructor: URLEndpointListenerConfiguration ### Description Initializes a new configuration for a URL endpoint listener. ### Parameters #### Request Body - **collections** (Set) - Required - The set of collections to include. - **networkInterface** (String) - Optional - The network interface to bind to. - **port** (Int) - Required - The port number. - **disableTls** (Boolean) - Required - Whether to disable TLS. - **identity** (TLSIdentity) - Optional - The TLS identity. - **authenticator** (ListenerAuthenticator) - Optional - The listener authenticator. - **readOnly** (Boolean) - Required - Whether the configuration is read-only. - **enableDeltaSync** (Boolean) - Required - Whether to enable delta sync. ## Constructor: URLEndpointListenerConfiguration (Copy) ### Description Creates a new configuration by duplicating an existing one. ### Parameters #### Request Body - **config** (URLEndpointListenerConfiguration) - Required - The configuration to duplicate. ``` -------------------------------- ### Get Collections in Scope Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-scope/index.html Retrieves all collections within a given scope. ```APIDOC ## GET /scope/collections ### Description Get all collections in the scope. ### Method GET ### Endpoint `/scope/collections` ### Platform Availability - apple ### Response #### Success Response (200) - **collections** (Set<[Collection](../-collection/index.html)>) - A set of all collections within the scope. ``` -------------------------------- ### GET Scope.database Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-scope/database.html Retrieves the Database instance associated with the current Scope. ```APIDOC ## GET Scope.database ### Description Retrieves the Database instance associated with the current Scope object. This property is available across multiple platforms including Apple, JVM, and Linux/Mingw. ### Method GET ### Endpoint kotbase.Scope.database ### Response - **database** (Database) - The Database instance associated with the scope. ``` -------------------------------- ### useKeyStore Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-t-l-s-identity/-companion/index.html Registers a KeyStore for use in common APIs. ```APIDOC ## useKeyStore ### Description Register a KeyStore and key password to use in common APIs. ### Parameters - **keyStore** (KeyStore) - Required - The KeyStore to register. - **keyPassword** (CharArray) - Optional - The password for the KeyStore. ``` -------------------------------- ### Constructor: Clone URLEndpointListenerConfiguration Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-u-r-l-endpoint-listener-configuration/-u-r-l-endpoint-listener-configuration.html Creates a new URLEndpointListenerConfiguration by cloning an existing configuration instance. ```APIDOC ## Constructor: Clone URLEndpointListenerConfiguration ### Description Clone the passed listener configuration. ### Parameters - **config** (URLEndpointListenerConfiguration) - Required - The existing configuration to clone. ``` -------------------------------- ### GET ReplicatorChange.status Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-replicator-change/status.html Retrieves the current status of the replicator change event. ```APIDOC ## GET ReplicatorChange.status ### Description Returns the current status of the replicator, represented by a ReplicatorStatus object. ### Method GET ### Response #### Success Response (200) - **status** (ReplicatorStatus) - The current status of the replicator. ``` -------------------------------- ### GET MutableDictionary.getValue Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/api/couchbase-lite-ee/kotbase/-mutable-dictionary/get-value.html Retrieves the value associated with the specified key from the MutableDictionary. ```APIDOC ## getValue ### Description Retrieves the value associated with the specified key from the MutableDictionary instance. ### Method Function Call ### Parameters #### Path Parameters - **key** (String) - Required - The key whose associated value is to be returned. ### Response - **Return Value** (Any?) - The value associated with the key, or null if the key does not exist. ``` -------------------------------- ### Download Couchbase Lite Meta Package (wget) Source: https://github.com/jeffdgr8/kotbase/blob/main/docs/site/platforms.md Use wget to download the Couchbase Lite meta package for APT-based systems. ```bash wget https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-noarch.deb ```