sqldelight
sqldelight copied to clipboard
Table not created on desktop without awaiting the result of Schema.create
SQLDelight Version
2.0.2
Operating System
Mac 14.4.1
Gradle Version
8.7
Kotlin Version
2.0.0
Dialect
SQLite
AGP Version
8.4.1
Describe the Bug
When running the desktop JVM app on Mac, the driver gets created like so:
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite:${dbFilePath}")
val result = Database.Schema.create(driver)
return driver
However, this .create
seems to be an asynchronous operation. As such, when I create a query over the database, by the time the query is created, this create operation is either not finished or for some reason cancelled, resulting in a missing database error ([SQLITE_ERROR] SQL error or missing database (no such table: ChatEntity)
)
For some reason, this is not an issue on Android nor iOS - perhaps just a matter of timing.
The solution seems to be to manually await the Schema.create call:
val result = Database.Schema.create(driver)
result.await()
However, nowhere in the docs is it mentioned that:
- creating a driver should be a suspend operation (i.e. the coroutine is managed and launched by the calling app)
- the create function needs to be awaited before proceeding to do other things with the database
Stacktrace
No response
Gradle Build Script
No response