From the course: Building an Android App with Jetpack Libraries
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Create a custom type converter - Android Tutorial
From the course: Building an Android App with Jetpack Libraries
Create a custom type converter
- [Instructor] My notes table is going to have three columns. The integer and string values are simple values that can be handled by SQLite. That is those types match up with two of SQLite on native column types. But SQLite doesn't have a date type. So I have to convert date values to long integers and back again. So I can store them in my SQLite database. Broom handles this with classes called type converters. You create the converter class and then you register it with your database and Room takes care of everything else. So before I can create my database definition, I need to create a type converter for date values. I'll name this new Kotlin class date converter. The class itself doesn't get any special annotations. Instead you create functions to convert values and then mark those with Room annotation. I'll start with the room annotation type converter. Then I'll create a function named fromTimestamp. This function…
Contents
-
-
-
-
-
-
Turn a data class into a Room entity3m 3s
-
(Locked)
Implement database operations in a DAO4m 7s
-
(Locked)
Create a custom type converter2m 14s
-
(Locked)
Define an SQLite database with Room4m 31s
-
(Locked)
Create a unit test for database logic5m 11s
-
(Locked)
Challenge: Add another unit test for database logic1m 27s
-
(Locked)
Solution: Add another unit test for database logic3m 3s
-
-
-
-