androidsqljodatimeandroid-roomandroid-jodatime

How to use Joda DateTime date as id in Room, or how to get date in query?


I need to write an app that uses date as id, and I must be able to update just by comparing date

@Entity
data class DailyCount(@PrimaryKey
                  var date:DateTime,
                  var summ: Double = 0.0)

And here is the DAO

@Query("update DailyCount set summ = :sum where date = :today")
fun updateCash(today: DateTime, sum: Double)

I want to make like this :

@Entity
data class DailyCount(@PrimaryKey
                  var date:Date,//JodaTime containing only date
                  var summ: Double = 0.0)

Or like this:

@Query("update DailyCount set summ = :sum where date.today = :dateArg.today")
fun updateCash(dateArg: DateTime, sum: Double)

Solution

  • I was needed to write this query :

    @Query("update DailyCount set summ = :sum where date between  :startTimeOfDay and :endTimeOfDay")
    fun updateCash(startTimeOfDay: DateTime, endTimeOfDay: DateTime, sum: Double)
    

    I gave here a range with start and end time. This approach returns true when I want to set info in today's Id