協同程式
Flow
若要將查詢作為 Flow 取用,請加入 Coroutines 擴充功能構件(artifact)的相依性,並使用其提供的擴充方法:
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 會發送查詢結果,並且每當該查詢相關的資料庫發生變更時,都會發送新的結果。
