Delete Or update query- room . android

42 views Asked by At

This is My Code :

 @Delete
    fun deleteItemFfromCart(model: CartTable)


    @Query("UPDATE CART SET amount = amount-1  WHERE id = :id")
    fun updateForDelete(id: Int) : Int


    @Transaction
    fun deleteOrupdat(model: CartTable) {

        val id = model.id?.let { updateForDelete(it) }

        if (id == -1) {

            deleteItemFfromCart(model)


        }
    }

I need a update or delete query for this case : 5 items is selected and there is a button for decrease this items , each button that will be pressed the update query execute and the amount minus by one and if the items getting to 0 the delete query execute and delete the row from table . I write above code but not work well . any idea whats worng with this code ?

thank's in advanced .

0

There are 0 answers