asObjectsFlow

fun <T : Any> Query.asObjectsFlow(coroutineContext: CoroutineContext?, factory: (String) -> T?): Flow<List<T>>(source)

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

coroutineContext

optional CoroutineContext on which to run the change listener: default is the flow collector's CoroutineContext

factory

the lambda used for creating object instances.


fun <T : Any> Query.asObjectsFlow(factory: (String) -> T?): Flow<List<T>>(source)

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

factory

the lambda used for creating object instances.


fun <T : Any> Query.asObjectsFlow(coroutineContext: CoroutineContext?, factory: (Map<String, Any?>) -> T?): Flow<List<T>>(source)

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

coroutineContext

optional CoroutineContext on which to run the change listener: default is the flow collector's CoroutineContext

factory

the lambda used for creating object instances.


fun <T : Any> Query.asObjectsFlow(factory: (Map<String, Any?>) -> T?): Flow<List<T>>(source)

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

factory

the lambda used for creating object instances.