add ReadCRUDFromKeyValueRepo

This commit is contained in:
InsanusMokrassar 2023-02-15 20:16:54 +06:00
parent 16c720fddd
commit c1476bd075
3 changed files with 34 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## 0.16.10
* `Repos`:
* `Cache`:
* New transformer type: `ReadCRUDFromKeyValueRepo`
## 0.16.9
* `Versions`:

View File

@ -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)

View File

@ -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)
}