Search code examples
javaandroidsqlandroid-room

Android Room @Delete with parameters


I know I can't use DELETE in a query (that 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?


Solution

  • The beauty of room is, we play with the objects. As per requirement you can use for kotlin:

    @Delete
    fun delete(model: LanguageModel)
    

    for Java:

    @Delete
    void delete(LanguageModel model)
    

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