Hi, I was messing around with SQLDelight and WASM ...
# squarelibraries
a
Hi, I was messing around with SQLDelight and WASM without much success before version 2.1.0 came out. Now that it's supported in the current release, I'd like to pick it up again, but I'm not sure if there's any official documentation or example repo available. Right now, I'm a bit lost because of all the experiments I did before this version.
y
You can check out this repository: https://github.com/joreilly/PeopleInSpace
a
Thanks! That helped me! Especially PR https://github.com/joreilly/PeopleInSpace/pull/411. Although now I'm stuck with this error:
Copy code
IllegalStateException: The driver used with SQLDelight is asynchronous, so SQLDelight should be configured for
asynchronous usage:

sqldelight {
  databases {
    MyDatabase {
      generateAsync = true
    }
  }
}
I have the database configured as Async in the
build.gradle
, but I see that some of the generated methods are not marked with
suspend
(especially the
SELECT *
ones), and I don't know what else to look at anymore
y
Make sure to use
.synchronous()
when initializing the driver? For example, in this code:
Copy code
val platformModule = module {
    single {
        val driver = AndroidSqliteDriver(
            schema = LlmsDatabase.Schema.synchronous(),
            context = MyApp.getContext(),
            name = "LlmsDatabase.db"
        ).apply {
            enableForeignKeys()
        }
        LlmsDatabaseWrapper(driver, LlmsDatabase(driver))
    }
}
a
Yes, I have that in the Android and iOS target, but not for wasmJS and jvm. The error occurs in wasmJS
y
Try adding it to jvm and wasm too. I wanted to clarify my experience with SQL Delight’s WASM/JS, my code is correct, but I’m getting an ‘Uncaught coroutine exception’ error. So in case you got exception make sure to report it to the issue tracker
a
Turns out I found the issue... I forgot to migrate the
executeAs
calls to
awaitAs
. It's working fine now!
b
Yeah honestly the whole aync/not async aspect is not ideal. I wish the whole API would be suspend for all drivers.