Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

kotlin - Android/JVM SQLite database

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:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...