mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-16 13:23:49 +00:00
commit
1efd94181d
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.4.1
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* Fixed error in `ExposedKeyValueRepo` related to negative size of shared flow
|
||||||
|
* Fixed error in `ExposedKeyValueRepo` related to avoiding of table initiation
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
* `Repos`:
|
* `Repos`:
|
||||||
|
@ -41,5 +41,5 @@ dokka_version=1.4.0
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.4.0
|
version=0.4.1
|
||||||
android_code_version=4
|
android_code_version=5
|
||||||
|
@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
|
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
|
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
@ -18,8 +19,8 @@ open class ExposedKeyValueRepo<Key, Value>(
|
|||||||
valueColumnAllocator,
|
valueColumnAllocator,
|
||||||
tableName
|
tableName
|
||||||
) {
|
) {
|
||||||
private val _onNewValue = MutableSharedFlow<Pair<Key, Value>>(Channel.BUFFERED)
|
private val _onNewValue = MutableSharedFlow<Pair<Key, Value>>()
|
||||||
private val _onValueRemoved = MutableSharedFlow<Key>(Channel.BUFFERED)
|
private val _onValueRemoved = MutableSharedFlow<Key>()
|
||||||
|
|
||||||
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
|
||||||
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()
|
||||||
|
@ -2,8 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.pagination.*
|
import dev.inmo.micro_utils.pagination.*
|
||||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.*
|
||||||
import dev.inmo.micro_utils.repos.exposed.ExposedRepo
|
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
@ -17,6 +16,8 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
||||||
|
|
||||||
|
init { initTable() }
|
||||||
|
|
||||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||||
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
||||||
}
|
}
|
||||||
@ -33,8 +34,8 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
}
|
}
|
||||||
}.createPaginationResult(pagination, count())
|
}.createPaginationResult(pagination, count())
|
||||||
|
|
||||||
override suspend fun keys(value: Value, pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
|
override suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
|
||||||
select { valueColumn.eq(value) }.let {
|
select { valueColumn.eq(v) }.let {
|
||||||
it.count() to it.paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
it.count() to it.paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
||||||
it[keyColumn]
|
it[keyColumn]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user