Search code examples
androidandroid-room

Update all column values to boolean in room android?


I have database table as

@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)

I want to update all the column values of isRead to true

I am using the following query but it isn't working.

@Query("UPDATE NotificationEntity SET is_read = 'true'")
suspend fun updateReadStatus()

Is it correct or not?


Solution

  • The boolean values are mapped to the integer internally. So you should use

    @Query("UPDATE NotificationEntity SET is_read = 1")