is there a way to perform an operation within the DAO after getting the result from Room, something like
Copy code
@Query("SELECT mutualFriends FROM friends where userId = :userId")
fun getMutualFriends(userId: String): List<Friend> {
// do some further operation with list
// like filter or some other
}
k
Kiprop Victor
12/08/2021, 5:00 AM
Yes you can, but would suggest to alleviate these effects to a repository to do actions like filter or map the list.
m
ms
12/08/2021, 8:10 AM
@Kiprop Victor how can I access the list from given Query in the function body?
k
Kiprop Victor
12/08/2021, 8:26 AM
It won't be direct. You will need two functions: 1
Copy code
@Query("SELECT mutualFriends FROM friends where userId = :userId")
fun getMutualFriends(userId: String): List<Friend>
Then 2:
Copy code
fun getFilteredMutualFriends(userId: String): List<Friend> = getMutualFriends().filter{}
These will be in your dao. But, as earlier suggested, the second would be an operation you would do in the repo.
m
ms
12/08/2021, 5:11 PM
currently handling using 2 methods as you mentioned. I thought that there might be a way to achieve using 1 method
no issues