调用
@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()
是否可以像 RxJava 一样使用 Flow 与 Int 或 long 来获取数据库操作结果的 id?
@Insert(onConflict = REPLACE)
fun insert(entity: T): Maybe<Long>
@Insert(onConflict = REPLACE)
fun insert(entity: T): Single<Long>
最佳答案
根据 Async queries with Kotlin coroutines in Room ,Kotlin 协程中 Maybe
和 Single
的等效项是 suspend
:
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(entity: PostEntity): Long
@Delete
suspend fun deletePost(entity: PostEntity): Long
关于android - 是否可以将 Flow 与 Room 删除或插入操作一起使用,就像在 RxJava 中使用 Single 或 Maybe 返回行 id 一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63308455/