Complete the code to declare a suspend function for inserting a user in the DAO.
suspend fun insertUser(user: User) [1]The suspend function must have a body or delegate to another suspend function. Here, we use a function body placeholder.
Complete the DAO function to return all users as a Flow.
@Query("SELECT * FROM users") fun getAllUsers(): [1]
Using Flow> allows observing the database changes asynchronously with coroutines.
Fix the error in the suspend DAO function declaration for deleting a user.
suspend fun deleteUser(user: User) [1]The suspend function should have a function body calling the delete method. Using curly braces with the call is correct.
Fill both blanks to define a suspend function that updates a user in the DAO.
suspend fun updateUser(user: User) [1] update(user) [2]
The suspend function must have curly braces around the update call to define its body.
Fill all three blanks to create a DAO function that returns a Flow of users filtered by age.
@Query("SELECT * FROM users WHERE age [1] :minAge") fun getUsersOlderThan(minAge: Int): [2] = [3]
- >.
The query uses '>' to filter users older than minAge. The function returns a Flow of user lists, implemented by emitting all results from a query flow.