From 3f0d8d5fbfcd4d3bd637d20017ffb740bb62d15d Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Mon, 28 Oct 2024 12:36:57 -0600 Subject: [PATCH] Prepare 3.1.9-1.1.1 release --- CHANGELOG.md | 10 +++++++++ LICENSE | 2 +- README.md | 22 ++++++++++---------- couchbase-lite-ee-kermit/README.md | 2 +- couchbase-lite-ee-ktx/README.md | 2 +- couchbase-lite-ee-paging/README.md | 2 +- couchbase-lite-ee/README.md | 2 +- couchbase-lite-kermit/README.md | 2 +- couchbase-lite-ktx/README.md | 2 +- couchbase-lite-paging/README.md | 2 +- couchbase-lite/README.md | 2 +- docs/api/couchbase-lite-ee-kermit/index.html | 2 +- docs/api/couchbase-lite-ee-ktx/index.html | 2 +- docs/api/couchbase-lite-ee-paging/index.html | 2 +- docs/api/couchbase-lite-ee/index.html | 2 +- docs/api/couchbase-lite-kermit/index.html | 2 +- docs/api/couchbase-lite-ktx/index.html | 2 +- docs/api/couchbase-lite-paging/index.html | 2 +- docs/api/couchbase-lite/index.html | 2 +- docs/site/differences.md | 6 +++--- docs/site/kotlin-extensions.md | 6 +++--- docs/site/license.md | 2 +- gradle.properties | 2 +- mkdocs.yml | 6 +++--- 24 files changed, 49 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e818c15f3..2a9d8e1f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## 3.1.9-1.1.1 +> 28 Oct 2024 + +* Update Couchbase Lite dependency to 3.1.9 ([#29](https://github.com/jeffdgr8/kotbase/pull/29)) + * [Android SDK](https://docs.couchbase.com/couchbase-lite/3.1/android/releasenotes.html#maint-3-1-9) + * [Java SDK](https://docs.couchbase.com/couchbase-lite/3.1/java/releasenotes.html#maint-3-1-9) + * [Objective-C SDK](https://docs.couchbase.com/couchbase-lite/3.1/objc/releasenotes.html#maint-3-1-9) + * [C SDK](https://docs.couchbase.com/couchbase-lite/3.1/c/releasenotes.html#maint-3-1-9) +* Update dependencies ([#30](https://github.com/jeffdgr8/kotbase/pull/30)) + ## 3.1.3-1.1.0 > 1 Feb 2023 diff --git a/LICENSE b/LICENSE index bcf967af3..78b15521c 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022-2023 Jeff Lockhart and respective authors and developers. + Copyright 2022-2024 Jeff Lockhart and respective authors and developers. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 63367a1e8..ad8fa0d1e 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ kotlin { sourceSets { commonMain.dependencies { // Community Edition - implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1") // or Enterprise Edition - implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1") } } } @@ -103,9 +103,9 @@ https://kotlinlang.org/api/kotlinx-datetime/kotlinx-datetime/kotlinx.datetime/-i * Some deprecated APIs are omitted. * While not available in the Java SDK, as Java doesn't support operator overloading, [`Fragment` subscript APIs]( https://kotbase.dev/current/kotlin-extensions/#fragment-subscripts) are available in Kotbase, similar to [Swift]( - https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( - https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( - https://docs.couchbase.com/mobile/3.1.3/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). ## Extension Libraries @@ -120,9 +120,9 @@ as well as other convenience functions for composing queries, observing change ` ```kotlin // Community Edition -implementation("dev.kotbase:couchbase-lite-ktx:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-ktx:3.1.9-1.1.1") // or Enterprise Edition -implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.9-1.1.1") ``` ### Kotbase Kermit @@ -134,9 +134,9 @@ https://kermit.touchlab.co/). Kermit can direct its logs to any number of log ou ```kotlin // Community Edition -implementation("dev.kotbase:couchbase-lite-kermit:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-kermit:3.1.9-1.1.1") // or Enterprise Edition -implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.9-1.1.1") ``` ### Kotbase Paging @@ -151,9 +151,9 @@ performs limit/offset paging queries based on a user-supplied database query. ```kotlin // Community Edition -implementation("dev.kotbase:couchbase-lite-paging:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-paging:3.1.9-1.1.1") // or Enterprise Edition -implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.3-1.1.0") +implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.9-1.1.1") ``` ## Roadmap diff --git a/couchbase-lite-ee-kermit/README.md b/couchbase-lite-ee-kermit/README.md index 4ddb46fb0..54ca37138 100644 --- a/couchbase-lite-ee-kermit/README.md +++ b/couchbase-lite-ee-kermit/README.md @@ -11,7 +11,7 @@ its logs to any number of log outputs, including the console. kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-ee-ktx/README.md b/couchbase-lite-ee-ktx/README.md index 699731cac..487ab1250 100644 --- a/couchbase-lite-ee-ktx/README.md +++ b/couchbase-lite-ee-ktx/README.md @@ -11,7 +11,7 @@ as well as other convenience functions for composing queries, observing change ` kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-ee-paging/README.md b/couchbase-lite-ee-paging/README.md index a84499ca3..053803cde 100644 --- a/couchbase-lite-ee-paging/README.md +++ b/couchbase-lite-ee-paging/README.md @@ -14,7 +14,7 @@ based on a user-supplied database query. kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-ee/README.md b/couchbase-lite-ee/README.md index ce251822d..1224bbe98 100644 --- a/couchbase-lite-ee/README.md +++ b/couchbase-lite-ee/README.md @@ -10,7 +10,7 @@ Kotbase core Couchbase Lite Enterprise Edition library kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-kermit/README.md b/couchbase-lite-kermit/README.md index 4a1f06ac1..8550a4207 100644 --- a/couchbase-lite-kermit/README.md +++ b/couchbase-lite-kermit/README.md @@ -11,7 +11,7 @@ its logs to any number of log outputs, including the console. kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-kermit:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-kermit:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-ktx/README.md b/couchbase-lite-ktx/README.md index 0d7a17006..853e94678 100644 --- a/couchbase-lite-ktx/README.md +++ b/couchbase-lite-ktx/README.md @@ -11,7 +11,7 @@ as well as other convenience functions for composing queries, observing change ` kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-ktx:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-ktx:3.1.9-1.1.1") } } } diff --git a/couchbase-lite-paging/README.md b/couchbase-lite-paging/README.md index 25b743d25..8b1bb8c07 100644 --- a/couchbase-lite-paging/README.md +++ b/couchbase-lite-paging/README.md @@ -14,7 +14,7 @@ based on a user-supplied database query. kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite-paging:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite-paging:3.1.9-1.1.1") } } } diff --git a/couchbase-lite/README.md b/couchbase-lite/README.md index 986394acc..ae7d3a744 100644 --- a/couchbase-lite/README.md +++ b/couchbase-lite/README.md @@ -10,7 +10,7 @@ Kotbase core Couchbase Lite Community Edition library kotlin { sourceSets { commonMain.dependencies { - implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0") + implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1") } } } diff --git a/docs/api/couchbase-lite-ee-kermit/index.html b/docs/api/couchbase-lite-ee-kermit/index.html index 13b860c43..3fd12f562 100644 --- a/docs/api/couchbase-lite-ee-kermit/index.html +++ b/docs/api/couchbase-lite-ee-kermit/index.html @@ -67,7 +67,7 @@

