Android Room @Delete with options

I know that I can’t use DELETEin the request (this is a shame, by the way), I will get the following error:

<i>Error:error: Observable query return type (LiveData, Flowable etc) can only be used with SELECT queries that directly or indirectly (via @Relation, for example) access at least one table.</i>

But I can’t use. @Delete(WHERE... xxx) So, how do I delete a specific row by a parameter?

+4
source share
2 answers

The beauty of the room, we play with objects. Upon request, you can use for kotlin:

@Delete
fun delete(model: LanguageModel)

for Java:

@Delete
void delete(LanguageModel model)

it will delete the exact object that is stored in db with the same values. LanguageModel is my model class and it works great.

0
source

Actually, you can use @Query to do the deletion

  @Query("DELETE FROM users WHERE user_id = :userId")
  abstract void deleteByUserId(long userId);

Extracted from Query javadoc

UPDATE DELETE void int. int, value - , .

+8

Source: https://habr.com/ru/post/1689976/


All Articles