Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a column for a list of items in Room

I want to update a specific column against a list of items/rows in a table. 1 way is to apply a loop on the update method, but is there any way to pass list of items and update that column for all, instead of doing it in loop?

Dao method:

   @Query("UPDATE items SET is_processing=1 WHERE item_id=:id")
    public abstract void updateProcessingStatus(String id);

Current update code:

public void updateStatusOfList(List<Item> items)
{

   for(Item item:items)
   myDao.updateProcessingStatus(item);

}
like image 608
Usman Rana Avatar asked May 25 '18 11:05

Usman Rana


1 Answers

Just pass your list as a variable into the query:

@Query("UPDATE items SET is_processing=1 WHERE item_id in (:items) ")
public abstract void updateProcessingStatus(List<String> items);

You will probably need to create a String List from your Items list first.

like image 80
live-love Avatar answered Nov 17 '22 02:11

live-love