mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-29 13:38:45 +00:00
add extensions for onetomany functions
This commit is contained in:
parent
6115c1bcac
commit
9ece160aa8
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
## 0.2.2
|
## 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
|
## 0.2.1
|
||||||
|
|
||||||
* `Pagination`
|
* `Pagination`
|
||||||
|
@ -25,11 +25,11 @@ interface ReadOneToManyKeyValueRepo<Key, Value> : Repo {
|
|||||||
/**
|
/**
|
||||||
* WARNING!!! THIS METHOD PROBABLY IS NOT EFFICIENT, USE WITH CAUTION
|
* WARNING!!! THIS METHOD PROBABLY IS NOT EFFICIENT, USE WITH CAUTION
|
||||||
*/
|
*/
|
||||||
suspend fun getAll(): Map<Key, List<Value>> = mutableMapOf<Key, List<Value>>().also { map ->
|
suspend fun getAll(reverseLists: Boolean = false): Map<Key, List<Value>> = mutableMapOf<Key, List<Value>>().also { map ->
|
||||||
doWithPagination {
|
doWithPagination {
|
||||||
keys(it).also { paginationResult ->
|
keys(it).also { paginationResult ->
|
||||||
paginationResult.results.forEach { k ->
|
paginationResult.results.forEach { k ->
|
||||||
map[k] = getAll(k)
|
map[k] = getAll(k, reverseLists)
|
||||||
}
|
}
|
||||||
}.nextPageIfNotEmpty()
|
}.nextPageIfNotEmpty()
|
||||||
}
|
}
|
||||||
@ -62,4 +62,30 @@ interface WriteOneToManyKeyValueRepo<Key, Value> : Repo {
|
|||||||
@Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo"))
|
@Deprecated("Renamed", ReplaceWith("WriteOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.WriteOneToManyKeyValueRepo"))
|
||||||
typealias OneToManyWriteKeyValueRepo<Key, Value> = WriteOneToManyKeyValueRepo<Key, Value>
|
typealias OneToManyWriteKeyValueRepo<Key, Value> = WriteOneToManyKeyValueRepo<Key, Value>
|
||||||
|
|
||||||
interface OneToManyKeyValueRepo<Key, Value> : ReadOneToManyKeyValueRepo<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())
|
||||||
|
Loading…
Reference in New Issue
Block a user