couchbase-lite-ee-kermit

-

Couchbase Lite Enterprise Edition – Kermit Logging Extensions

Kotbase Kermit is a Couchbase Lite custom logger which logs to Kermit. Kermit can direct its logs to any number of log outputs, including the console.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.3-1.1.0")
}
}
}

Usage

// Disable default console logs and log to Kermit
Database.log.console.level = LogLevel.NONE
Database.log.custom = KermitCouchbaseLiteLogger(kermit)
+

Couchbase Lite Enterprise Edition – Kermit Logging Extensions

Kotbase Kermit is a Couchbase Lite custom logger which logs to Kermit. Kermit can direct its logs to any number of log outputs, including the console.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-kermit:3.1.9-1.1.1")
}
}
}

Usage

// Disable default console logs and log to Kermit
Database.log.console.level = LogLevel.NONE
Database.log.custom = KermitCouchbaseLiteLogger(kermit)

Packages

diff --git a/docs/api/couchbase-lite-ee-ktx/index.html b/docs/api/couchbase-lite-ee-ktx/index.html index 475a0fa06..d8d0519b7 100644 --- a/docs/api/couchbase-lite-ee-ktx/index.html +++ b/docs/api/couchbase-lite-ee-ktx/index.html @@ -70,7 +70,7 @@

couchbase-lite-ee-ktx

-

Couchbase Lite Enterprise Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.3-1.1.0")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Couchbase Lite Enterprise Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.3-1.1.0")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

+

Couchbase Lite Enterprise Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.9-1.1.1")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Couchbase Lite Enterprise Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-ktx:3.1.9-1.1.1")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Packages

