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

Daniele B

08/10/2020, 7:39 PM
Does SqlDelight also work with pre-populated databases?
k

Kris Wong

08/10/2020, 7:43 PM
all databases are populated, outside of the short window before data is inserted into them
s

Seyed Jafari

08/10/2020, 7:45 PM
it does not support currently but the database can be moved to the correct location before opening database so when sqldelight starts it reads from your copied file
d

Daniele B

08/10/2020, 8:16 PM
do you have any reference I can read to understand what are the platform-specific mechanisms for including the database file in the final packaging?
k

Kris Wong

08/10/2020, 8:17 PM
well, that depends on the your target platforms
d

Daniele B

08/10/2020, 8:17 PM
Android and iOS
I mean, do you I need to include the database file in CommonMain, or both in CommonAndroid and CommonIos ?
k

Kris Wong

08/10/2020, 8:18 PM
on Android you'll be using the resource system, specifically assets, and on iOS, bundle resources
d

Daniele B

08/10/2020, 8:18 PM
doesn’t SqlDelight automate any these things?
k

Kris Wong

08/10/2020, 8:18 PM
this really isn't in scope for SqlDelight
d

Daniele B

08/10/2020, 8:19 PM
so, I guess the location where I place the file is outside Common
k

Kris Wong

08/10/2020, 8:19 PM
it would be odd for a database library to be concerned with adding files into your target packaging
d

Daniele B

08/10/2020, 8:20 PM
I would expect a MultiPlatform library to be provided with the database file only once, and then it would do the rest
k

Kris Wong

08/10/2020, 8:20 PM
that's exactly how it works
but you need the file to be there, in the right place, within the app sandbox
SqlDelight doesn't care how it gets there
d

Daniele B

08/10/2020, 8:22 PM
mmm, I think I am missing something
I am not really following what you are saying
k

Kris Wong

08/10/2020, 8:22 PM
are you familiar with mobile app packaging and sandboxes?
d

Daniele B

08/10/2020, 8:23 PM
I don’t exactly understand what you mean with app sandboxing
k

Kris Wong

08/10/2020, 8:23 PM
alright. that's a fundamental concept for mobile apps. you will need to understand that.
d

Daniele B

08/10/2020, 8:23 PM
maybe I know it by another name?
k

Kris Wong

08/10/2020, 8:24 PM
i am not familiar with another term for the same concept
app packaging is installed on the device. it can include any kind of files you want. but in this case you need those files to be in the runtime area (sandbox) for the app.
d

Daniele B

08/10/2020, 8:30 PM
what I know is that at the moment in standard Android (not multiplatform), I am shipping the sqlite file in the asset directory, and at runtime when I call the database, there is some code that checks if the database exists in the right location, and if not it moves the database from the assets directory to the proper location
I was expecting that SqlDelight had some inbuilt mechanism to do this under the hood
as long as you provide the database file in a specific commonMain directory
k

Kris Wong

08/10/2020, 8:35 PM
sqldelight does not have a mechanism for that
even if it did, that's only half of the equation. you would still need to get the database file onto the device, which KMP does not provide a mechanism for.
d

Daniele B

08/10/2020, 8:37 PM
I thought that through the commonAndroid (and commonIos) sourcesets it was straightforward to manage that
k

Kris Wong

08/10/2020, 8:37 PM
i am not sure why you thought that, but if you have a source i'd be delighted to see it 🙂
d

Daniele B

08/10/2020, 8:39 PM
I haven’t actually written any code using SqlDelight yet. All examples I have seen so far are with creating a database from scratch.
But my use case is different than that
So I was looking for a way to get started on my use case
If I manage to do find a way, I guess it would be useful if I wrote a small tutorial
as I haven’t found any yet
Actually, now that I think about it, instead of shipping an sqlite file, I can provide SqlDelight the structure and content of the database and create it then. It doesn’t actually change much for me.
Actually, thinking further! I don’t even need a sqlite database! they are just 250 records, with 2 fields each, I can just store it on a Kotlin Map, why not!? 🙂
The Kotlin language already has great sorting/higher-order functions. I can just use those 🙂
k

Kris Wong

08/11/2020, 12:56 PM
yeah, that makes much more sense for that small amount of data
143 Views