room-kmp-setup

Installation
SKILL.md

Room in a multiplatform module

The database class, its entities and its DAOs live in commonMain. Only two things vary per platform: where the file goes and what the builder is handed. Both hide behind one expect:

// commonMain
@Database(entities = [...], version = <N>, exportSchema = true, autoMigrations = [...])
@TypeConverters(Converters::class)
abstract class MusicDatabase : RoomDatabase() {
    abstract fun getDatabaseDao(): DatabaseDao
}

expect fun getDatabaseBuilder(converters: Converters): RoomDatabase.Builder<MusicDatabase>

The driver and the query dispatcher are set once, at the shared injection site, so no platform can disagree about them:

Installs
2
GitHub Stars
35
First Seen
6 days ago
room-kmp-setup — maxrave-dev/kotlin-footguns