From c1476bd0752b8f7660292be4118b95796c822e2a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 15 Feb 2023 20:16:54 +0600 Subject: [PATCH] add ReadCRUDFromKeyValueRepo --- CHANGELOG.md | 4 ++++ .../repos/transforms/crud/Factories.kt | 10 ++++++++++ .../crud/ReadCRUDFromKeyValueRepo.kt | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/Factories.kt create mode 100644 repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/ReadCRUDFromKeyValueRepo.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 32104bdeab7..da1ec448987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.16.10 +* `Repos`: + * `Cache`: + * New transformer type: `ReadCRUDFromKeyValueRepo` + ## 0.16.9 * `Versions`: diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/Factories.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/Factories.kt new file mode 100644 index 00000000000..4bb02112cb8 --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/Factories.kt @@ -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 ReadKeyValueRepo.asReadCRUDRepo() = ReadCRUDFromKeyValueRepo(this) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/ReadCRUDFromKeyValueRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/ReadCRUDFromKeyValueRepo.kt new file mode 100644 index 00000000000..b158592bc26 --- /dev/null +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/transforms/crud/ReadCRUDFromKeyValueRepo.kt @@ -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( + protected open val original: ReadKeyValueRepo +) : ReadCRUDRepo { + override suspend fun contains(id: IdType): Boolean = original.contains(id) + + override suspend fun count(): Long = original.count() + + override suspend fun getByPagination(pagination: Pagination): PaginationResult = original.values(pagination) + + override suspend fun getIdsByPagination(pagination: Pagination): PaginationResult = original.keys(pagination) + + override suspend fun getById(id: IdType): RegisteredType? = original.get(id) +}