0

打电话

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(entity: PostEntity): Flow<Long>
   
@Delete
fun deletePost(entity: PostEntity): Flow<Long>

返回编译错误

 Not sure how to handle insert method's return type.
    public abstract kotlinx.coroutines.flow.Flow<java.util.List<java.lang.Long>> insertFlow(@org.jetbrains.annotations.NotNull()

不能使用带有 Int 或 long 的 Flow 来获取 RxJava 中数据库操作结果的 id 吗?

@Insert(onConflict = REPLACE)
fun insert(entity: T): Maybe<Long>

@Insert(onConflict = REPLACE)
fun insert(entity: T): Single<Long>
4

1 回答 1

3

根据Room 中 Kotlin 协程的异步查询,Kotlin 协程中Maybe的和等价Singlesuspend

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(entity: PostEntity): Long

@Delete
suspend fun deletePost(entity: PostEntity): Long
于 2020-08-07T20:04:08.467 回答