不确定如何在 Room Android 中将 Cursor 转换为此方法的 return 类型?
Not sure how to convert a Cursor to this method's return type in Room Android?
我在构建应用程序时遇到以下错误
Not sure how to convert a Cursor to this method's return type (kotlinx.coroutines.flow.Flow<? extends java.util.List<com.notification.NotificationEntity>>)
这是我的实体class
@Entity
internal data class NotificationEntity(
@PrimaryKey @ColumnInfo(name = "notification_id") val notificationId: String,
val title: String,
val body: String?,
@ColumnInfo(name = "is_actionable") val isActionable: Boolean,
@ColumnInfo(name = "created_at") val createdAt: Instant,
@ColumnInfo(name = "is_read") val isRead: Boolean = false)
这就是我的道Class
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
suspend fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
谁能帮忙看看这是什么问题?
当你声明 Dao 的函数时,returns Flow
该函数不应该是可暂停的。 Please see docs.
将您的代码更改为:
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
并为 Instant
类型添加 type converter,如果尚未添加,则在 NotificationEntity 中使用。
我在构建应用程序时遇到以下错误
Not sure how to convert a Cursor to this method's return type (kotlinx.coroutines.flow.Flow<? extends java.util.List<com.notification.NotificationEntity>>)
这是我的实体class
@Entity
internal data class NotificationEntity(
@PrimaryKey @ColumnInfo(name = "notification_id") val notificationId: String,
val title: String,
val body: String?,
@ColumnInfo(name = "is_actionable") val isActionable: Boolean,
@ColumnInfo(name = "created_at") val createdAt: Instant,
@ColumnInfo(name = "is_read") val isRead: Boolean = false)
这就是我的道Class
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
suspend fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
谁能帮忙看看这是什么问题?
当你声明 Dao 的函数时,returns Flow
该函数不应该是可暂停的。 Please see docs.
将您的代码更改为:
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
并为 Instant
类型添加 type converter,如果尚未添加,则在 NotificationEntity 中使用。