'How to write a SQLite query for android room database

What my User class looks like

  @Parcelize
    @Entity(tableName = "user_table")
    data class User(
        @PrimaryKey(autoGenerate = true)
        val id: Int,
        var name: String,
        var highScore: String?,
        var activeUser: Boolean,
    ): Parcelable

What my UserDao looks like

@Dao
interface UserDao {


    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun addUser(user: User)

    @Update
    suspend fun updateUser(user: User)

    @Delete
    suspend fun deleteUser(user: User)

    @Query("DELETE FROM user_table")
    suspend fun deleteAllUsers()

    @Query("SELECT * FROM user_table ORDER BY id ASC")
    fun readAllData(): LiveData<List<User>>

    @Query("UPDATE user_table SET activeUser = 0")
    fun updateAllActiveUsers()

    @Update
    fun updateActiveUser(user: User)

}

Hi, I want to know how do I write a query that will select all active user that are true. so only activeUser = 1



Solution 1:[1]

SELECT * FROM user_table WHERE activeUser = true

Or if doing a suspend function and want to pass the Boolean

SELECT * FROM user_table WHERE activeUser = :value
suspend fun getUsers(value: Boolean): T

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Papa Yev