Skip to main content

Posts

Showing posts with the label RoomDB

Implementing a Simple Room Database in Android

What is Room Persistence Library? Room is a library built on top of SQLite that provides a more convenient and structured way to manage your Android app's local database,lets you work with your data as Kotlin objects (data classes) instead of writing raw SQL queries this simplifies database interactions and also checks your SQL queries at compile time. This helps us to catch errors early in the development cycle. so kets get started. Dependencies dependencies { // Room implementation("androidx.room:room-runtime:2.5.0") implementation("androidx.room:room-ktx:2.5.0") kapt("androidx.room:room-compiler:2.5.0") } Key Components Entity @Entity(tableName = "word_table") data class Word( @PrimaryKey val word: String ) Entity is a Kotlin data class representing a single table in the database,each property of the class corresponds to a column in the table and each entity is annotates with