i am trying out sqldelight on web with the async webworker stuff
i am getting weird error messages
IllegalStateException: The driver used with SQLDelight is asynchronous, so SQLDelight should be configured for
asynchronous usage:
sqldelight {
databases {
MyDatabase {
generateAsync = true
}
}
}
even though it is configured for it..
sqldelight {
databases {
create("MyDatabase") {
packageName.set("com.example.projectname")
generateAsync.set(true)
}
}
}
sqldelight = "2.0.1" web-worker-driver = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "sqldelight" }
jsMain.dependencies {
implementation(compose.html.core)
implementation(libs.ktor.client.js)
implementation(libs.web.worker.driver)
implementation(devNpm("copy-webpack-plugin", "9.1.0"))
implementation(npm("@cashapp/sqldelight-sqljs-worker", "2.0.0"))
implementation(npm("sql.js", "1.8.0"))
}
actual class DatabaseDriverFactory {
private val mutex = Mutex()
actual suspend fun createDriver(): SqlDriver {
@Suppress("UnsafeCastFromDynamic")
val driver = WebWorkerDriver(
Worker(js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""")),
)
mutex.withLock {
MyDatabase.Schema.awaitCreate(driver)
return driver
}
}
}
this is kmp project
I encountered a similar problem and for a long time I was looking for the reason in the creation of the DB.
But it turned out that the creation (as given in the question) is correct. The problem was in the way the data was obtained.
I used a blocking call to executeAsList()
which conflicted with the async driver. After replacing it with awaitAsList()
, the program started working without exceptions.