From the course: Building an Android App with Jetpack Libraries
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Define an SQLite database with Room - Android Tutorial
From the course: Building an Android App with Jetpack Libraries
Define an SQLite database with Room
- After you create your entity classes, your DAO interfaces, and any required type converters. You're ready to create your Room Database definition. I'll create a new Kotlin class in my data package and I'll name it, Appdatabase. This could be any name you like. This class will extend a class named Roomdatabase, and it's a class. So I'll put in the parentheses at the end. This class also has to be abstract. It's up to the room library to generate the concrete class that you'll use at runtime. I also need to mark this class with a couple of annotations. I'll start with the database annotation, and I'll use the entities property to indicate which entities are part of the database structure. This is a common delimited list that goes between a couple of square brackets. I only have one entity, note entity and I'll pass in note entity, colon, colon class. Next, I need to indicate the version number for this database structure.…
Contents
-
-
-
-
-
-
Turn a data class into a Room entity3m 3s
-
Implement database operations in a DAO4m 7s
-
Create a custom type converter2m 14s
-
Define an SQLite database with Room4m 31s
-
Create a unit test for database logic5m 11s
-
Challenge: Add another unit test for database logic1m 27s
-
Solution: Add another unit test for database logic3m 3s
-
-
-
-