Home > Enterprise >  Updating room database by using Object
Updating room database by using Object

Time:11-09

I am using Room databse in android and I want to update it by using object.

I want to do this. Is it possible? `


@Query("UPDATE video_info_table SET videoStatus = :model.videoStatus WHERE id = :model.id")
fun delete(model: FileModelClass)

`

CodePudding user response:

No (not directly), you should use either:-

@Update
fun update(model: FileModelClass)
  • and obviously set ALL the fields/members correctly (as all fields bar the primary key, which is used for the where clause, will be updated)

OR

@Query("UPDATE video_info_table SET videoStatus = :videoStatus WHERE id = :id")
fun update(videoStatus: String, id: Long)
  • when calling then use thedao.update(theFileModelClass.videoStatus,theFileModel.id)

  • note that the types may have to be changed to suit the actual fields/members (e.g. perhaps Int instead of Long)

Of course you could have a wrapper for the second in the interface and thus yes to the question but indirectly, such as

fun update(model: FileModelClass) {
    update(model.videoStatus, model.id)
}

CodePudding user response:

You can try this

@Query("UPDATE video_info_table SET videoStatus =:status WHERE id = :id")
void update(String status, int id);
  • Related