mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-01-05 15:29:57 +00:00
add ReadCRUDFromKeyValueRepo
This commit is contained in:
parent
16c720fddd
commit
c1476bd075
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## 0.16.10
|
## 0.16.10
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Cache`:
|
||||||
|
* New transformer type: `ReadCRUDFromKeyValueRepo`
|
||||||
|
|
||||||
## 0.16.9
|
## 0.16.9
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.transforms.crud
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
|
||||||
|
import kotlin.js.JsName
|
||||||
|
import kotlin.jvm.JvmName
|
||||||
|
|
||||||
|
fun <K, V> ReadKeyValueRepo<K, V>.asReadCRUDRepo() = ReadCRUDFromKeyValueRepo(this)
|
@ -0,0 +1,20 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.transforms.crud
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
|
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||||
|
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
|
|
||||||
|
open class ReadCRUDFromKeyValueRepo<RegisteredType, IdType>(
|
||||||
|
protected open val original: ReadKeyValueRepo<IdType, RegisteredType>
|
||||||
|
) : ReadCRUDRepo<RegisteredType, IdType> {
|
||||||
|
override suspend fun contains(id: IdType): Boolean = original.contains(id)
|
||||||
|
|
||||||
|
override suspend fun count(): Long = original.count()
|
||||||
|
|
||||||
|
override suspend fun getByPagination(pagination: Pagination): PaginationResult<RegisteredType> = original.values(pagination)
|
||||||
|
|
||||||
|
override suspend fun getIdsByPagination(pagination: Pagination): PaginationResult<IdType> = original.keys(pagination)
|
||||||
|
|
||||||
|
override suspend fun getById(id: IdType): RegisteredType? = original.get(id)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user