Room Database: Getting Started

Covers loads of cool concepts in local data persistence, using the Room database on Android. Learn how to use Entities, Queries, Relations, Kotlin Coroutines, Type Converters, and database Migrations to develop a complex and wholesome app. By Filip Babić.

Leave a rating/review
Download materials
Save for later
Comments
Share

Learning path

This is part of the Android Data & Networking learning path. View path.

Who is this for?

Android developers looking to extend their app's functionality, by adding a way to persist data, using a local database.

Covered concepts

  • Room basics
  • Setting Up Room
  • Data Access Objects - DAOs
  • Queries
  • Entities
  • Primary keys
  • Relations
  • Embedded entities
  • One-to-one relations
  • One-to-many relations
  • Many-to-many relations
  • Complex queries
  • Query comparisons
  • Kotlin Coroutines
  • Room suspend functions
  • Room & Kotlin Flow
  • Complex Room types
  • TypeConverters
  • Gson parser
  • Room Migrations
  • Destructive migrations
  • Migrations between versions

Part 1: Set Up The Room Database

01
Toggle description

Learn what Room is, why it's useful to have local databases, and what you'll cover throughout this course.

Toggle description

Set up the project, take a look at the final application, and add needed dependencies for the app.

Toggle description

Create your first Room Entity, add it to a basic Room database, and learn about the Entity and PrimaryKey annotations.

Toggle description

Practice using Room entities by creating more entities for the project and adding them to the database.

Write DAOs 3:04
Toggle description

Learn what Data access objects are, how to implement them, and how to connect DAOs to Room.

Toggle description

Practice creating data access objects in a small challenge. Add remaining DAOs to the app, and connect them to the Room Database.

Toggle description

Learn how to abstract away the database behavior by implementing another layer of communication, through the Repository pattern.

Conclusion 1:30
Toggle description

Review all the concepts learned in the first part of the course, and prepare for the second part, where you'll implement queries.

Part 2: Make Queries

Toggle description

Learn more about data access objects and queries. Learn what kind of queries you can write, and what their implementation looks like.

Toggle description

Write your first few Queries, then learn how to fetch data from the database, and how to write queries to insert data.

Toggle description

Practice writing and using queries in a fun challenge! Finally insert data into the database, to pre-populate the database.

Toggle description

Learn how to write different types of queries to add more functionality to the app.

Toggle description

Practice writing more queries, to add even more functionality to the app, in a fun challenge!

Toggle description

After storing some data in the database, learn how to explore the database, using a third party database browser tool.

Conclusion 1:34
Toggle description

Review the concepts you covered in this part of the course, then find out what's up next!

Part 3: Define Entity Relationships

Toggle description

Learn what relationships are, and which types exist. Learn how to implement them, and about some examples of relationships.

Toggle description

Learn how to use the Embedded and Relation annotations, and how to create one-to-one relations between Books and Genres.

Toggle description

Extend your knowledge of relations to build a one-to-many relation between a genre and books by that genre.

Toggle description

Practice using relations, to implement another use case, and combine the Review and the Book entities into a single structure.

Conclusion 2:16
Toggle description

Review the concepts you've learned about relationships and combining multiple entities, and prepare for the next part.

Part 4: Use Coroutines With Room

Toggle description

Learn about Kotlin Coroutines, and the Flow API, and why it's important to avoid blocking the main thread.

Toggle description

Use the coroutines API to implement a few suspending function calls to the database, to offload the main thread.

Toggle description

Practice suspending functions with Room queries, to fetch data asynchronously.

Toggle description

Use the Kotlin Flow API to return a reactive stream from the database, and receive updates every time you add or remove an entry.

Toggle description

Practice using the Kotlin Flow API, and add more reactive streams to database queries, to receive updates from the database.

Conclusion 1:24
Toggle description

Wrap up this part of the course, by reviewing all the concepts you've learned about Kotlin Coroutines.

Part 5: Use Complex Types & Migrations

Toggle description

Learn about using complex types in Room with TypeConverters, and about migrating the database between different versions.

Toggle description

Learn what TypeConverters are, how to use them, and what their functions have to be written as.

Toggle description

Fix the problems with changed database schema, using a database migration. Learn what migrations are, and how to write them.

Learn how to store even more complex types of data, such as lists of objects. Migrate the database once more.

Toggle description

Practice using TypeConverters to store lists of data, implement a third migration for the database.

Conclusion 3:01
Toggle description

Congratulations on reaching the end of the course! Review all the concepts you've learned, and find out where to go next.

Up next

Android & Kotlin
Android Networking: Fundamentals
Learn about the the HTTP, JSON, REST and all the other cool and important abbreviations in the world of ne... more

Instructors

Contributors

Filip Babić

Instructor

Christine Sweigart

Editor

Adriana Kutenko

Illustrator

Over 300 content creators. Join our team.