mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-29 21:48:45 +00:00
commit
cc18f58e4c
@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 0.2.2
|
||||
|
||||
* `Repos`
|
||||
* `Common`
|
||||
* Several new methods `ReadOneToManyKeyValueRepo#getAll`
|
||||
* Several new method `WriteOneToManyKeyValueRepo#add` and several extensions
|
||||
* Several new method `WriteOneToManyKeyValueRepo#remove` and several extensions
|
||||
|
||||
## 0.2.1
|
||||
|
||||
* `Pagination`
|
||||
|
@ -19,4 +19,4 @@ github_release_plugin_version=2.2.12
|
||||
uuidVersion=0.2.2
|
||||
|
||||
group=dev.inmo
|
||||
version=0.2.1
|
||||
version=0.2.2
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.inmo.micro_utils.repos
|
||||
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
@ -11,6 +10,30 @@ interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
suspend fun contains(k: Key, v: Value): Boolean
|
||||
suspend fun count(k: Key): Long
|
||||
suspend fun count(): Long
|
||||
|
||||
suspend fun getAll(k: Key, reversed: Boolean = false): List<Value> = mutableListOf<Value>().also { list ->
|
||||
doWithPagination {
|
||||
get(k, it).also {
|
||||
list.addAll(it.results)
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
if (reversed) {
|
||||
list.reverse()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING!!! THIS METHOD PROBABLY IS NOT EFFICIENT, USE WITH CAUTION
|
||||
*/
|
||||
suspend fun getAll(reverseLists: Boolean = false): Map<Key, List<Value>> = mutableMapOf<Key, List<Value>>().also { map ->
|
||||
doWithPagination {
|
||||
keys(it).also { paginationResult ->
|
||||
paginationResult.results.forEach { k ->
|
||||
map[k] = getAll(k, reverseLists)
|
||||
}
|
||||
}.nextPageIfNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
@Deprecated("Renamed", ReplaceWith("ReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo"))
|
||||
typealias OneToManyReadKeyValueRepo<Key, Value> = ReadOneToManyKeyValueRepo<Key, Value>
|
||||
@ -20,11 +43,51 @@ interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
|
||||
val onValueRemoved: Flow<Pair<Key, Value>>
|
||||
val onDataCleared: Flow<Key>
|
||||
|
||||
suspend fun add(toAdd: Map<Key, List<Value>>) = toAdd.forEach { (k, values) ->
|
||||
values.forEach { v ->
|
||||
add(k, v)
|
||||
}
|
||||
}
|
||||
@Deprecated("Will be extracted as extension for other add method")
|
||||
suspend fun add(k: Key, v: Value)
|
||||
|
||||
suspend fun remove(toRemove: Map<Key, List<Value>>) = toRemove.forEach { (k, values) ->
|
||||
values.forEach { v ->
|
||||
remove(k, v)
|
||||
}
|
||||
}
|
||||
@Deprecated("Will be extracted as extension for other remove method")
|
||||
suspend fun remove(k: Key, v: Value)
|
||||
|
||||
suspend fun clear(k: Key)
|
||||
}
|
||||
@Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo"))
|
||||
typealias OneToManyWriteKeyValueRepo<Key, Value> = WriteOneToManyKeyValueRepo<Key, Value>
|
||||
|
||||
interface OneToManyKeyValueRepo<Key, Value> : ReadOneToManyKeyValueRepo<Key, Value>, WriteOneToManyKeyValueRepo<Key, Value>
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.add(
|
||||
k: Key,
|
||||
vararg v: Value
|
||||
) = add(mapOf(k to v.toList()))
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.add(
|
||||
keysAndValues: List<Pair<Key, List<Value>>>
|
||||
) = add(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.add(
|
||||
vararg keysAndValues: Pair<Key, List<Value>>
|
||||
) = add(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.remove(
|
||||
k: Key,
|
||||
vararg v: Value
|
||||
) = remove(mapOf(k to v.toList()))
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.remove(
|
||||
keysAndValues: List<Pair<Key, List<Value>>>
|
||||
) = remove(keysAndValues.toMap())
|
||||
|
||||
suspend inline fun <Key, Value, REPO : WriteOneToManyKeyValueRepo<Key, Value>> REPO.remove(
|
||||
vararg keysAndValues: Pair<Key, List<Value>>
|
||||
) = remove(keysAndValues.toMap())
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
|
||||
suspend inline fun <Key, Value, REPO : ReadStandardKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.pagination
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
|
||||
suspend inline fun <Key, Value, REPO : ReadOneToManyKeyValueRepo<Key, Value>> REPO.doForAll(
|
||||
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||
|
Loading…
Reference in New Issue
Block a user