diff --git a/docs/api/couchbase-lite-ee-paging/index.html b/docs/api/couchbase-lite-ee-paging/index.html index ba06bf435..b8715ab69 100644 --- a/docs/api/couchbase-lite-ee-paging/index.html +++ b/docs/api/couchbase-lite-ee-paging/index.html @@ -67,7 +67,7 @@

couchbase-lite-ee-paging

-

Couchbase Lite Enterprise Edition – Paging Extensions

The paging extensions are built on Cash App's Multiplatform Paging, Google's AndroidX Paging with multiplatform support. Kotbase Paging provides a PagingSource which performs limit/offset paging queries based on a user-supplied database query.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.3-1.1.0")
}
}
}

Usage

// 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<Hotel>(json)
}
val queryProvider: From.() -> LimitRouter = {
where {
("type" equalTo "hotel") and
("state" equalTo "California")
}
.orderBy { "name".ascending() }
}

val pagingSource = QueryPagingSource(
EmptyCoroutineContext,
select,
collection,
mapper,
queryProvider
)
+

Couchbase Lite Enterprise Edition – Paging Extensions

The paging extensions are built on Cash App's Multiplatform Paging, Google's AndroidX Paging with multiplatform support. Kotbase Paging provides a PagingSource which performs limit/offset paging queries based on a user-supplied database query.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee-paging:3.1.9-1.1.1")
}
}
}

Usage

// 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<Hotel>(json)
}
val queryProvider: From.() -> LimitRouter = {
where {
("type" equalTo "hotel") and
("state" equalTo "California")
}
.orderBy { "name".ascending() }
}

val pagingSource = QueryPagingSource(
EmptyCoroutineContext,
select,
collection,
mapper,
queryProvider
)

Packages

diff --git a/docs/api/couchbase-lite-ee/index.html b/docs/api/couchbase-lite-ee/index.html index f05585601..77d5f1363 100644 --- a/docs/api/couchbase-lite-ee/index.html +++ b/docs/api/couchbase-lite-ee/index.html @@ -75,7 +75,7 @@

couchbase-lite-ee

-

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

+

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Enterprise Edition

Kotbase core Couchbase Lite Enterprise Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ee:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
maven("https://mobile.maven.couchbase.com/maven2/dev/")
}

Usage

See usage guide at kotbase.dev.

Packages

diff --git a/docs/api/couchbase-lite-kermit/index.html b/docs/api/couchbase-lite-kermit/index.html index 617ac66db..babc81653 100644 --- a/docs/api/couchbase-lite-kermit/index.html +++ b/docs/api/couchbase-lite-kermit/index.html @@ -67,7 +67,7 @@

couchbase-lite-kermit

-

Couchbase Lite Community Edition – Kermit Logging Extensions

Kotbase Kermit is a Couchbase Lite custom logger which logs to Kermit. Kermit can direct its logs to any number of log outputs, including the console.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-kermit:3.1.3-1.1.0")
}
}
}

Usage

// Disable default console logs and log to Kermit
Database.log.console.level = LogLevel.NONE
Database.log.custom = KermitCouchbaseLiteLogger(kermit)
+

Couchbase Lite Community Edition – Kermit Logging Extensions

Kotbase Kermit is a Couchbase Lite custom logger which logs to Kermit. Kermit can direct its logs to any number of log outputs, including the console.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-kermit:3.1.9-1.1.1")
}
}
}

Usage

// Disable default console logs and log to Kermit
Database.log.console.level = LogLevel.NONE
Database.log.custom = KermitCouchbaseLiteLogger(kermit)

Packages

diff --git a/docs/api/couchbase-lite-ktx/index.html b/docs/api/couchbase-lite-ktx/index.html index 7ab328a47..7ee3d2bc6 100644 --- a/docs/api/couchbase-lite-ktx/index.html +++ b/docs/api/couchbase-lite-ktx/index.html @@ -70,7 +70,7 @@

couchbase-lite-ktx

-

Couchbase Lite Community Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ktx:3.1.3-1.1.0")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Couchbase Lite Community Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ktx:3.1.3-1.1.0")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

+

Couchbase Lite Community Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ktx:3.1.9-1.1.1")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Couchbase Lite Community Edition – Kotlin Extensions

The KTX extensions include the excellent Kotlin extensions by MOLO17, as well as other convenience functions for composing queries, observing change Flows, and creating indexes.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-ktx:3.1.9-1.1.1")
}
}
}

Usage

QueryBuilder extensions

The syntax for building a query is more straight-forward thanks to Kotlin's infix function support.

select(all()) from collection where { "type" equalTo "user" }

Or just a bunch of fields:

