Home > other >  UPDATE query methods must either return void or int (the number of updated rows) while trying to ret
UPDATE query methods must either return void or int (the number of updated rows) while trying to ret

Time:08-25

Koltin version : 1.6.21.

Room dependencies :

implementation "androidx.room:room-runtime:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"
implementation "androidx.room:room-rxjava2:2.4.2"
testImplementation "androidx.room:room-testing:2.4.2"

Here is the query method :

@Query("UPDATE releve SET accuracy_indicator = :isEnabled WHERE id_local = :releveId")
    fun updateAccuracyIndicator(releveId: Long, isEnabled: Boolean): Flow<Int>

I don't know how to handle this issue ?

CodePudding user response:

An update operation is a one-shot so it should return a single Int rather than a flow of Ints. You can make the return type Int, and you can optionally mark the function suspend so it won’t block the caller.

  • Related