|
|
@@ -3,11 +3,9 @@ package org.sirekanyan.outline.db
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
+import app.cash.sqldelight.Query
|
|
|
import app.cash.sqldelight.coroutines.asFlow
|
|
|
-import app.cash.sqldelight.coroutines.mapToList
|
|
|
-import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
-import kotlinx.coroutines.withContext
|
|
|
import org.sirekanyan.outline.app
|
|
|
import org.sirekanyan.outline.db.model.KeyEntity
|
|
|
import org.sirekanyan.outline.db.model.ServerEntity
|
|
|
@@ -22,15 +20,13 @@ class KeyDao(database: OutlineDatabase) {
|
|
|
|
|
|
private val queries = database.keyEntityQueries
|
|
|
|
|
|
- fun observe(server: ServerEntity): Flow<List<KeyEntity>> =
|
|
|
- queries.selectKeys(server.id).asFlow().mapToList(Dispatchers.IO)
|
|
|
+ fun observe(server: ServerEntity): Flow<Query<KeyEntity>> =
|
|
|
+ queries.selectKeys(server.id).asFlow()
|
|
|
|
|
|
- suspend fun update(server: ServerEntity, keys: List<KeyEntity>) {
|
|
|
- withContext(Dispatchers.IO) {
|
|
|
- queries.transaction {
|
|
|
- queries.deleteKeys(server.id)
|
|
|
- keys.forEach(queries::insertKey)
|
|
|
- }
|
|
|
+ fun update(server: ServerEntity, keys: List<KeyEntity>) {
|
|
|
+ queries.transaction {
|
|
|
+ queries.deleteKeys(server.id)
|
|
|
+ keys.forEach(queries::insertKey)
|
|
|
}
|
|
|
}
|
|
|
|