renames in keyvalue

This commit is contained in:
InsanusMokrassar 2020-10-14 22:29:03 +06:00
parent 22f5a59dfa
commit 8f522509c0
10 changed files with 36 additions and 28 deletions

View File

@ -22,6 +22,8 @@ Inited :)
* `Common` * `Common`
* Interfaces related to `OneToManyKeyValueRepo` were renamed with convenience to `Read`/`Write` modifier before name * Interfaces related to `OneToManyKeyValueRepo` were renamed with convenience to `Read`/`Write` modifier before name
* All subclasses were renamed * 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: * Extensions `doForAll` and `getAll` were added for all current types of repos:
* `ReadStandardCRUDRepo` * `ReadStandardCRUDRepo`
* `ReadStandardKeyValueRepo` * `ReadStandardKeyValueRepo`

View File

@ -4,7 +4,7 @@ import dev.inmo.micro_utils.pagination.Pagination
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
interface StandardReadKeyValueRepo<Key, Value> : Repo { interface ReadStandardKeyValueRepo<Key, Value> : Repo {
suspend fun get(k: Key): Value? suspend fun get(k: Key): Value?
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value> suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key> suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
@ -12,7 +12,7 @@ interface StandardReadKeyValueRepo<Key, Value> : Repo {
suspend fun count(): Long suspend fun count(): Long
} }
interface StandardWriteKeyValueRepo<Key, Value> : Repo { interface WriteStandardKeyValueRepo<Key, Value> : Repo {
val onNewValue: Flow<Pair<Key, Value>> val onNewValue: Flow<Pair<Key, Value>>
val onValueRemoved: Flow<Key> val onValueRemoved: Flow<Key>
@ -20,4 +20,4 @@ interface StandardWriteKeyValueRepo<Key, Value> : Repo {
suspend fun unset(k: Key) 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>

View File

@ -3,7 +3,7 @@ package dev.inmo.micro_utils.repos.pagination
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.* 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") @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>, methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>,
block: (List<Pair<Key, Value>>) -> Unit 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 block: (List<Pair<Key, Value>>) -> Unit
) = doForAll({ keys(it, false) }, block) ) = 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") @Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key> methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
): List<Pair<Key, Value>> { ): List<Pair<Key, Value>> {

View File

@ -1,7 +1,7 @@
package dev.inmo.micro_utils.repos.exposed.keyvalue 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.StandardReadKeyValueRepo import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
@ -9,7 +9,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
protected val database: Database, protected val database: Database,
protected val keyColumn: Column<Key>, protected val keyColumn: Column<Key>,
protected val valueColumn: Column<Value> protected val valueColumn: Column<Value>
) : StandardReadKeyValueRepo<Key, Value>, Table() { ) : ReadStandardKeyValueRepo<Key, Value>, Table() {
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn) override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
override suspend fun get(k: Key): Value? = transaction(database) { override suspend fun get(k: Key): Value? = transaction(database) {

View File

@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow
class ReadMapKeyValueRepo<Key, Value>( class ReadMapKeyValueRepo<Key, Value>(
private val map: Map<Key, Value> = emptyMap() 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 get(k: Key): Value? = map[k]
override suspend fun values( override suspend fun values(
@ -47,7 +47,7 @@ class ReadMapKeyValueRepo<Key, Value>(
class WriteMapKeyValueRepo<Key, Value>( class WriteMapKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, Value> = mutableMapOf() private val map: MutableMap<Key, Value> = mutableMapOf()
) : StandardWriteKeyValueRepo<Key, Value> { ) : WriteStandardKeyValueRepo<Key, Value> {
private val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow() private val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
override val onNewValue: Flow<Pair<Key, Value>> override val onNewValue: Flow<Pair<Key, Value>>
get() = _onNewValue get() = _onNewValue
@ -68,7 +68,7 @@ class WriteMapKeyValueRepo<Key, Value>(
class MapKeyValueRepo<Key, Value>( class MapKeyValueRepo<Key, Value>(
private val map: MutableMap<Key, Value> = mutableMapOf() private val map: MutableMap<Key, Value> = mutableMapOf()
) : StandardKeyValueRepo<Key, Value>, ) : StandardKeyValueRepo<Key, Value>,
StandardReadKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map), ReadStandardKeyValueRepo<Key, Value> by ReadMapKeyValueRepo(map),
StandardWriteKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map) WriteStandardKeyValueRepo<Key, Value> by WriteMapKeyValueRepo(map)
fun <K, V> MutableMap<K, V>.asKeyValueRepo(): StandardKeyValueRepo<K, V> = MapKeyValueRepo(this) fun <K, V> MutableMap<K, V>.asKeyValueRepo(): StandardKeyValueRepo<K, V> = MapKeyValueRepo(this)

View File

@ -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.Pagination
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.asUrlQueryParts 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 dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.client.* import io.ktor.client.*
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
class KtorStandartReadKeyValueRepo<Key, Value> ( class KtorReadStandardKeyValueRepo<Key, Value> (
private var baseUrl: String, private var baseUrl: String,
private var client: HttpClient = HttpClient(), private var client: HttpClient = HttpClient(),
private var keySerializer: KSerializer<Key>, private var keySerializer: KSerializer<Key>,
private var valueSerializer: KSerializer<Value>, private var valueSerializer: KSerializer<Value>,
private var valueNullableSerializer: KSerializer<Value?>, private var valueNullableSerializer: KSerializer<Value?>,
) : StandardReadKeyValueRepo<Key, Value> { ) : ReadStandardKeyValueRepo<Key, Value> {
override suspend fun get(k: Key): Value? = client.uniget( override suspend fun get(k: Key): Value? = client.uniget(
buildStandardUrl( buildStandardUrl(
baseUrl, baseUrl,
@ -71,3 +71,6 @@ class KtorStandartReadKeyValueRepo<Key, Value> (
Long.serializer() Long.serializer()
) )
} }
@Deprecated("Renamed", ReplaceWith("KtorReadStandardKeyValueRepo", "dev.inmo.micro_utils.repos.ktor.client.key_value.KtorReadStandardKeyValueRepo"))
typealias KtorStandartReadKeyValueRepo<Key, Value> = KtorReadStandardKeyValueRepo<Key, Value>

View File

@ -1,8 +1,8 @@
package dev.inmo.micro_utils.repos.ktor.client.key_value package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.repos.StandardKeyValueRepo import dev.inmo.micro_utils.repos.StandardKeyValueRepo
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
import dev.inmo.micro_utils.repos.StandardWriteKeyValueRepo import dev.inmo.micro_utils.repos.WriteStandardKeyValueRepo
import io.ktor.client.* import io.ktor.client.*
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
@ -14,14 +14,14 @@ class KtorStandartKeyValueRepo<K, V> (
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?> valueNullableSerializer: KSerializer<V?>
) : StandardKeyValueRepo<K, V>, ) : StandardKeyValueRepo<K, V>,
StandardReadKeyValueRepo<K, V> by KtorStandartReadKeyValueRepo( ReadStandardKeyValueRepo<K, V> by KtorReadStandardKeyValueRepo(
"$baseUrl/$baseSubpart", "$baseUrl/$baseSubpart",
client, client,
keySerializer, keySerializer,
valueSerializer, valueSerializer,
valueNullableSerializer valueNullableSerializer
), ),
StandardWriteKeyValueRepo<K, V> by KtorStandartWriteKeyValueRepo( WriteStandardKeyValueRepo<K, V> by KtorWriteStandardKeyValueRepo(
"$baseUrl/$baseSubpart", "$baseUrl/$baseSubpart",
client, client,
keySerializer, keySerializer,

View File

@ -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.createStandardWebsocketFlow
import dev.inmo.micro_utils.ktor.client.unipost import dev.inmo.micro_utils.ktor.client.unipost
import dev.inmo.micro_utils.ktor.common.buildStandardUrl 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 dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.client.* import io.ktor.client.*
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -12,12 +12,12 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.PairSerializer import kotlinx.serialization.builtins.PairSerializer
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
class KtorStandartWriteKeyValueRepo<K, V> ( class KtorWriteStandardKeyValueRepo<K, V> (
private var baseUrl: String, private var baseUrl: String,
private var client: HttpClient = HttpClient(), private var client: HttpClient = HttpClient(),
private var keySerializer: KSerializer<K>, private var keySerializer: KSerializer<K>,
private var valueSerializer: KSerializer<V>, private var valueSerializer: KSerializer<V>,
) : StandardWriteKeyValueRepo<K, V> { ) : WriteStandardKeyValueRepo<K, V> {
override val onNewValue: Flow<Pair<K, V>> = client.createStandardWebsocketFlow( override val onNewValue: Flow<Pair<K, V>> = client.createStandardWebsocketFlow(
buildStandardUrl(baseUrl, onNewValueRoute), buildStandardUrl(baseUrl, onNewValueRoute),
deserializer = PairSerializer(keySerializer, valueSerializer) deserializer = PairSerializer(keySerializer, valueSerializer)
@ -46,3 +46,6 @@ class KtorStandartWriteKeyValueRepo<K, V> (
Unit.serializer() Unit.serializer()
) )
} }
@Deprecated("Renamed", ReplaceWith("KtorWriteStandardKeyValueRepo", "dev.inmo.micro_utils.repos.ktor.client.key_value.KtorWriteStandardKeyValueRepo"))
typealias KtorStandartWriteKeyValueRepo<K, V> = KtorWriteStandardKeyValueRepo<K, V>

View File

@ -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.ktor.server.unianswer
import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.extractPagination 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 dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.application.* import io.ktor.application.*
import io.ktor.routing.* import io.ktor.routing.*
@ -12,7 +12,7 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
fun <K, V> Route.configureReadStandartKeyValueRepoRoutes ( fun <K, V> Route.configureReadStandartKeyValueRepoRoutes (
originalRepo: StandardReadKeyValueRepo<K, V>, originalRepo: ReadStandardKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
valueNullableSerializer: KSerializer<V?>, valueNullableSerializer: KSerializer<V?>,

View File

@ -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.includeWebsocketHandling
import dev.inmo.micro_utils.ktor.server.uniload 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 dev.inmo.micro_utils.repos.ktor.common.key_value.*
import io.ktor.application.* import io.ktor.application.*
import io.ktor.routing.* import io.ktor.routing.*
@ -10,7 +10,7 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.PairSerializer import kotlinx.serialization.builtins.PairSerializer
fun <K, V> Route.configureWriteStandartKeyValueRepoRoutes ( fun <K, V> Route.configureWriteStandartKeyValueRepoRoutes (
originalRepo: StandardWriteKeyValueRepo<K, V>, originalRepo: WriteStandardKeyValueRepo<K, V>,
keySerializer: KSerializer<K>, keySerializer: KSerializer<K>,
valueSerializer: KSerializer<V>, valueSerializer: KSerializer<V>,
) { ) {