https://kotlinlang.org logo
u

ursus

12/11/2021, 4:30 AM
I'd like to share whole feature with ios app, Feature uses sqlite database, or rather adds table to the schema. I use sqldelight for that. Now, if the native sqlite driver uses the same database name, then it should add feature's tables to the existing database the ios app already used, right? However, is this safe in terms of threads, locks etc at runtime? Doesn't feel like it. There should probably be only one database connection. However I dont want to create a separate db, that wont scale well etc.
k

kpgalligan

12/12/2021, 12:39 AM
I'm going to set up a reminder to reply in detail tomorrow. Have thoughts, but not much time right now...
u

ursus

12/12/2021, 3:41 AM
thanks
a reminder 😀
k

kpgalligan

12/13/2021, 4:47 PM
There are multiple considerations here. sqldelight (and other db systems on Andriod) us a sqlite built-in version number to manage migrations. If you have 2 different systems talking the same db, there is a big risk that you won't update the db correctly. I don't know how else you're talking to the db, or if it cares about that version number. If not, this is less of a problem.
On single vs multiple connections, I'll assume you're using a WAL config. Your data should be fine as the db itself should prevent multiple threads from doing bad things. Where this may be a problem is if your db system expects to be talking to the db by itself. For example, sqldelight assumes it's the only thing talking to the db, so when starting a transaction, it doesn't think it'll need to wait for anybody else. You won't run into data problems so much, but I could see a scenario where the transaction connection times out waiting to be able to write. That's not something that's normally a problem, so we don't normally worry about it much. It may not be a problem, but something to look for.
So, version is an issue. If multiple connections are talking to the db, I think you'll be OK with WAL. The only thing I'd worry about is timing out, which may not actually be a problem anyway. If you're using a different non-WAL config, it may be a different story.
u

ursus

12/14/2021, 3:46 AM
I never set anything explicitly so I assume its wal. Okay so, best course of action is to just share dao interfaces until whole ios app backend is taken over by kmm?