Thread
#multiplatform
    d

    Daniele B

    2 years ago
    Does SqlDelight also work with pre-populated databases?
    Kris Wong

    Kris Wong

    2 years ago
    all databases are populated, outside of the short window before data is inserted into them
    s

    Seyed Jafari

    2 years ago
    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

    2 years ago
    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?
    Kris Wong

    Kris Wong

    2 years ago
    well, that depends on the your target platforms
    d

    Daniele B

    2 years ago
    Android and iOS
    I mean, do you I need to include the database file in CommonMain, or both in CommonAndroid and CommonIos ?
    Kris Wong

    Kris Wong

    2 years ago
    on Android you'll be using the resource system, specifically assets, and on iOS, bundle resources
    d

    Daniele B

    2 years ago
    doesn’t SqlDelight automate any these things?
    Kris Wong

    Kris Wong

    2 years ago
    this really isn't in scope for SqlDelight
    d

    Daniele B

    2 years ago
    so, I guess the location where I place the file is outside Common
    Kris Wong

    Kris Wong

    2 years ago
    it would be odd for a database library to be concerned with adding files into your target packaging
    d

    Daniele B

    2 years ago
    I would expect a MultiPlatform library to be provided with the database file only once, and then it would do the rest
    Kris Wong

    Kris Wong

    2 years ago
    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

    2 years ago
    mmm, I think I am missing something
    I am not really following what you are saying
    Kris Wong

    Kris Wong

    2 years ago
    are you familiar with mobile app packaging and sandboxes?
    d

    Daniele B

    2 years ago
    I don’t exactly understand what you mean with app sandboxing
    Kris Wong

    Kris Wong

    2 years ago
    alright. that's a fundamental concept for mobile apps. you will need to understand that.
    d

    Daniele B

    2 years ago
    maybe I know it by another name?
    Kris Wong

    Kris Wong

    2 years ago
    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

    2 years ago
    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
    Kris Wong

    Kris Wong

    2 years ago
    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

    2 years ago
    I thought that through the commonAndroid (and commonIos) sourcesets it was straightforward to manage that
    Kris Wong

    Kris Wong

    2 years ago
    i am not sure why you thought that, but if you have a source i'd be delighted to see it 🙂
    d

    Daniele B

    2 years ago
    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 🙂
    Kris Wong

    Kris Wong

    2 years ago
    yeah, that makes much more sense for that small amount of data