Anyone has experience building a common module wit...
# multiplatform
l
Anyone has experience building a common module with android and ios kotlin database implementations?
k
Do you have more detail here? Like the db’s are in their native platform, not in common (sqldelight)?
l
Well, on android I am already using Room, I just don't know if there's an equivalent on the ios side
k
Well, I wrote the sqldelight driver for native, and a few years ago I had Room running on iOS with j2objc, so I guess I can say I am experienced here. It’s not that there’s no equivalent. You can use core data, and I’d guess there are a handful of far less well known optinos on iOS, but regardless of what you use, you’ll need some kind of interface in common that you can talk to, that delegates to the platform implementatinos. I would seriously consider porting android to sqldelight, and then you avoid a whole bunch of pain. We just did this for a client project.
🤔 1
As a life hack, get DataGrip from Jetbrains, then point it at the db you have from room, and it can generate sql from that. That sql can be fed directly into sqldelight to make the tables.
plus1 4
h
The native equivalent on iOS would be CoreData, which provides an Objective-C api. But afaik you can't use Kotlin classes inheriting objective/C in swift. Also using a common db layer is much easier to maintain.
k
Yeah, like if the core data code already existed, I’d say maybe just write an interface that does everything you need from the calling code, then wire that on each platform. However, building the core data side from scratch, it just seems like time would be better spent moving the db code into common.
l
Hmmm actually on our common module, we haven't been using room. So I might be able to build the database using sqlite from the ground up
k
Hmmm actually on our common module, we haven’t been using room.
You can’t do that. You can use sqldelight, or maybe realm (not sql)
l
I mean on our android src repo inside the common module. We haven't been using any sort of database on our common module.
So it might be a good starting place to use sqldelight to share database functionalities from here on now
c
I have been using SQLDelight on both platforms and it has been working quite well. The
Flow
support in particular is great for updating view models