Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Room - Fails to order by date

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.

like image 828
Siegmeyer Avatar asked Apr 23 '18 13:04

Siegmeyer


1 Answers

Make it only as ORDER BY date DESC in your Query.

Like

@get:Query("SELECT * FROM my_table ORDER BY date DESC")
like image 104
Jay Rathod RJ Avatar answered Oct 12 '22 05:10

Jay Rathod RJ