Convert query return type when using flows #2782
-
I want to use SQLDelight as a caching layer in my App with the coroutines extension to return a flow from my SQL queries and get notified when the entry in the local Database changes. Below you can find an extract of my // SQLDelight queries
CREATE TABLE FriendEntity (
id TEXT NOT NULL PRIMARY KEY,
username TEXT NOT NULL,
firstname TEXT NOT NULL,
lastname TEXT,
phone TEXT,
picture TEXT,
accepted INTEGER AS Boolean DEFAULT 0 NOT NULL
getFriendById:
SELECT * FROM FriendEntity
WHERE id = :id;
); Below I want to create a caching service which also emits a override fun get(id: String): Flow<Friend>? {
return try {
return queries.getFriendById(id = id).asFlow() //returns Flow<Query<FriendEntity>>
} catch (e: NullPointerException) {
null
}
}
data class Friend(
var profile: Profile,
var accepted: Boolean
)
data class Profile(
var id: String,
var username: String,
var firstname: String,
var lastname: String?,
var phone: String? = null,
var picture: String? = null,
) Generated By SQLDelight:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
yes, you need to use the custom mapper parameter API:
|
Beta Was this translation helpful? Give feedback.
yes, you need to use the custom mapper parameter API: