Using Room in Jetpack Compose

Aseem Wangoo
Level Up Coding
Published in
5 min readMay 2, 2021

--

Using Room in Jetpack Compose

Article here: https://flatteredwithflutter.com/using-room-in-jetpack-compose/

Introduction

Level: Beginner

We will cover briefly:

  1. Using Room in Jetpack Compose
  2. Writing CRUD operations
  3. Write Test for Database

Note: This article assumes the reader knows about Jetpack Compose

Using Room in Jetpack Compose

Using Room in Jetpack Compose

What is Room?

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.

Room in Jetpack

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:

--

--