Skip to content

Commit 828e1cc

Browse files
authored
Add Room integration (#249)
1 parent e7d0f0f commit 828e1cc

File tree

23 files changed

+687
-58
lines changed

23 files changed

+687
-58
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- os: windows-latest
2323
targets: jvmTest
2424
runs-on: ${{ matrix.os }}
25-
timeout-minutes: 20
25+
timeout-minutes: 30
2626

2727
steps:
2828
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Add `rawConnection` getter to `ConnectionContext`, which is a `SQLiteConnection` instance from
77
`androidx.sqlite` that can be used to step through statements in a custom way.
88
* Fix an issue where `watch()` would run queries more often than intended.
9+
* Add an integration for the Room database library ([readme](integrations/room/README.md)).
910

1011
## 1.5.1
1112

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is the PowerSync client SDK for Kotlin. This SDK currently supports the fol
1313
- iOS
1414
- macOS
1515
- watchOS
16+
- tvOS
1617

1718
If you need support for additional targets, please reach out!
1819

@@ -32,6 +33,11 @@ and API documentation [here](https://powersync-ja.github.io/powersync-kotlin/).
3233
1. Retrieve a token to connect to the PowerSync service.
3334
2. Apply local changes on your backend application server (and from there, to your backend database).
3435

36+
- [integrations](./integrations/)
37+
- [room](./integrations/room/README.md): Allows using the [Room database library](https://developer.android.com/jetpack/androidx/releases/room)
38+
with PowerSync, making it easier to run typed queries on the database.
39+
40+
3541
## Demo Apps / Example Projects
3642

3743
The easiest way to test the PowerSync KMP SDK is to run one of our demo applications.
@@ -41,12 +47,6 @@ Demo applications are located in the [`demos/`](./demos) directory. See their re
4147
- [demos/supabase-todolist](./demos/supabase-todolist/README.md): A simple to-do list application demonstrating the use of the PowerSync Kotlin Multiplatform SDK and the Supabase connector.
4248
- [demos/android-supabase-todolist](./demos/android-supabase-todolist/README.md): A simple to-do list application demonstrating the use of the PowerSync Kotlin Multiplatform SDK and the Supabase connector in an Android application.
4349

44-
## Current Limitations / Future work
45-
46-
Current limitations:
47-
48-
- Integration with SQLDelight schema and API generation (ORM) is not yet supported.
49-
5050
## Installation
5151

5252
Add the PowerSync Kotlin Multiplatform SDK to your project by adding the following to your `build.gradle.kts` file:

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ plugins {
1919
alias(libs.plugins.keeper) apply false
2020
alias(libs.plugins.kotlin.atomicfu) apply false
2121
alias(libs.plugins.cocoapods) apply false
22+
alias(libs.plugins.ksp) apply false
23+
alias(libs.plugins.androidx.room) apply false
2224
id("org.jetbrains.dokka") version libs.versions.dokkaBase
2325
id("dokka-convention")
2426
}

core/src/androidMain/kotlin/com/powersync/DatabaseDriverFactory.android.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.powersync
33
import android.content.Context
44
import androidx.sqlite.SQLiteConnection
55
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
6+
import kotlin.Throws
67

78
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
89
public actual class DatabaseDriverFactory(
@@ -21,3 +22,7 @@ public actual class DatabaseDriverFactory(
2122
public fun BundledSQLiteDriver.addPowerSyncExtension() {
2223
addExtension("libpowersync.so", "sqlite3_powersync_init")
2324
}
25+
26+
@ExperimentalPowerSyncAPI
27+
@Throws(PowerSyncException::class)
28+
public actual fun resolvePowerSyncLoadableExtensionPath(): String? = "libpowersync.so"

core/src/appleNonWatchOsMain/kotlin/com/powersync/DatabaseDriverFactory.appleNonWatchOs.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ public actual class DatabaseDriverFactory {
2121
return db
2222
}
2323
}
24+
25+
@ExperimentalPowerSyncAPI
26+
@Throws(PowerSyncException::class)
27+
public actual fun resolvePowerSyncLoadableExtensionPath(): String? = powerSyncExtensionPath

core/src/commonMain/kotlin/com/powersync/DatabaseDriverFactory.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ public expect class DatabaseDriverFactory {
1717
): SQLiteConnection
1818
}
1919

20+
/**
21+
* Resolves a path to the loadable PowerSync core extension library.
22+
*
23+
* This library must be loaded on all databases using the PowerSync SDK. On platforms where the
24+
* extension is linked statically (only watchOS at the moment), this returns `null`.
25+
*
26+
* When using the PowerSync SDK directly, there is no need to invoke this method. It is intended for
27+
* configuring external database connections not managed by PowerSync to work with the PowerSync
28+
* SDK.
29+
*/
30+
@ExperimentalPowerSyncAPI
31+
@Throws(PowerSyncException::class)
32+
public expect fun resolvePowerSyncLoadableExtensionPath(): String?
33+
2034
@OptIn(ExperimentalPowerSyncAPI::class)
2135
internal fun openDatabase(
2236
factory: DatabaseDriverFactory,

core/src/jvmMain/kotlin/com/powersync/DatabaseDriverFactory.jvm.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.powersync
22

33
import androidx.sqlite.SQLiteConnection
44
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
5+
import com.powersync.db.runWrapped
56

67
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING", "SqlNoDataSourceInspection")
78
public actual class DatabaseDriverFactory {
@@ -20,3 +21,7 @@ public fun BundledSQLiteDriver.addPowerSyncExtension() {
2021
}
2122

2223
private val powersyncExtension: String by lazy { extractLib("powersync") }
24+
25+
@ExperimentalPowerSyncAPI
26+
@Throws(PowerSyncException::class)
27+
public actual fun resolvePowerSyncLoadableExtensionPath(): String? = runWrapped { powersyncExtension }

core/src/watchosMain/kotlin/com/powersync/DatabaseDriverFactory.watchos.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ private val didLoadExtension by lazy {
3131

3232
true
3333
}
34+
35+
@ExperimentalPowerSyncAPI
36+
@Throws(PowerSyncException::class)
37+
public actual fun resolvePowerSyncLoadableExtensionPath(): String? {
38+
didLoadExtension
39+
return null
40+
}

gradle/libs.versions.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ java = "17"
1010

1111
# Dependencies
1212
kermit = "2.0.8"
13-
kotlin = "2.2.10"
13+
kotlin = "2.2.10" # Note: When updating, always update the first part of the ksp version too
14+
ksp = "2.2.10-2.0.2"
1415
coroutines = "1.10.2"
1516
kotlinx-datetime = "0.7.1"
17+
serialization = "1.9.0"
1618
kotlinx-io = "0.8.0"
1719
ktor = "3.2.3"
1820
uuid = "0.8.4"
@@ -30,6 +32,7 @@ compose-preview = "1.9.0"
3032
compose-lifecycle = "2.9.2"
3133
androidxSqlite = "2.6.0-rc02"
3234
androidxSplashscreen = "1.0.1"
35+
room = "2.8.0-rc02"
3336

3437
# plugins
3538
android-gradle-plugin = "8.12.1"
@@ -88,6 +91,7 @@ ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "kto
8891
ktor-client-contentnegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
8992
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
9093
ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
94+
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
9195
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
9296
kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
9397

@@ -97,6 +101,8 @@ supabase-auth = { module = "io.github.jan-tennert.supabase:auth-kt", version.ref
97101
supabase-storage = { module = "io.github.jan-tennert.supabase:storage-kt", version.ref = "supabase" }
98102
androidx-sqlite-sqlite = { module = "androidx.sqlite:sqlite", version.ref = "androidxSqlite" }
99103
androidx-sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "androidxSqlite" }
104+
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
105+
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
100106

101107
# Sample - Android
102108
androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "androidx-core" }
@@ -143,3 +149,5 @@ keeper = { id = "com.slack.keeper", version.ref = "keeper" }
143149
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
144150
kotlin-atomicfu = { id = "org.jetbrains.kotlinx.atomicfu", version.ref = "atomicfu" }
145151
buildKonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildKonfig" }
152+
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
153+
androidx-room = { id = "androidx.room", version.ref = "room" }

0 commit comments

Comments
 (0)