Skip to content

Commit cbe1691

Browse files
committed
New unified driver interfaces
1 parent 1c833dc commit cbe1691

File tree

45 files changed

+738
-1768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+738
-1768
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ plugins {
1313
alias(libs.plugins.skie) apply false
1414
alias(libs.plugins.kotlin.jvm) apply false
1515
alias(libs.plugins.kotlin.android) apply false
16-
alias(libs.plugins.sqldelight) apply false
17-
alias(libs.plugins.grammarKitComposer) apply false
1816
alias(libs.plugins.mavenPublishPlugin) apply false
1917
alias(libs.plugins.downloadPlugin) apply false
2018
alias(libs.plugins.kotlinter) apply false

compose/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ kotlin {
1919
sourceSets {
2020
commonMain.dependencies {
2121
api(project(":core"))
22-
implementation(project(":persistence"))
2322
implementation(compose.runtime)
2423
}
2524
androidMain.dependencies {

core/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ kotlin {
201201
}
202202

203203
dependencies {
204+
api(libs.kermit)
205+
204206
implementation(libs.uuid)
205207
implementation(libs.kotlin.stdlib)
206208
implementation(libs.ktor.client.core)
@@ -213,8 +215,7 @@ kotlin {
213215
implementation(libs.kotlinx.datetime)
214216
implementation(libs.stately.concurrency)
215217
implementation(libs.configuration.annotations)
216-
api(projects.persistence)
217-
api(libs.kermit)
218+
implementation(projects.drivers.common)
218219
}
219220
}
220221

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,37 @@
11
package com.powersync
22

33
import android.content.Context
4-
import com.powersync.db.JdbcSqliteDriver
5-
import com.powersync.db.buildDefaultWalProperties
6-
import com.powersync.db.internal.InternalSchema
7-
import com.powersync.db.migrateDriver
8-
import kotlinx.coroutines.CoroutineScope
9-
import org.sqlite.SQLiteCommitListener
10-
import java.util.concurrent.atomic.AtomicBoolean
4+
import androidx.sqlite.SQLiteConnection
5+
import com.powersync.db.loadExtensions
6+
import com.powersync.db.setSchemaVersion
7+
import com.powersync.internal.driver.AndroidDriver
8+
import com.powersync.internal.driver.ConnectionListener
9+
import com.powersync.internal.driver.JdbcConnection
1110

1211
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
1312
public actual class DatabaseDriverFactory(
1413
private val context: Context,
1514
) {
16-
internal actual fun createDriver(
17-
scope: CoroutineScope,
15+
internal actual fun openDatabase(
1816
dbFilename: String,
1917
dbDirectory: String?,
2018
readOnly: Boolean,
21-
): PsSqlDriver {
22-
val schema = InternalSchema
23-
19+
listener: ConnectionListener?
20+
): SQLiteConnection {
2421
val dbPath =
2522
if (dbDirectory != null) {
2623
"$dbDirectory/$dbFilename"
2724
} else {
28-
context.getDatabasePath(dbFilename)
25+
"${context.getDatabasePath(dbFilename)}"
2926
}
3027

31-
val properties = buildDefaultWalProperties(readOnly = readOnly)
32-
val isFirst = IS_FIRST_CONNECTION.getAndSet(false)
33-
if (isFirst) {
34-
// Make sure the temp_store_directory points towards a temporary directory we actually
35-
// have access to. Due to sandboxing, the default /tmp/ is inaccessible.
36-
// The temp_store_directory pragma is deprecated and not thread-safe, so we only set it
37-
// on the first connection (it sets a global field and will affect every connection
38-
// opened).
39-
val escapedPath = context.cacheDir.absolutePath.replace("\"", "\"\"")
40-
properties.setProperty("temp_store_directory", "\"$escapedPath\"")
41-
}
42-
43-
val driver =
44-
JdbcSqliteDriver(
45-
url = "jdbc:sqlite:$dbPath",
46-
properties = properties,
47-
)
48-
49-
migrateDriver(driver, schema)
50-
51-
driver.loadExtensions(
28+
val driver = AndroidDriver(context)
29+
val connection = driver.openDatabase(dbPath, readOnly, listener) as JdbcConnection
30+
connection.setSchemaVersion()
31+
connection.loadExtensions(
5232
"libpowersync.so" to "sqlite3_powersync_init",
5333
)
5434

55-
val mappedDriver = PsSqlDriver(driver = driver)
56-
57-
driver.connection.database.addUpdateListener { _, _, table, _ ->
58-
mappedDriver.updateTable(table)
59-
}
60-
61-
driver.connection.database.addCommitListener(
62-
object : SQLiteCommitListener {
63-
override fun onCommit() {
64-
// We track transactions manually
65-
}
66-
67-
override fun onRollback() {
68-
mappedDriver.clearTableUpdates()
69-
}
70-
},
71-
)
72-
73-
return mappedDriver
74-
}
75-
76-
private companion object {
77-
val IS_FIRST_CONNECTION = AtomicBoolean(true)
35+
return connection
7836
}
7937
}

core/src/commonJava/kotlin/com/powersync/db/JdbcPreparedStatement.kt

Lines changed: 0 additions & 226 deletions
This file was deleted.

0 commit comments

Comments
 (0)