Created
May 4, 2018 13:32
-
-
Save NikolayKul/3a091ba50e6f10d3f396ef53aeaf7c74 to your computer and use it in GitHub Desktop.
Android Room @TypeConverter example in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Singleton that contains all `@TypeConverter`s of the app. | |
Mark all inner converters with `@JvmStatic` so Room can use them as regular static functions | |
*/ | |
object Converters { | |
@TypeConverter | |
@JvmStatic | |
fun convertDateFrom(value: Date?): Long? = value?.time | |
@TypeConverter | |
@JvmStatic | |
fun convertDateTo(value: Long?): Date? = value?.let(::Date) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = [DummyEntity::class], version = 1) | |
@TypeConverters(Converters::class) | |
abstract class DummyDatabase : RoomDatabase() { | |
abstract fun dummyDao(): DummyDao | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where dao class ?