select("name", "surname") from collection where { "type" equalTo "user" }

Or if you also want the document ID:

select(Meta.id, all()) from collection where { "type" equalTo "user" }
select(Meta.id, "name", "surname") from collection where { "type" equalTo "user" }

You can even do more powerful querying:

select("name", "type")
.from(collection)
.where {
(("type" equalTo "user") and ("name" equalTo "Damian")) or
(("type" equalTo "pet") and ("name" like "Kitt"))
}
.orderBy { "name".ascending() }
.limit(10)

There are also convenience extensions for performing SELECT COUNT(*) queries:

val query = selectCount() from collection where { "type" equalTo "user" }
val count = query.execute().countResult()

Document builder DSL

For creating a MutableDocument ready to be saved, you can use a Kotlin builder DSL:

val document = MutableDocument {
"name" to "Damian"
"surname" to "Giusti"
"age" to 24
"pets" to listOf("Kitty", "Kitten", "Kitto")
"type" to "user"
}

collection.save(document)
Collection creation functions

You can create a MutableArray or MutableDictionary using idiomatic vararg functions:

mutableArrayOf("hello", 42, true)
mutableDictOf("key1" to "value1", "key2" to 2, "key3" to null)

The similar mutableDocOf function allows nesting dictionary types, unlike the MutableDocument DSL:

mutableDocOf(
"string" to "hello",
"number" to 42,
"array" to mutableArrayOf(1, 2, 3),
"dict" to mutableDictOf("key" to "value")
)

Flow support

Supplementing the Flow APIs from Couchbase Lite Android KTX present in the base couchbase-lite modules, Kotbase KTX adds some additional useful Flow APIs.

Query Flow

Query.asFlow() builds on top of Query.queryChangeFlow() to emit non-null ResultSets and throw any QueryChange errors.

select(all())
.from(collection)
.where { "type" equalTo "user" }
.asFlow()
.collect { value: ResultSet ->
// consume ResultSet
}
Document Flow

Unlike Collection.documentChangeFlow(), which only emits DocumentChanges, Collection.documentFlow() handles the common use case of getting the initial document state and observing changes from the collection, enabling reactive UI patterns.

collection.documentFlow("userProfile")
.collect { doc: Document? ->
// consume Document
}

ResultSet model mapping

Map delegation

Thanks to Map delegation, mapping a ResultSet to a Kotlin class has never been so easy.

The library provides the ResultSet.toObjects() and Query.asObjectsFlow() extensions for helping to map results given a factory lambda.

Such factory lambdas accept a Map<String, Any?> and return an instance of a certain type. Those requirements fit perfectly with a Map-delegated class.

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

val usersFlow: Flow<List<User>> = query.asObjectsFlow(::User)
JSON deserialization

Kotbase KTX also provides extensions for mapping documents from a JSON string to Kotlin class. This works well together with a serialization library, like kotlinx-serialization, to decode the JSON string to a Kotlin object.

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

val usersFlow: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Index creation

Kotbase KTX provides concise top-level functions for index creation:

collection.createIndex("typeNameIndex", valueIndex("type", "name"))
collection.createIndex("overviewFTSIndex", fullTextIndex("overview"))
Replicator extensions

For the Android platform, you can bind the Replicator start() and stop() methods to be performed automatically when your Lifecycle-enabled component gets resumed or paused.

// Binds the Replicator to the Application lifecycle.
replicator.bindToLifecycle(ProcessLifecycleOwner.get().lifecycle)
// Binds the Replicator to the Activity/Fragment lifecycle.
// inside an Activity or Fragment...
override fun onCreate(savedInstanceState: Bundle?) {
replicator.bindToLifecycle(lifecycle)
}

That's it! The Replicator will be automatically started when your component passes the ON_RESUME state, and it will be stopped when the component passes the ON_PAUSED state. As you may imagine, no further action will be made after the ON_DESTROY state.

Packages

diff --git a/docs/api/couchbase-lite-paging/index.html b/docs/api/couchbase-lite-paging/index.html index fba7fb15c..87678a89e 100644 --- a/docs/api/couchbase-lite-paging/index.html +++ b/docs/api/couchbase-lite-paging/index.html @@ -67,7 +67,7 @@

couchbase-lite-paging

-

Couchbase Lite Community Edition – Paging Extensions

The paging extensions are built on Cash App's Multiplatform Paging, Google's AndroidX Paging with multiplatform support. Kotbase Paging provides a PagingSource which performs limit/offset paging queries based on a user-supplied database query.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-paging:3.1.3-1.1.0")
}
}
}

Usage

