https://kotlinlang.org logo
Title
i

Iliyan Germanov

04/14/2023, 4:01 PM
Hey all, what's the best way to plug-in a SQLDelight
SqlDriver
that is persistent and works on Desktop (Linux, Windows, MacOS)? Here's the Github repo. Best I can do is in-memory one:
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import ivy.Database

actual class SQLDelightDriverFactory {
    actual fun createDriver(): SqlDriver {
        val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
        Database.Schema.create(driver)
        return driver
    }
}
c

Casey Brooks

04/14/2023, 4:17 PM
I believe you can do it using a connection string like
jdbc:sqlite:PATH/TO/SQLITE/database.db
instead of
<http://JdbcSqliteDriver.IN|JdbcSqliteDriver.IN>_MEMORY
. It’s up to you to make sure that file exists, and perform the necessary migrations At one point, I recall having some issues with the default JDBC connection string, but I was able to make it work using HikariCP instead. Give the default connection a try first, but if that’s not working give HikariCP a go
i

Iliyan Germanov

04/14/2023, 4:29 PM
Thank you @Casey Brooks! Much appreciated. I'll go through the links that you've shared and try to make it work. Generally, I'm looking for the shortest path to make it work. Desktop is secondary priority for nice but it'll be nice if we support it w/o much work
About schema migrations - I don't care. It's okay for us to do "DROP ALL -> RECREATE" migration because the data will be synced via network.
@Casey Brooks if you have any code snippets that can get me started or repo of yours - it'll be awesome! I'm noob when it comes to Desktop development and just want to paste so default setup that'll make the Desktop version work like it does with SQLite on Android.