如何在 Android 房间中使用其属性条件从 sqlite 数据库中删除对象
How to delete an object from sqlite db with condition of his attribute in Android Room
如果属性 lessonId
与我的 db
中的对象之一匹配,我想从我的 SQLite db
中删除一行(对象)。
我正在使用 Room
.
我不知道应该输入哪个查询。
NotificationDao:
@Dao
interface NotificationDao {
@Query("SELECT * FROM notifications")
fun getNotifications(): Single<List<Notification>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun updateNotification(notification: Notification): Completable
@Query("DELETE")
fun clearNotification(notification: Notification): Completable
}
通知class:
@Entity(tableName = "notifications")
data class Notification(
@PrimaryKey
var lessonId: String = "",
var count: Int = 0)
您是否尝试过使用带条件的删除(但您必须更改参数的类型)?
@Query("DELETE FROM notifications WHERE lessonId = :lessonId")
fun clearNotification(lessonId: String): Completable
如果属性 lessonId
与我的 db
中的对象之一匹配,我想从我的 SQLite db
中删除一行(对象)。
我正在使用 Room
.
我不知道应该输入哪个查询。
NotificationDao:
@Dao
interface NotificationDao {
@Query("SELECT * FROM notifications")
fun getNotifications(): Single<List<Notification>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun updateNotification(notification: Notification): Completable
@Query("DELETE")
fun clearNotification(notification: Notification): Completable
}
通知class:
@Entity(tableName = "notifications")
data class Notification(
@PrimaryKey
var lessonId: String = "",
var count: Int = 0)
您是否尝试过使用带条件的删除(但您必须更改参数的类型)?
@Query("DELETE FROM notifications WHERE lessonId = :lessonId")
fun clearNotification(lessonId: String): Completable