// 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<Hotel>(json)
}
val queryProvider: From.() -> LimitRouter = {
where {
("type" equalTo "hotel") and
("state" equalTo "California")
}
.orderBy { "name".ascending() }
}

val pagingSource = QueryPagingSource(
EmptyCoroutineContext,
select,
collection,
mapper,
queryProvider
)
+

Couchbase Lite Community Edition – Paging Extensions

The paging extensions are built on Cash App's Multiplatform Paging, Google's AndroidX Paging with multiplatform support. Kotbase Paging provides a PagingSource which performs limit/offset paging queries based on a user-supplied database query.

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite-paging:3.1.9-1.1.1")
}
}
}

Usage

// 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<Hotel>(json)
}
val queryProvider: From.() -> LimitRouter = {
where {
("type" equalTo "hotel") and
("state" equalTo "California")
}
.orderBy { "name".ascending() }
}

val pagingSource = QueryPagingSource(
EmptyCoroutineContext,
select,
collection,
mapper,
queryProvider
)

Packages

diff --git a/docs/api/couchbase-lite/index.html b/docs/api/couchbase-lite/index.html index ede330f5d..0a232b108 100644 --- a/docs/api/couchbase-lite/index.html +++ b/docs/api/couchbase-lite/index.html @@ -75,7 +75,7 @@

couchbase-lite

-

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.3-1.1.0")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

+

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Couchbase Lite Community Edition

Kotbase core Couchbase Lite Community Edition library

Installation

kotlin {
sourceSets {
commonMain.dependencies {
implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
}
}
}
repositories {
mavenCentral()
}

Usage

See usage guide at kotbase.dev.

Packages

diff --git a/docs/site/differences.md b/docs/site/differences.md index b01f246c7..f89aec002 100644 --- a/docs/site/differences.md +++ b/docs/site/differences.md @@ -24,6 +24,6 @@ as straightforward as changing the import package from `com.couchbase.lite` to ` * Some deprecated APIs are omitted. * While not available in the Java SDK, as Java doesn't support operator overloading, [`Fragment` subscript APIs]( kotlin-extensions.md#fragment-subscripts) are available in Kotbase, similar to [Swift]( - https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( - https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( - https://docs.couchbase.com/mobile/3.1.3/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( + https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). diff --git a/docs/site/kotlin-extensions.md b/docs/site/kotlin-extensions.md index b1dbadd85..41bcd5944 100644 --- a/docs/site/kotlin-extensions.md +++ b/docs/site/kotlin-extensions.md @@ -15,9 +15,9 @@ This includes: Additionally, while not available in the Java SDK, as Java doesn't support operator overloading, Kotbase adds support for [`Fragment` subscript APIs](#fragment-subscripts), similar to Couchbase Lite [Swift]( -https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( -https://docs.couchbase.com/mobile/3.1.4/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( -https://docs.couchbase.com/mobile/3.1.3/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). +https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-swift/Classes/Fragment.html), [Objective-C]( +https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-objc/Protocols/CBLFragment.html), and [.NET]( +https://docs.couchbase.com/mobile/3.1.9/couchbase-lite-net/api/Couchbase.Lite.IFragment.html). ## Configuration Factories diff --git a/docs/site/license.md b/docs/site/license.md index dcdfec46c..2efa9ca83 100644 --- a/docs/site/license.md +++ b/docs/site/license.md @@ -3,7 +3,7 @@ hide: - toc --- -Copyright 2023 Jeff Lockhart +Copyright 2022-2024 Jeff Lockhart Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/gradle.properties b/gradle.properties index f36453d35..b2d63323d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,4 @@ android.nonTransitiveRClass=true # Publishing GROUP=dev.kotbase -VERSION=1.1.1-SNAPSHOT +VERSION=1.1.1 diff --git a/mkdocs.yml b/mkdocs.yml index c0428cdbe..a272b1fa6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -3,7 +3,7 @@ site_name: Kotbase site_url: https://kotbase.dev/ site_description: Kotlin Multiplatform library for Couchbase Lite—a lightweight, embedded, syncable, NoSQL database site_author: Jeff Lockhart -copyright: "© 2023 Jeff Lockhart" +copyright: "© 2024 Jeff Lockhart" repo_name: Kotbase repo_url: https://github.com/jeffdgr8/kotbase remote_branch: gh-pages @@ -81,8 +81,8 @@ extra: version: provider: mike default: current - version_full: 3.1.3-1.1.0 - version_objc: 3.1.4 + version_full: 3.1.9-1.1.1 + version_objc: 3.1.9 generator: false social: - icon: simple/github