Android Room @Delete 带参数
问题描述:
我知道我不能在查询中使用 DELETE
(顺便说一句,这是一种耻辱),我会得到以下错误:
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>
但是我不能使用 @Delete(WHERE... xxx)
那么如何通过参数删除特定行呢?
But I can't use @Delete(WHERE... xxx)
So how do I delete a specific row by a parameter?
答
房间的美妙之处在于,我们可以玩弄物体.根据要求,您可以使用对于科特林:
The beauty of room is, we play with the objects. As per requirement you can use for kotlin:
@Delete
fun delete(model: LanguageModel)
对于 Java:
@Delete
void delete(LanguageModel model)
它将删除存储在具有相同值的数据库中的确切对象.LanguageModel 是我的模型类,它运行良好.
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.