mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-26 18:47:17 +00:00
renames in keyvalue
This commit is contained in:
parent
22f5a59dfa
commit
8f522509c0
@ -22,6 +22,8 @@ Inited :)
|
||||
* `Common`
|
||||
* Interfaces related to `OneToManyKeyValueRepo` were renamed with convenience to `Read`/`Write` modifier before name
|
||||
* All subclasses were renamed
|
||||
* Interfaces related to `StandartKeyValueRepo` were renamed with convenience to `Read`/`Write` modifier before name
|
||||
* All subclasses were renamed
|
||||
* Extensions `doForAll` and `getAll` were added for all current types of repos:
|
||||
* `ReadStandardCRUDRepo`
|
||||
* `ReadStandardKeyValueRepo`
|
||||
|
@ -4,7 +4,7 @@ import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface StandardReadKeyValueRepo<Key, Value> : Repo {
|
||||
interface ReadStandardKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun get(k: Key): Value?
|
||||
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||
@ -12,7 +12,7 @@ interface StandardReadKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun count(): Long
|
||||
}
|
||||
|
||||
interface StandardWriteKeyValueRepo<Key, Value> : Repo {
|
||||
interface WriteStandardKeyValueRepo<Key, Value> : Repo {
|
||||
val onNewValue: Flow<Pair<Key, Value>>
|
||||
val onValueRemoved: Flow<Key>
|
||||
|
||||
@ -20,4 +20,4 @@ interface StandardWriteKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun unset(k: Key)
|
||||
}
|
||||
|
||||
interface StandardKeyValueRepo<Key, Value> : StandardReadKeyValueRepo<Key, Value>, StandardWriteKeyValueRepo<Key, Value>
|
||||
interface StandardKeyValueRepo<Key, Value> : ReadStandardKeyValueRepo<Key, Value>, WriteStandardKeyValueRepo<Key, Value>
|
@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.pagination
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
|
||||
block: (List<Pair<Key, Value>>) -> Unit
|
||||
@ -15,11 +15,11 @@ suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REP
|
||||
}
|
||||
}
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
block: (List<Pair<Key, Value>>) -> Unit
|
||||
) = doForAll({ keys(it, false) }, block)
|
||||
|
||||
suspend inline fun <Key, Value, REPO : StandardReadKeyValueRepo<Key, Value>> REPO.getAll(
|
||||
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.getAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
|
||||
): List<Pair<Key, Value>> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
@ -9,7 +9,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
protected val database: Database,
|
||||
protected val keyColumn: Column<Key>,
|
||||
protected val valueColumn: Column<Value>
|
||||
) : StandardReadKeyValueRepo<Key, Value>, Table() {
|
||||
) : ReadStandardKeyValueRepo<Key, Value>, Table() {
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
||||
|
||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||
|
@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class ReadMapKeyValueRepo<Key, Value>(
|
||||
private val map: Map<Key, Value> = emptyMap()
|
||||
) : StandardReadKeyValueRepo<Key, Value> {
|
||||
) : ReadStandardKeyValueRepo<Key, Value> {
|
||||
override suspend fun get(k: Key): Value? = map[k]
|
||||
|
||||
override suspend fun values(
|
||||
@ -47,7 +47,7 @@ class ReadMapKeyValueRepo<Key, Value>(
|
||||
|
||||
class WriteMapKeyValueRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, Value> = mutableMapOf()
|
||||
) : StandardWriteKeyValueRepo<Key, Value> {
|
||||
) : WriteStandardKeyValueRepo<Key, Value> {
|
||||
private val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>>
|
||||
get() = _onNewValue
|
||||
@ -68,7 +68,7 @@ class WriteMapKeyValueRepo<Key, Value>(
|
||||
class MapKeyValueRepo<Key, Value>(
|
||||
private val map: MutableMap<Key, Value> = mutableMapOf()
|
||||
) : StandardKeyValueRepo<Key, Value>,
|
||||
StandardReadKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map),
|
||||
StandardWriteKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map)
|
||||
ReadStandardKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map),
|
||||
WriteStandardKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map)
|
||||
|
||||
fun <K, V> MutableMap<K, V>.asKeyValueRepo(): StandardKeyValueRepo<K, V> = MapKeyValueRepo(this)
|
||||
|
@ -6,19 +6,19 @@ import dev.inmo.micro_utils.ktor.common.buildStandardUrl
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.asUrlQueryParts
|
||||
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.key_value.*
|
||||
import io.ktor.client.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
class KtorStandartReadKeyValueRepo<Key, Value> (
|
||||
class KtorReadStandardKeyValueRepo<Key, Value> (
|
||||
private var baseUrl: String,
|
||||
private var client: HttpClient = HttpClient(),
|
||||
private var keySerializer: KSerializer<Key>,
|
||||
private var valueSerializer: KSerializer<Value>,
|
||||
private var valueNullableSerializer: KSerializer<Value?>,
|
||||
) : StandardReadKeyValueRepo<Key, Value> {
|
||||
) : ReadStandardKeyValueRepo<Key, Value> {
|
||||
override suspend fun get(k: Key): Value? = client.uniget(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
@ -70,4 +70,7 @@ class KtorStandartReadKeyValueRepo<Key, Value> (
|
||||
),
|
||||
Long.serializer()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("KtorReadStandardKeyValueRepo", "dev.inmo.micro_utils.repos.ktor.client.key_value.KtorReadStandardKeyValueRepo"))
|
||||
typealias KtorStandartReadKeyValueRepo<Key, Value> = KtorReadStandardKeyValueRepo<Key, Value>
|
@ -1,8 +1,8 @@
|
||||
package dev.inmo.micro_utils.repos.ktor.client.key_value
|
||||
|
||||
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.StandardWriteKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo
|
||||
import io.ktor.client.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
@ -14,14 +14,14 @@ class KtorStandartKeyValueRepo<K, V> (
|
||||
valueSerializer: KSerializer<V>,
|
||||
valueNullableSerializer: KSerializer<V?>
|
||||
) : StandardKeyValueRepo<K, V>,
|
||||
StandardReadKeyValueRepo<K, V> by KtorStandartReadKeyValueRepo(
|
||||
ReadStandardKeyValueRepo<K, V> by KtorReadStandardKeyValueRepo(
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
valueNullableSerializer
|
||||
),
|
||||
StandardWriteKeyValueRepo<K, V> by KtorStandartWriteKeyValueRepo(
|
||||
WriteStandardKeyValueRepo<K, V> by KtorWriteStandardKeyValueRepo(
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
|
@ -4,7 +4,7 @@ import dev.inmo.micro_utils.ktor.client.BodyPair
|
||||
import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow
|
||||
import dev.inmo.micro_utils.ktor.client.unipost
|
||||
import dev.inmo.micro_utils.ktor.common.buildStandardUrl
|
||||
import dev.inmo.micro_utils.repos.StandardWriteKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.key_value.*
|
||||
import io.ktor.client.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -12,12 +12,12 @@ import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.PairSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
class KtorStandartWriteKeyValueRepo<K, V> (
|
||||
class KtorWriteStandardKeyValueRepo<K, V> (
|
||||
private var baseUrl: String,
|
||||
private var client: HttpClient = HttpClient(),
|
||||
private var keySerializer: KSerializer<K>,
|
||||
private var valueSerializer: KSerializer<V>,
|
||||
) : StandardWriteKeyValueRepo<K, V> {
|
||||
) : WriteStandardKeyValueRepo<K, V> {
|
||||
override val onNewValue: Flow<Pair<K, V>> = client.createStandardWebsocketFlow(
|
||||
buildStandardUrl(baseUrl, onNewValueRoute),
|
||||
deserializer = PairSerializer(keySerializer, valueSerializer)
|
||||
@ -45,4 +45,7 @@ class KtorStandartWriteKeyValueRepo<K, V> (
|
||||
BodyPair(keySerializer, k),
|
||||
Unit.serializer()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("KtorWriteStandardKeyValueRepo", "dev.inmo.micro_utils.repos.ktor.client.key_value.KtorWriteStandardKeyValueRepo"))
|
||||
typealias KtorStandartWriteKeyValueRepo<K, V> = KtorWriteStandardKeyValueRepo<K, V>
|
@ -4,7 +4,7 @@ import dev.inmo.micro_utils.ktor.server.decodeUrlQueryValueOrSendError
|
||||
import dev.inmo.micro_utils.ktor.server.unianswer
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.extractPagination
|
||||
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.key_value.*
|
||||
import io.ktor.application.*
|
||||
import io.ktor.routing.*
|
||||
@ -12,7 +12,7 @@ import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
fun <K, V> Route.configureReadStandartKeyValueRepoRoutes (
|
||||
originalRepo: StandardReadKeyValueRepo<K, V>,
|
||||
originalRepo: ReadStandardKeyValueRepo<K, V>,
|
||||
keySerializer: KSerializer<K>,
|
||||
valueSerializer: KSerializer<V>,
|
||||
valueNullableSerializer: KSerializer<V?>,
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.micro_utils.repos.ktor.server.key_value
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.includeWebsocketHandling
|
||||
import dev.inmo.micro_utils.ktor.server.uniload
|
||||
import dev.inmo.micro_utils.repos.StandardWriteKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.ktor.common.key_value.*
|
||||
import io.ktor.application.*
|
||||
import io.ktor.routing.*
|
||||
@ -10,7 +10,7 @@ import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.PairSerializer
|
||||
|
||||
fun <K, V> Route.configureWriteStandartKeyValueRepoRoutes (
|
||||
originalRepo: StandardWriteKeyValueRepo<K, V>,
|
||||
originalRepo: WriteStandardKeyValueRepo<K, V>,
|
||||
keySerializer: KSerializer<K>,
|
||||
valueSerializer: KSerializer<V>,
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user