房间Rxjava Single作为删除响应

LeD*_*Don 2 android android-room

我正面临房间库中编译时错误的一些问题.

我正在使用版本:2.1.0-alpha02

以下Dao导致错误:

@Dao()
public interface WorkoutExerciseDao {

    [......]
    @Update()
    Single<Integer> updateWorkout(final WorkoutExercise... workoutExercises);


    @Delete
    Single<Integer> deleteWorkouts(final WorkoutExercise... user);

    @Query("DELETE FROM workout_exercise_table WHERE id  IN(:exerciseIds)")
    Single<Integer> deleteWorkouts(final long... exerciseIds);
}
Run Code Online (Sandbox Code Playgroud)

目前,第一个@Delete带注释的方法编译正常并按预期工作.如果我添加第二个(在查询方法中删除),它会中断编译并出现错误:

删除方法必须返回void或return int(删除的行数).

我在这里想念一下吗?

小智 5

你是对的我有这个问题.我不知道原因,但我知道在最新版本的空间中没有办法处理这个问题,当你使用查询时,DELETE返回类型必须是void或int但是如果你想RX用于DELETE查询你可以做这可能不是最好的方法:首先转换interfaceabstract class和所有方法abstract method然后

@Dao
public abstract class WorkoutExerciseDao {

    @Update()
    abstract Single<Integer> updateWorkout(final WorkoutExercise... workoutExercises);

    @Delete
    abstract Single<Integer> deleteWorkouts(final WorkoutExercise... user);

    @Query("DELETE FROM workout_exercise_table WHERE id  IN(:exerciseIds)")
    abstract Integer deleteWorkouts(final long... exerciseIds);

    Single<Integer> deleteWorkoutsById(final long... exerciseIds) {
        return Single.create(emitter -> {
            emitter.onSuccess(deleteWorkouts(exerciseIds));
        });
    }
}
Run Code Online (Sandbox Code Playgroud)