refactor(db): Migrate last category queries (that can be migrated) to SQLDelight

This commit is contained in:
Ahmad Ansori Palembani 2024-11-29 12:08:17 +07:00
parent 663360c283
commit a4a7f8fb6d
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 4 additions and 6 deletions

View file

@ -18,8 +18,4 @@ interface CategoryQueries : DbProvider {
)
.prepare()
fun insertCategory(category: Category) = db.put().`object`(category).prepare()
fun insertCategories(categories: List<Category>) = db.put().objects(categories).prepare()
}

View file

@ -285,10 +285,12 @@ class LibraryPresenter(
}
}
private fun reorderCategories(categories: List<Category>) {
private suspend fun reorderCategories(categories: List<Category>) {
val sortedCategories = categories.sortedBy { it.order }
sortedCategories.forEachIndexed { i, category -> category.order = i }
db.insertCategories(sortedCategories).executeAsBlocking()
updateCategories.await(
sortedCategories.map { CategoryUpdate(id = it.id!!.toLong(), order = it.order.toLong()) }
)
}
fun switchSection(order: Int) {