https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
d

Daniele B

10/13/2023, 11:54 AM
I would like to ship a multiplatform app with an existing read-only sqlite database file. I guess SqlDelight cannot help with that. Any suggestion of which KMP library could I use?
a

Alex Nabrozidis

10/13/2023, 12:21 PM
Why not? Just don't write any write sql statements
d

Daniele B

10/13/2023, 12:57 PM
I mean, I want to ship an already populated sqlite database file. Is it possible to do that with SqlDelight? Where should the file be placed?
a

Alex Nabrozidis

10/13/2023, 1:01 PM
It should be, in the case of android you can just include it on the assets folder. I think you could even be able to read the db file from the there too
👍 1
d

Daniele B

10/13/2023, 1:15 PM
SqlDelight requires you to write the database table schema on a .sq text file. In this case, the database schema is already defined in the sqlite file. Unless SqlDelight is able to extract the schema from the sqlite database file, I wouldn't think it's the best tool for this job.
m

Mitchell Syer

10/13/2023, 1:48 PM
You just need to define the scheme, it doesn't require writing it to the database if you don't need to
d

Daniele B

10/13/2023, 1:53 PM
Where do you specify the location of the sqlite file you are shipping?
d

Derek Ellis

10/13/2023, 11:56 PM
As long as you know the schema of your database ahead of time, you can still define the schema in .sq files for SQLDelight to understand it. From there, you just need to put the database file in a place where you can load it, and then configure your driver correctly to point to that file
d

Daniele B

10/15/2023, 8:54 AM
Any idea which is the exact location where the file should be placed and/or where such location can be defined via the SqlDelight gradle config?
d

Derek Ellis

10/15/2023, 1:18 PM
There's no special SQLDelight config needed for this on Android, database files generally go into the app's private
databases/
directory, i.e.
Context.getDatabasePath()
I'm not sure where databases go on iOS
h

hfhbd

10/16/2023, 7:54 AM
Sqldelight can extract the schema from a local (dev, accessible from Gradle) SQLite database!
d

Daniele B

10/16/2023, 8:30 AM
Is there any documentation/sample for this?
h

hfhbd

10/16/2023, 8:35 AM
Just put a .db file in the sqldelight source folders, without a password of course
d

Daniele B

10/16/2023, 8:39 AM
Sounds exactly like what I was hoping for ❤️ I hope it's true 🙏
is it this documented anywhere?
i

Isaac

10/24/2023, 4:29 AM
@Daniele B I had to do something similar a couple of days ago and documented the experience here. The main focus was on iOS as Android was pretty straightforward(I link to a StackOverflow post that solves it for Android). Please let me know if you have any questions
d

Daniele B

10/24/2023, 12:01 PM
@Isaac great many thanks! I wish it was properly documented in the SqlDelight website
i

Isaac

10/24/2023, 12:20 PM
This was my wish too. It’s why I wrote it 😅
2 Views