https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
k

Kapil Yadav

09/25/2023, 2:31 AM
Good mornings fweens !! Anyone used cash free sqldelight library to store data in Desktop. They have something like this to get SqlDriver
Copy code
val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
That means it isn’t persistent and its only in memory ? If these is another way please let me know. Thanks
p

Pablichjenkov

09/25/2023, 2:39 AM
Copy code
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite: your_database_name.db")
It places the .db in the Application root directory
k

Kapil Yadav

09/25/2023, 2:43 AM
Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (table Categories already exists) As I done after that facing this
Copy code
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite: SpendSense.db")
do we need to take some kind of permission in desktop for this ? @Pablichjenkov
j

jw

09/25/2023, 2:53 AM
You need to conditionally handle creation/migration of the schema
p

Pablichjenkov

09/25/2023, 2:53 AM
Honestly I haven't tried it in a production App. Just on my personal Mac and some other Macs at work and no need for permission so far. It is very likely that depending on the OS and the mechanism you use to distribute the package, you would have to ask for some permission.
k

Kapil Yadav

09/25/2023, 2:54 AM
Isn’t any way by which we can just remove it so that schema also gets remove, just for local testing
the debug version not the one which installs on machine
j

jw

09/25/2023, 2:55 AM
check for the file and delete it if present before opening the db
k

Kapil Yadav

09/25/2023, 2:55 AM
what is the path ?
j

jw

09/25/2023, 2:56 AM
whatever you pass in
presumably without an absolute root it uses the working directory, so simply doing
File("whatever.db")
should work fine
m

Michael Paus

09/25/2023, 6:55 AM
I have a published desktop application which uses SQLDelight and it just works on all major platforms (Mac, Windows and Linux) and you don’t need any specific permissions to run it. You define the location of the database file and when you delete it a new one is created according to your schema definition.
👍 1
p

Pablichjenkov

09/25/2023, 1:12 PM
Great to know that Michael !
d

Derek Ellis

09/25/2023, 1:25 PM
There is a
JdbcSqliteDriver
function that accepts a schema as an argument and will handle the conditional migration for you (as of SQLDelight 2.0)
2 Views