协程
Flow
要将查询作为 Flow 使用,请依赖协程 (Coroutines) 扩展制品并使用其提供的扩展方法:
kotlin
kotlin {
sourceSets.commonMain.dependencies {
implementation("app.cash.sqldelight:coroutines-extensions:2.1.0")
}
}groovy
kotlin {
sourceSets.commonMain.dependencies {
implementation "app.cash.sqldelight:coroutines-extensions:2.1.0"
}
}kotlin
val players: Flow<List<HockeyPlayer>> =
playerQueries.selectAll()
.asFlow()
.mapToList(Dispatchers.IO)此 Flow 会发射查询结果,并且每当该查询对应的数据库发生变更时,都会发射新的结果。
