asObjectsFlow
Returns a Flow that maps the Query ResultSet to instances of a class that can be created using the given factory lambda.
Example of usage with kotlinx-serialization:
@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)
val users: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Parameters
optional CoroutineContext on which to run the change listener: default is the flow collector's CoroutineContext
the lambda used for creating object instances.
Returns a Flow that maps the Query ResultSet to instances of a class that can be created using the given factory lambda.
Example of usage with kotlinx-serialization:
@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)
val users: Flow<List<User>> = query.asObjectsFlow { json: String ->
Json.decodeFromString<User>(json)
}
Parameters
the lambda used for creating object instances.
Returns a Flow that maps the Query ResultSet to instances of a class that can be created using the given factory lambda.
Example of usage:
class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}
val users: Flow<List<User>> = query.asObjectsFlow(::User)
Using Kotlin Map delegation for creating such instances is a great shorthand.
Parameters
optional CoroutineContext on which to run the change listener: default is the flow collector's CoroutineContext
the lambda used for creating object instances.
Returns a Flow that maps the Query ResultSet to instances of a class that can be created using the given factory lambda.
Example of usage:
class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}
val users: Flow<List<User>> = query.asObjectsFlow(::User)
Using Kotlin Map delegation for creating such instances is a great shorthand.
Parameters
the lambda used for creating object instances.