mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
impl common for repos
This commit is contained in:
parent
c6d0b0920e
commit
dbfe2f6661
16
repos/common/build.gradle
Normal file
16
repos/common/build.gradle
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppProjectWithSerializationPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api internalProject("micro_utils.pagination.common")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
|
||||||
|
fun generateId() = uuid4().toString()
|
@ -0,0 +1,23 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
|
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||||
|
|
||||||
|
interface OneToManyReadKeyValueRepo<Key, Value> : Repo {
|
||||||
|
suspend fun get(k: Key, pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||||
|
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||||
|
suspend fun contains(k: Key): Boolean
|
||||||
|
suspend fun contains(k: Key, v: Value): Boolean
|
||||||
|
suspend fun count(k: Key): Long
|
||||||
|
suspend fun count(): Long
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OneToManyWriteKeyValueRepo<Key, Value> :
|
||||||
|
Repo {
|
||||||
|
suspend fun add(k: Key, v: Value)
|
||||||
|
suspend fun remove(k: Key, v: Value)
|
||||||
|
suspend fun clear(k: Key)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OneToManyKeyValueRepo<Key, Value> : OneToManyReadKeyValueRepo<Key, Value>,
|
||||||
|
OneToManyWriteKeyValueRepo<Key, Value>
|
@ -0,0 +1,4 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
interface Repo {
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
|
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||||
|
|
||||||
|
interface ReadStandardCRUDRepo<ObjectType, IdType> : Repo {
|
||||||
|
suspend fun getByPagination(pagination: Pagination): PaginationResult<ObjectType>
|
||||||
|
suspend fun getById(id: IdType): ObjectType?
|
||||||
|
suspend fun contains(id: IdType): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias UpdatedValuePair<IdType, ValueType> = Pair<IdType, ValueType>
|
||||||
|
val <IdType> UpdatedValuePair<IdType, *>.id
|
||||||
|
get() = first
|
||||||
|
val <ValueType> UpdatedValuePair<*, ValueType>.value
|
||||||
|
get() = second
|
||||||
|
|
||||||
|
interface WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> : Repo {
|
||||||
|
val newObjectsFlow: Flow<ObjectType>
|
||||||
|
val updatedObjectsFlow: Flow<ObjectType>
|
||||||
|
val deletedObjectsIdsFlow: Flow<IdType>
|
||||||
|
|
||||||
|
suspend fun create(values: List<InputValueType>): List<ObjectType>
|
||||||
|
suspend fun update(id: IdType, value: InputValueType): ObjectType?
|
||||||
|
suspend fun update(values: List<UpdatedValuePair<IdType, InputValueType>>): List<ObjectType>
|
||||||
|
suspend fun deleteById(ids: List<IdType>)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.create(
|
||||||
|
vararg values: InputValueType
|
||||||
|
): List<ObjectType> = create(values.toList())
|
||||||
|
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.update(
|
||||||
|
vararg values: UpdatedValuePair<IdType, InputValueType>
|
||||||
|
): List<ObjectType> = update(values.toList())
|
||||||
|
suspend fun <ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>.deleteById(
|
||||||
|
vararg ids: IdType
|
||||||
|
) = deleteById(ids.toList())
|
||||||
|
|
||||||
|
interface StandardCRUDRepo<ObjectType, IdType, InputValueType> : ReadStandardCRUDRepo<ObjectType, IdType>,
|
||||||
|
WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>
|
@ -0,0 +1,23 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.Pagination
|
||||||
|
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||||
|
|
||||||
|
interface StandardReadKeyValueRepo<Key, Value> : Repo {
|
||||||
|
suspend fun get(k: Key): Value?
|
||||||
|
suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value>
|
||||||
|
suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key>
|
||||||
|
suspend fun contains(key: Key): Boolean
|
||||||
|
suspend fun count(): Long
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StandardWriteKeyValueRepo<Key, Value> : Repo {
|
||||||
|
val onNewValue: Flow<Pair<Key, Value>>
|
||||||
|
val onValueRemoved: Flow<Key>
|
||||||
|
|
||||||
|
suspend fun set(k: Key, v: Value)
|
||||||
|
suspend fun unset(k: Key)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StandardKeyValueRepo<Key, Value> : StandardReadKeyValueRepo<Key, Value>,
|
||||||
|
StandardWriteKeyValueRepo<Key, Value>
|
@ -5,6 +5,7 @@ String[] includes = [
|
|||||||
":pagination:exposed",
|
":pagination:exposed",
|
||||||
":pagination:ktor:common",
|
":pagination:ktor:common",
|
||||||
":pagination:ktor:server",
|
":pagination:ktor:server",
|
||||||
|
":repos:common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user