Android Room throws error: Deletion methods must either return void or return int (the number of deleted rows)
Android Room throws error: Deletion methods must either return void or return int (the number of deleted rows)
我正在使用 Android 带 RxJava 的 Room
dependencies {
implementation 'androidx.room:room-rxjava2:2.1.0-alpha02'
}
我需要从参数化删除方法中获取 Completable,我认为这个功能是从 2.1.0 开始添加的?例如
@Query("DELETE FROM message_table WHERE uid = :id")
Completable delete(String id);
@Query("DELETE FROM message_table")
Completable deleteAll();
仍然抛出错误:Deletion methods must either return void or return int (the number of deleted rows).
正如错误消息试图告诉的那样:
使用 @Query
,您必须将返回的数据类型从 Completable
更改为 int
或 void
。
Completable
需要订阅另一个方法,该方法运行 Dao
的方法:
Completable
.fromAction(aMethodWhichCallsDao)
.subscribeOn(Schedulers.single())
.subscribe();
或使用 @Delete
注释,如@Commonsware 所建议的那样(以防它像宣传的那样工作)。
我不知道你是否还需要这个,但今天刚开始做同样的事情,发现你需要使用所有这 3 个库来创建 DAO 方法 return Completable:
implementation 'androidx.room:room-runtime:2.2.1'
kapt 'androidx.room:room-compiler:2.2.1'
implementation 'androidx.room:room-rxjava2:2.2.1'
希望对您有所帮助。
我正在使用 Android 带 RxJava 的 Room
dependencies {
implementation 'androidx.room:room-rxjava2:2.1.0-alpha02'
}
我需要从参数化删除方法中获取 Completable,我认为这个功能是从 2.1.0 开始添加的?例如
@Query("DELETE FROM message_table WHERE uid = :id")
Completable delete(String id);
@Query("DELETE FROM message_table")
Completable deleteAll();
仍然抛出错误:Deletion methods must either return void or return int (the number of deleted rows).
正如错误消息试图告诉的那样:
使用 @Query
,您必须将返回的数据类型从 Completable
更改为 int
或 void
。
Completable
需要订阅另一个方法,该方法运行 Dao
的方法:
Completable
.fromAction(aMethodWhichCallsDao)
.subscribeOn(Schedulers.single())
.subscribe();
或使用 @Delete
注释,如@Commonsware 所建议的那样(以防它像宣传的那样工作)。
我不知道你是否还需要这个,但今天刚开始做同样的事情,发现你需要使用所有这 3 个库来创建 DAO 方法 return Completable:
implementation 'androidx.room:room-runtime:2.2.1'
kapt 'androidx.room:room-compiler:2.2.1'
implementation 'androidx.room:room-rxjava2:2.2.1'
希望对您有所帮助。