I want to know that how can i sum value in the room database .
Let say i have insert this value (10,000) in the room database and i want to insert new value to database (20,000) and i want the new value to be sum with old value not replace it .
how can i do that .?
example of code :
Database Table :
@entity
class sum (
id : int ,
value : Long )
Dao :
@insert (onConflict = OnConflictStrategy.REPLACE)
suspend fun insert (model :sum)
what shoud i use instead of above insert .
@Query("SELECT * FROM sum")
fun getall () : LiveData<sum>
and in activity :
late init var : viewmodel : Viewmodeldatabase
val textvalue : TextView
viewmodel = Viewmodelprovider(this).get(Viewmodeldatabase::class.java)
textvalue = findvidwbyid(R.id.text)
viewmodel.insert(sum(1 , 10000)
// when the above value insert , if there is an old value sum with it and not replace it or remove it
viewmodel.getall.observe(this , Observer {
textvalue.text = it.value
)}
thank's guys for watch my code and help me .