My model fragment:
@NonNull
@ColumnInfo(name = "date")
@TypeConverters(TimestampConverter::class)
var date: Date? = null
My converter:
class TimestampConverter {
@TypeConverter
fun fromTimestamp(value: Long?): Date? {
return if (value == null) null else Date(value)
}
@TypeConverter
fun dateToTimestamp(date: Date?): Long? {
return date?.time
}
}
My query:
@get:Query("SELECT * FROM my_table ORDER BY date(date) DESC")
val all: LiveData<List<MyModel>>
Any ideas why Room is not sorting my data? Thanks.
Make it only as ORDER BY date DESC
in your Query.
Like
@get:Query("SELECT * FROM my_table ORDER BY date DESC")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With