Skip to content

Convert query return type when using flows #2782

Answered by AlecKazakova
JonasHiltl asked this question in Q&A
Discussion options

You must be logged in to vote

yes, you need to use the custom mapper parameter API:

override fun get(id: String): Flow<Friend>? {
    return try {
        return queries.getFriendById(id = id, mapper = {
            id TEXT NOT NULL PRIMARY KEY,
            username,
            firstname,
            lastname,
            phone,
            picture,
            accepted -> Friend(
              Profile(
                id, username, firstname, lastname, phone, picture
              ), accepted
            )
        }).asFlow()
    } catch (e: NullPointerException) {
        null
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AlecKazakova
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants