Skip to content

Commit 924a115

Browse files
authored
Merge pull request #268 from powersync-ja/sql-libs-readme-polish
Leaner Readmes for Room and SQLDelight, linking to docs
2 parents a159bb9 + c9db4e8 commit 924a115

File tree

3 files changed

+5
-121
lines changed

3 files changed

+5
-121
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ and API documentation [here](https://powersync-ja.github.io/powersync-kotlin/).
3434
2. Apply local changes on your backend application server (and from there, to your backend database).
3535

3636
- [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.
37+
- [room](./integrations/room/README.md): Allows using the [Room database library](https://developer.android.com/jetpack/androidx/releases/room) with PowerSync, making it easier to run typed queries on the database.
3938
- [sqldelight](./integrations/sqldelight/README.md): Allows using [SQLDelight](https://sqldelight.github.io/sqldelight)
4039
with PowerSync, also enabling typed statements on the database.
4140

integrations/room/README.md

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,6 @@
33
> [!NOTE]
44
> Note that this package is currently in alpha.
55
6-
This module provides the ability to use PowerSync with Room databases. This module aims for complete
7-
Room support, meaning that:
6+
This module integrates PowerSync with Room databases. This allows you run typed queries against the local database with compile-time validation.
87

9-
1. Changes synced from PowerSync automatically update your Room `Flow`s.
10-
2. Room and PowerSync cooperate on the write connection, avoiding "database is locked errors".
11-
3. Changes from Room trigger a CRUD upload.
12-
13-
For more details on using this module, see its page on the [PowerSync documentation](https://docs.powersync.com/client-sdk-references/kotlin-multiplatform/libraries/room).
14-
15-
## Setup
16-
17-
Add a dependency on `com.powersync:integration-room` with the same version you use for the main
18-
PowerSync SDK.
19-
20-
PowerSync can use an existing Room database, provided that the PowerSync core SQLite extension has
21-
been loaded. To do that:
22-
23-
1. Add a dependency on `androidx.sqlite:sqlite-bundled`. Using the SQLite version from the Android
24-
framework will not work as it doesn't support loading extensions.
25-
2. On your `RoomDatabase.Builder`, call `setDriver()` with a PowerSync-enabled driver:
26-
```Kotlin
27-
val driver = BundledSQLiteDriver().also {
28-
it.loadPowerSyncExtension() // Extension method by this module
29-
}
30-
31-
Room.databaseBuilder(...).setDriver(driver).build()
32-
```
33-
3. Configure raw tables for your Room databases.
34-
35-
After these steps, you can open your Room database like you normally would. Then, you can use the
36-
following method to obtain a `PowerSyncDatabase` instance which is backed by Room:
37-
38-
```Kotlin
39-
// With Room, you need to use raw tables (https://docs.powersync.com/usage/use-case-examples/raw-tables).
40-
// This is because Room verifies your schema at runtime, and PowerSync-managed views will not
41-
// pass those checks.
42-
val schema = Schema(...)
43-
val pool = RoomConnectionPool(yourRoomDatabase, schema)
44-
val powersync = PowerSyncDatabase.opened(
45-
pool = pool,
46-
scope = this,
47-
schema = schema,
48-
identifier = "databaseName", // Prefer to use the same path/name as your Room database
49-
logger = Logger,
50-
)
51-
powersync.connect(...)
52-
```
53-
54-
Changes from PowerSync (regardless of whether they've been made with `powersync.execute` or from a
55-
sync operation) will automatically trigger updates in Room.
56-
57-
To also transfer local writes to PowerSync, you need to
58-
59-
1. Create triggers on your Room tables to insert into `ps_crud` (see the
60-
[PowerSync documentation on raw tables](https://docs.powersync.com/usage/use-case-examples/raw-tables#capture-local-writes-with-triggers)
61-
for details).
62-
2. Pass the schema as a second parameter to the `RoomConnectionPool` constructor. This will make the
63-
pool notify PowerSync on Room writes for every raw table mentioned in the schema.
64-
Alternatively, call `transferPendingRoomUpdatesToPowerSync` after writes in Room.
8+
For details on using this integration, see its page on the [PowerSync documentation](https://docs.powersync.com/client-sdk-references/kotlin-multiplatform/libraries/room).

integrations/sqldelight/README.md

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,6 @@
33
> [!NOTE]
44
> Note that this package is currently in beta.
55
6-
This library provides the `PowerSyncDriver` class, which implements an `SqlDriver` for `SQLDelight`
7-
backed by PowerSync.
6+
This library integrates PowerSync with SQLDelight. This allows you run typed queries against the local database with compile-time validation. It provides the `PowerSyncDriver` class, which implements a `SqlDriver` for `SQLDelight` backed by PowerSync.
87

9-
For more details on using this module, see its page on the [PowerSync documentation](https://docs.powersync.com/client-sdk-references/kotlin-multiplatform/libraries/sqldelight).
10-
11-
## Setup
12-
13-
Add a dependency on `com.powersync:integration-sqldelight`, using the same version you use for the
14-
PowerSync SDK.
15-
16-
## Usage
17-
18-
To get started, ensure that SQLDelight is not linking sqlite3 (the PowerSync SDK takes care of that,
19-
and you don't want to link it twice). Also, ensure the async generator is active because the
20-
PowerSync driver does not support synchronous reads:
21-
22-
```kotlin
23-
sqldelight {
24-
databases {
25-
linkSqlite.set(false)
26-
27-
create("MyAppDatabase") {
28-
generateAsync.set(true)
29-
deriveSchemaFromMigrations.set(false)
30-
31-
dialect("app.cash.sqldelight:sqlite-3-38-dialect")
32-
}
33-
}
34-
}
35-
```
36-
37-
Next, define your tables in `.sq` files (but note that the `CREATE TABLE` statement won't be used,
38-
PowerSync creates JSON-backed views for tables instead).
39-
Open a PowerSync database [in the usual way](https://docs.powersync.com/client-sdk-references/kotlin-multiplatform#getting-started)
40-
and finally pass it to the constructor of your generated SQLDelight database:
41-
42-
```kotlin
43-
val db: PowerSyncDatabase = openPowerSyncDatabase()
44-
val yourSqlDelightDatabase = YourDatabase(PowerSyncDriver(db))
45-
```
46-
47-
Afterwards, writes on both databases (the original `PowerSyncDatabase` instance and the SQLDelight
48-
database) will be visible to each other, update each other's query flows and will get synced
49-
properly.
50-
51-
## Limitations
52-
53-
Please note that this library is currently in alpha. It is tested, but API changes are still
54-
possible.
55-
56-
There are also some limitations to be aware of:
57-
58-
1. Due to historical reasons, the PowerSync SDK migrates all databases to `user_version` 1 when
59-
created (but it will never downgrade a database).
60-
So if you want to use SQLDelight's schema tools, the first version would have to be `2`.
61-
2. The `CREATE TABLE` statements in your `.sq` files are only used at build time to verify your
62-
queries. At runtime, PowerSync will create tables from your schema as views, the defined
63-
statements are ignored.
64-
If you want to use the schema managed by SQLDelight, configure PowerSync to use
65-
[raw tables](https://docs.powersync.com/usage/use-case-examples/raw-tables).
66-
3. Functions and tables contributed by the PowerSync core extension are not visible to `.sq` files
67-
at the moment. We might revisit this with a custom dialect in the future.
8+
For details on using this integration, see its page on the [PowerSync documentation](https://docs.powersync.com/client-sdk-references/kotlin-multiplatform/libraries/sqldelight).

0 commit comments

Comments
 (0)