Using Room in Jetpack Compose
Using Room in Jetpack Compose
Article here: https://flatteredwithflutter.com/using-room-in-jetpack-compose/
Introduction
Level: Beginner
We will cover briefly:
- Using Room in Jetpack Compose
- Writing CRUD operations
- Write Test for Database
Note: This article assumes the reader knows about Jetpack Compose
Using Room in Jetpack Compose
As per the documentation,
The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.
Setup Room in Compose
To use Room in your app, add the following dependencies to your app’s build.gradle
file:
dependencies {
def room_version = "2.2.6"
// FOR ROOM
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
// END FOR ROOM
}
Components of Room
There are 3 major components in the Room:
- The database class that holds the database.
- Data entities that represent tables in your app’s database.
- Data access objects (DAOs) provide methods that your app can use to query, update, insert, and delete data in the database.