Merge pull request #311 from InsanusMokrassar/0.20.6

0.20.6
This commit is contained in:
InsanusMokrassar 2023-09-08 04:20:58 +06:00 committed by GitHub
commit 1a3913b09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.20.6
* `Repos`:
* `Exposed`
* Fixes in exposed key-values repos
## 0.20.5 ## 0.20.5
* `Coroutines`: * `Coroutines`:

View File

@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.20.5 version=0.20.6
android_code_version=211 android_code_version=212

View File

@ -1,12 +1,10 @@
package dev.inmo.micro_utils.repos.exposed.onetomany package dev.inmo.micro_utils.repos.exposed.onetomany
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
import dev.inmo.micro_utils.repos.exposed.* import dev.inmo.micro_utils.repos.exposed.*
import dev.inmo.micro_utils.repos.exposed.utils.selectPaginated import dev.inmo.micro_utils.repos.exposed.utils.selectPaginated
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
abstract class AbstractExposedReadKeyValuesRepo<Key, Value>( abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
@ -73,4 +71,26 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) { override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) {
select { selectById(k).and(selectByValue(v)) }.limit(1).any() select { selectById(k).and(selectByValue(v)) }.limit(1).any()
} }
override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> = transaction(database) {
val query = if (reverseLists) {
selectAll().orderBy(keyColumn, SortOrder.DESC)
} else {
selectAll()
}
query.asSequence().map { it.asKey to it.asObject }.groupBy { it.first }.mapValues {
it.value.map { it.second }
}
}
override suspend fun getAll(k: Key, reverseLists: Boolean): List<Value> = transaction(database) {
val query = if (reverseLists) {
select { selectById(k) }.orderBy(keyColumn, SortOrder.DESC)
} else {
select { selectById(k) }
}
query.map {
it.asObject
}
}
} }