Ktor how to use android room in server code?

i know how to use room in android dev, but don’t know how to do in ktor, or say in server code

You can’t, since ROOM is an ORM targeted only towards Android and Sqlite.

You can choose any other Java ORM: Hibernate, JOOQ, eBean, OrmLite etc. I personally used eBean, it’s straightforward to use.

teacher, how sure are you? android is also based on linux, and app have a process, i think it may be ok if some work, but i have no idea.
whether have ORM focused on kotlin, not java?

It’s not about what the OS it’ s based upon, it’s about Room using Android-specific libraries that are not available in a standard JVM.

If you want a pure Kotlin ORM I’d recommend Exposed, the entity and repository mapping is a bit verbose but I’ve used it in some professional projects and it never failed me.

Or as andob said, you can pretty much use any Java ORM, though you will probably need to use the kotlin-allopen plugin for a nice developer experience.

1 Like

Historically, ORMs on the JVM uses JDBC to handle connections to databases.

Now, while the JDK inside Android supports JDBCs and SQLite can be used used with it (with some hacks), there are many compatibility issues with SQLite drivers (a driver is an implementation of the JDBC interface java.sql.Driver) on Android since Android JDK has been customized for the needs of a mobile device.

The Android team decided to reimplement from scratch access to SQLite, apart from JDBC (which indeed is a very old mechanism).

Room is very tied to internal mechanisms of the customizations of the Android runtime and it is not usable outside of it.

Other ORM solutions that I like very much are Exposed (from the JetBrains team) and Ktorm.

Both solutions uses JDBC drivers but Exposed is starting to add some conveniences for coroutines, which are very handful for Ktor.

1 Like