Skip to content

Commit 13dd40e

Browse files
committed
Update readmes
1 parent eaaeaed commit 13dd40e

File tree

11 files changed

+43
-50
lines changed

11 files changed

+43
-50
lines changed

common/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# PowerSync common
2+
3+
This module contains core definitions for the PowerSync SDK, without linking or bundling a SQLite dependency.
4+
5+
This allows the module to be used as a building block for PowerSync SDKs with and without encryption support.
6+
7+
Users should typically depend on `:core` instead.
8+
9+
## Structure
10+
11+
This is a Kotlin Multiplatform project targeting Android, iOS platforms, with the following
12+
structure:
13+
14+
- `commonMain` - Shared code for all targets, which includes the `PowerSyncBackendConnector`
15+
interface and `PowerSyncBuilder` for building a `PowerSync` instance. It also defines
16+
the `DatabaseDriverFactory` class to be implemented in each platform.
17+
- `commonJava` - Shared logic for Android and Java targets.
18+
- `androidMain` - Android-specific code for loading the core extension.
19+
- `jvmMain` - Java-specific code for loading the core extension.
20+
- `nativeMain` - A SQLite driver implemented with cinterop calls to sqlite3.
21+
22+
## Attachment Helpers
23+
24+
This module contains attachment helpers under the `com.powersync.attachments` package. See
25+
the [Attachment Helpers README](../common/src/commonMain/kotlin/com/powersync/attachments/README.md)

common/src/commonIntegrationTest/kotlin/com/powersync/sync/SyncIntegrationTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.powersync.bucket.WriteCheckpointData
1515
import com.powersync.bucket.WriteCheckpointResponse
1616
import com.powersync.connectors.PowerSyncBackendConnector
1717
import com.powersync.connectors.PowerSyncCredentials
18+
import com.powersync.connectors.readCachedCredentials
1819
import com.powersync.db.PowerSyncDatabaseImpl
1920
import com.powersync.db.schema.PendingStatement
2021
import com.powersync.db.schema.PendingStatementParameter
@@ -123,7 +124,7 @@ abstract class BaseSyncIntegrationTest(
123124
turbineScope(timeout = 10.0.seconds) {
124125
val turbine = database.currentStatus.asFlow().testIn(this)
125126
turbine.waitFor { it.connected }
126-
connector.cachedCredentials shouldNotBe null
127+
connector.readCachedCredentials() shouldNotBe null
127128

128129
database.disconnect()
129130
turbine.waitFor { !it.connected }
@@ -134,7 +135,7 @@ abstract class BaseSyncIntegrationTest(
134135
waitFor { syncLines.isClosedForSend shouldBe true }
135136

136137
// And called invalidateCredentials on the connector
137-
connector.cachedCredentials shouldBe null
138+
connector.readCachedCredentials() shouldBe null
138139
}
139140

140141
@Test
@@ -674,7 +675,7 @@ abstract class BaseSyncIntegrationTest(
674675
// Should invalidate credentials when token expires
675676
syncLines.send(SyncLine.KeepAlive(tokenExpiresIn = 0))
676677
turbine.waitFor { !it.connected }
677-
connector.cachedCredentials shouldBe null
678+
connector.readCachedCredentials() shouldBe null
678679

679680
turbine.cancelAndIgnoreRemainingEvents()
680681
}

common/src/commonMain/kotlin/com/powersync/connectors/PowerSyncBackendConnector.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,8 @@ public abstract class PowerSyncBackendConnector {
128128
@Throws(PowerSyncException::class, CancellationException::class)
129129
public abstract suspend fun uploadData(database: PowerSyncDatabase)
130130
}
131+
132+
// Not using this indirection causes linker errors in tests: https://youtrack.jetbrains.com/issue/CMP-3318
133+
internal fun PowerSyncBackendConnector.readCachedCredentials(): PowerSyncCredentials? {
134+
return this.cachedCredentials
135+
}

core/README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,12 @@ structure:
1111
- `commonMain` - Shared code for all targets, which includes the `PowerSyncBackendConnector`
1212
interface and `PowerSyncBuilder` for building a `PowerSync` instance. It also defines
1313
the `DatabaseDriverFactory` class to be implemented in each platform.
14-
- `commonJava` - Common Java code including a Java SQLite driver using
15-
the [Xerial JDBC Driver](https://github.com/xerial/sqlite-jdbc). This is used by both the Android
16-
and JVM drivers.
1714
- `androidMain` - Android specific code, which includes an implementation of
18-
`DatabaseDriverFactory`.
19-
- `jvmMain` - JVM specific code which includes an implementation of `DatabaseDriverFactory`.
20-
- `iosMain` - iOS specific code, which includes am implementation of `DatabaseDriverFactory` class
21-
that creates an instance of `app.cash.sqldelight.driver.native.NativeSqliteDriver` and also sets
22-
up native SQLite bindings for iOS.
23-
24-
## Note on SQLDelight
25-
26-
The PowerSync core module, internally makes use
27-
of [SQLDelight](https://sqldelight.github.io/sqldelight/latest/) for it database API and typesafe
28-
database
29-
query generation.
30-
31-
The PowerSync core module does not currently support integrating with SQLDelight from client
32-
applications.
15+
`PersistentConnectionFactory`.
16+
- `jvmMain` - JVM specific code which includes an implementation of `PersistentConnectionFactory`.
17+
- `nativeMain` - iOS specific code, which includes am implementation of `PersistentConnectionFactory`.
3318

3419
## Attachment Helpers
3520

3621
This module contains attachment helpers under the `com.powersync.attachments` package. See
37-
the [Attachment Helpers README](./src/commonMain/kotlin/com/powersync/attachments/README.md)
22+
the [Attachment Helpers README](../common/src/commonMain/kotlin/com/powersync/attachments/README.md)

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ kotlin {
7676

7777
commonTest.dependencies {
7878
implementation(projects.internal.testutils)
79+
implementation(libs.kotlin.test)
7980
}
8081

8182
// We're putting the native libraries into our JAR, so integration tests for the JVM can run as part of the unit

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,13 @@ public actual class DatabaseDriverFactory: PersistentConnectionFactory, DriverBa
1111
path: String,
1212
openFlags: Int,
1313
): SQLiteConnection = driver.open(path, openFlags)
14-
15-
internal companion object {
16-
fun newDriver(): BundledSQLiteDriver {
17-
return BundledSQLiteDriver().also { addPowerSyncExtension(it) }
18-
}
19-
20-
@OptIn(ExperimentalPowerSyncAPI::class)
21-
fun addPowerSyncExtension(driver: BundledSQLiteDriver) {
22-
driver.addExtension(resolvePowerSyncLoadableExtensionPath()!!, "sqlite3_powersync_init")
23-
}
24-
}
2514
}
2615

16+
internal fun newDriver() = BundledSQLiteDriver().also { it.addPowerSyncExtension() }
17+
2718
@OptIn(ExperimentalPowerSyncAPI::class)
2819
public fun BundledSQLiteDriver.addPowerSyncExtension() {
29-
DatabaseDriverFactory.addPowerSyncExtension(this)
20+
addExtension(resolvePowerSyncLoadableExtensionPath()!!, "sqlite3_powersync_init")
3021
}
3122

32-
internal actual val inMemoryDriver: InMemoryConnectionFactory = DriverBasedInMemoryFactory(DatabaseDriverFactory.newDriver())
23+
internal actual val inMemoryDriver: InMemoryConnectionFactory = DriverBasedInMemoryFactory(newDriver())

0 commit comments

Comments
 (0)