https://kotlinlang.org logo
i

Ivan

11/06/2020, 8:43 AM
Hi, there is any way to create kotrin coroutine flow from exposed query?
i

Ivan

11/08/2020, 2:46 PM
Hi @Bogdan, i know coroutines feature of exposed; But I meant how to create a flow using these features. I think I did it in this way:
Copy code
suspend fun Query.asFlowOnDb(
    database: Database,
    transactionIsolation: Int? = null
): Flow<ResultRow> {
    val q = this
    return channelFlow {
        val f = this
        newSuspendedTransaction (db = database,  transactionIsolation = transactionIsolation) {
            q.forEach { el -> f.send(el) }
        }
    }
}
@tapac Do u think there is another way to create flow with exposed or this method is ok?
5 Views