https://kotlinlang.org logo
Title
i

Iliyan Germanov

04/14/2023, 4:08 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
    }
}
m

Michael Paus

04/14/2023, 4:36 PM
What about
JdbcSqliteDriver("jdbc:sqlite:${dbFilePath}")
i

Iliyan Germanov

04/14/2023, 4:37 PM
I'm noob to Desktop, do you have any good sample/snippet for creating the DB file + getting its path?
We don't care about migrations or anything. Just need the minimal code to get it running simalrly to how it runs on Android via the SQLite driver
m

Michael Paus

04/14/2023, 4:39 PM
The
dbFilePath
is just a String with the path to your DB file.
i

Iliyan Germanov

04/14/2023, 4:39 PM
Ahaa, and the JdbcSqliteDriver will handle the DB file creation itself?
m

Michael Paus

04/14/2023, 4:40 PM
Yes or you can also provide an already existing database file.
i

Iliyan Germanov

04/14/2023, 4:41 PM
Thank you very much @Michael Paus! Appreciated - will try it out 🙂