I'm trying to have a small Android app have its own database, my first take on this was to simply use the Room persistence library, and it worked wonders, it's an awesome library but...
Later on I decided to try something weird and port that app to Desktop too (JVM).
My plan was to have 3 gradle modules:
- common logic
- android (importing common)
- jvm (importing common)
Problem is that... I can't use Room anymore since it would be in the common logic module that's not an android module.
I tried to switch to Ktorm, and it seemed nice but Ktorm can't create tables from the schema so i had to drop it.
Then i tried to switch to Exposed since it has the functionality to create tables from the schema, but Exposed has a few problems:
- The JDBC driver for Desktop (xerial) is not supported on android, so i should use different drivers per platform (for example using SQLDroid for android)
- Its DAO can't have a table with a composite key (which i need to have), and not having the DAO would make everything harder in the code since I'd have to issue the queries directly and get a ResultRow, and then convert them to the objects I need.
My last resort would be creating some monstruous class that totally hide the database providing only the minimum read and write methods that i need and has some sort of flag called android and totally change what its methods do if that flag is true or false, so that it would use Room on Android and Exposed on JVM, but it sounds like a terrible idea.
Some idea of how would it be possible to create and use a simple SQLite database in both JVM and Android with the same code?
UPDATE: I'm now using SQLDelight and even though it's not as comfy as Room and its documentation isn't super extensive, it's pretty nice and does what i wanted, figured out writing this could be useful for someone that come across my same doubt.
question from:https://stackoverflow.com/questions/65844081/android-jvm-sqlite-database