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ć.
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
Learn what Room is, why it's useful to have local databases, and what you'll cover throughout this course.
Set up the project, take a look at the final application, and add needed dependencies for the app.
Create your first Room Entity, add it to a basic Room database, and learn about the Entity and PrimaryKey annotations.
Practice using Room entities by creating more entities for the project and adding them to the database.
Learn what Data access objects are, how to implement them, and how to connect DAOs to Room.
Practice creating data access objects in a small challenge. Add remaining DAOs to the app, and connect them to the Room Database.
Learn how to abstract away the database behavior by implementing another layer of communication, through the Repository pattern.
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
Learn more about data access objects and queries. Learn what kind of queries you can write, and what their implementation looks like.
Write your first few Queries, then learn how to fetch data from the database, and how to write queries to insert data.
Practice writing and using queries in a fun challenge! Finally insert data into the database, to pre-populate the database.
Learn how to write different types of queries to add more functionality to the app.
Practice writing more queries, to add even more functionality to the app, in a fun challenge!
After storing some data in the database, learn how to explore the database, using a third party database browser tool.
Review the concepts you covered in this part of the course, then find out what's up next!
Part 3: Define Entity Relationships
Learn what relationships are, and which types exist. Learn how to implement them, and about some examples of relationships.
Learn how to use the Embedded and Relation annotations, and how to create one-to-one relations between Books and Genres.
Extend your knowledge of relations to build a one-to-many relation between a genre and books by that genre.
Practice using relations, to implement another use case, and combine the Review and the Book entities into a single structure.
Review the concepts you've learned about relationships and combining multiple entities, and prepare for the next part.
Part 4: Use Coroutines With Room
Learn about Kotlin Coroutines, and the Flow API, and why it's important to avoid blocking the main thread.
Use the coroutines API to implement a few suspending function calls to the database, to offload the main thread.
Practice suspending functions with Room queries, to fetch data asynchronously.
Use the Kotlin Flow API to return a reactive stream from the database, and receive updates every time you add or remove an entry.
Practice using the Kotlin Flow API, and add more reactive streams to database queries, to receive updates from the database.
Wrap up this part of the course, by reviewing all the concepts you've learned about Kotlin Coroutines.
Part 5: Use Complex Types & Migrations
Learn about using complex types in Room with TypeConverters, and about migrating the database between different versions.
Learn what TypeConverters are, how to use them, and what their functions have to be written as.
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.
Practice using TypeConverters to store lists of data, implement a third migration for the database.
Congratulations on reaching the end of the course! Review all the concepts you've learned, and find out where to go next.