Good mornings fweens !! Anyone used cash free sqld...
# compose-desktop
k
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
Copy code
val driver: SqlDriver = JdbcSqliteDriver("jdbc:sqlite: your_database_name.db")
It places the .db in the Application root directory
k
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
You need to conditionally handle creation/migration of the schema
p
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
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
check for the file and delete it if present before opening the db
k
what is the path ?
j
whatever you pass in
presumably without an absolute root it uses the working directory, so simply doing
File("whatever.db")
should work fine
m
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
Great to know that Michael !
d
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)