Room 234 has three building blocks. An entity is a class annotated @Entity; each instance is a row. A DAO (data access object) is an interface whose annotated functions become SQL. The database class lists the entities, carries the schema version, and hands out DAOs. BookNest's BookEntity repeats the fields of Book under @Entity(tableName = "books"), with @PrimaryKey val id: Int holding the server's id. A separate entity class keeps storage details (default values, the cache timestamp of Migrations) out of the UI's model; two one-line mappers, toBook() and toEntity(), convert between them. KSP implements the abstract database class:
@Database(entities = [BookEntity::class, NoteEntity::class], version = 2)
@ColumnTypeConverters(Converters::class)
abstract class BookNestDatabase : RoomDatabase() {
abstract fun bookDao(): BookDao
}
...
@Provides
@Singleton // one database object per process
fun provideDatabase(@ApplicationContext context: Context): BookNestDatabase =
Room.databaseBuilder<BookNestDatabase>(context, "booknest.db")
.setDriver(AndroidSQLiteDriver()) // the platform's own SQLite
.addMigrations(MIGRATION_1_2) // 5.25.4
.build()The dependencies are androidx.room3:room3-runtime 3.0.3, ksp(androidx.room3:room3-compiler), and androidx.sqlite:sqlite-framework 2.7.1 for AndroidSQLiteDriver (BundledSQLiteDriver ships its own SQLite 4,756 in the APK instead). The androidx.room3 Gradle 19,597 plugin exports each schema version as JSON for migration tests. Keep the database a @Singleton: two instances of one file break change tracking.