mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-18 14:59:24 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
64ee899b84 | |||
e0e0c1658b | |||
2c586f667c | |||
64164ef6c1 | |||
22343c0731 | |||
f4ec1a4c60 | |||
c1c33cceb1 | |||
a3e975b2ba | |||
06e705a687 | |||
d56eb6c867 | |||
9cbca864e3 | |||
abb4378694 | |||
0eb698d9a4 | |||
15ea9f2093 | |||
d47aca0923 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,5 +1,21 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.14.1
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Klock`: `3.3.1` -> `3.4.0`
|
||||||
|
* `UUID`: `0.5.0` -> `0.6.0`
|
||||||
|
|
||||||
|
## 0.14.0
|
||||||
|
|
||||||
|
**ALL DEPRECATIONS HAVE BEEN REMOVED**
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Kotlin`: `1.7.10` -> `1.7.20`
|
||||||
|
* `Klock`: `3.3.0` -> `3.3.1`
|
||||||
|
* `Compose`: `1.2.0` -> `1.2.1`
|
||||||
|
* `Exposed`: `0.39.2` -> `0.40.1`
|
||||||
|
|
||||||
## 0.13.2
|
## 0.13.2
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.13.2
|
version=0.14.1
|
||||||
android_code_version=160
|
android_code_version=162
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "1.7.10"
|
kt = "1.7.20"
|
||||||
kt-serialization = "1.4.1"
|
kt-serialization = "1.4.1"
|
||||||
kt-coroutines = "1.6.4"
|
kt-coroutines = "1.6.4"
|
||||||
|
|
||||||
jb-compose = "1.2.0"
|
jb-compose = "1.2.1"
|
||||||
jb-exposed = "0.39.2"
|
jb-exposed = "0.40.1"
|
||||||
jb-dokka = "1.7.10"
|
jb-dokka = "1.7.20"
|
||||||
|
|
||||||
klock = "3.3.0"
|
klock = "3.4.0"
|
||||||
uuid = "0.5.0"
|
uuid = "0.6.0"
|
||||||
|
|
||||||
ktor = "2.1.3"
|
ktor = "2.1.3"
|
||||||
|
|
||||||
|
@@ -0,0 +1,138 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.*
|
||||||
|
import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read part of [KeyValueRepo]
|
||||||
|
*
|
||||||
|
* @param Key This type will be used as key in all operations related to searches of data
|
||||||
|
* @param Value This type will be used as returning data in most "get" operations
|
||||||
|
*/
|
||||||
|
interface ReadKeyValueRepo<Key, Value> : Repo {
|
||||||
|
/**
|
||||||
|
* @return Result [Value] in case when it is presented in repo by its [k] or null otherwise
|
||||||
|
*/
|
||||||
|
suspend fun get(k: Key): Value?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*/
|
||||||
|
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*/
|
||||||
|
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*
|
||||||
|
* @param v This value should be used to exclude from search the items with different [Value]s
|
||||||
|
*/
|
||||||
|
suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if [key] is presented in current collection or false otherwise
|
||||||
|
*/
|
||||||
|
suspend fun contains(key: Key): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return count of all collection objects
|
||||||
|
*/
|
||||||
|
suspend fun count(): Long
|
||||||
|
}
|
||||||
|
typealias ReadStandardKeyValueRepo<Key,Value> = ReadKeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write part of [KeyValueRepo]
|
||||||
|
*
|
||||||
|
* @param Key This type will be used as key in all operations related to changes of data
|
||||||
|
* @param Value This type will be used as incoming data in most operations
|
||||||
|
*/
|
||||||
|
interface WriteKeyValueRepo<Key, Value> : Repo {
|
||||||
|
/**
|
||||||
|
* This flow must emit data each time when data by [Key] has been changed with [set] method or in any other way
|
||||||
|
* excluding cases of data removing
|
||||||
|
*
|
||||||
|
* @see onValueRemoved
|
||||||
|
*/
|
||||||
|
val onNewValue: Flow<Pair<Key, Value>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This flow must emit data each time when data by [Key] has been removed with [unset]/[unsetWithValues] methods or
|
||||||
|
* in any other way
|
||||||
|
*
|
||||||
|
* @see onNewValue
|
||||||
|
*/
|
||||||
|
val onValueRemoved: Flow<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will set as batch [toSet] data in current repo. Must pass the data which were successfully updated in repo to
|
||||||
|
* [onNewValue]
|
||||||
|
*/
|
||||||
|
suspend fun set(toSet: Map<Key, Value>)
|
||||||
|
/**
|
||||||
|
* Will unset as batch data with keys from [toUnset]. Must pass the [Key]s which were successfully removed in repo to
|
||||||
|
* [onValueRemoved]
|
||||||
|
*/
|
||||||
|
suspend fun unset(toUnset: List<Key>)
|
||||||
|
/**
|
||||||
|
* Will unset as batch data with values from [toUnset]. Must pass the [Key]s which were successfully removed in repo
|
||||||
|
* to [onValueRemoved]
|
||||||
|
*/
|
||||||
|
suspend fun unsetWithValues(toUnset: List<Value>)
|
||||||
|
}
|
||||||
|
typealias WriteStandardKeyValueRepo<Key,Value> = WriteKeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
||||||
|
vararg toSet: Pair<Key, Value>
|
||||||
|
) = set(toSet.toMap())
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
||||||
|
k: Key, v: Value
|
||||||
|
) = set(k to v)
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(
|
||||||
|
vararg k: Key
|
||||||
|
) = unset(k.toList())
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(
|
||||||
|
vararg v: Value
|
||||||
|
) = unsetWithValues(v.toList())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full version of standard key-value repository with all set/unset/clear/get methods
|
||||||
|
*/
|
||||||
|
interface KeyValueRepo<Key, Value> : ReadKeyValueRepo<Key, Value>, WriteKeyValueRepo<Key, Value> {
|
||||||
|
/**
|
||||||
|
* By default, will walk throw all the [keys] with [Value]s from [toUnset] and run [doAllWithCurrentPaging] with
|
||||||
|
* [unset] of found data [Key]s
|
||||||
|
*/
|
||||||
|
override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v ->
|
||||||
|
doAllWithCurrentPaging {
|
||||||
|
keys(v, it).also {
|
||||||
|
unset(it.results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, will remove all the data of current repo using [doAllWithCurrentPaging], [keys] and [unset]
|
||||||
|
*/
|
||||||
|
suspend fun clear() {
|
||||||
|
doAllWithCurrentPaging { keys(it).also { unset(it.results) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
typealias StandardKeyValueRepo<Key,Value> = KeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
class DelegateBasedKeyValueRepo<Key, Value>(
|
||||||
|
readDelegate: ReadKeyValueRepo<Key, Value>,
|
||||||
|
writeDelegate: WriteKeyValueRepo<Key, Value>
|
||||||
|
) : KeyValueRepo<Key, Value>,
|
||||||
|
ReadKeyValueRepo<Key, Value> by readDelegate,
|
||||||
|
WriteKeyValueRepo<Key, Value> by writeDelegate
|
@@ -1,63 +0,0 @@
|
|||||||
package dev.inmo.micro_utils.repos
|
|
||||||
|
|
||||||
import dev.inmo.micro_utils.pagination.*
|
|
||||||
import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface ReadKeyValueRepo<Key, Value> : Repo {
|
|
||||||
suspend fun get(k: Key): Value?
|
|
||||||
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
|
||||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
|
||||||
suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
|
||||||
suspend fun contains(key: Key): Boolean
|
|
||||||
suspend fun count(): Long
|
|
||||||
}
|
|
||||||
typealias ReadStandardKeyValueRepo<Key,Value> = ReadKeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
interface WriteKeyValueRepo<Key, Value> : Repo {
|
|
||||||
val onNewValue: Flow<Pair<Key, Value>>
|
|
||||||
val onValueRemoved: Flow<Key>
|
|
||||||
|
|
||||||
suspend fun set(toSet: Map<Key, Value>)
|
|
||||||
suspend fun unset(toUnset: List<Key>)
|
|
||||||
suspend fun unsetWithValues(toUnset: List<Value>)
|
|
||||||
}
|
|
||||||
typealias WriteStandardKeyValueRepo<Key,Value> = WriteKeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
|
||||||
vararg toSet: Pair<Key, Value>
|
|
||||||
) = set(toSet.toMap())
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
|
||||||
k: Key, v: Value
|
|
||||||
) = set(k to v)
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(
|
|
||||||
vararg k: Key
|
|
||||||
) = unset(k.toList())
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(
|
|
||||||
vararg v: Value
|
|
||||||
) = unsetWithValues(v.toList())
|
|
||||||
|
|
||||||
interface KeyValueRepo<Key, Value> : ReadKeyValueRepo<Key, Value>, WriteKeyValueRepo<Key, Value> {
|
|
||||||
override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v ->
|
|
||||||
doAllWithCurrentPaging {
|
|
||||||
keys(v, it).also {
|
|
||||||
unset(it.results)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun clear() {
|
|
||||||
doAllWithCurrentPaging { keys(it).also { unset(it.results) } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
typealias StandardKeyValueRepo<Key,Value> = KeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
class DelegateBasedKeyValueRepo<Key, Value>(
|
|
||||||
readDelegate: ReadKeyValueRepo<Key, Value>,
|
|
||||||
writeDelegate: WriteKeyValueRepo<Key, Value>
|
|
||||||
) : KeyValueRepo<Key, Value>,
|
|
||||||
ReadKeyValueRepo<Key, Value> by readDelegate,
|
|
||||||
WriteKeyValueRepo<Key, Value> by writeDelegate
|
|
@@ -50,14 +50,6 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
|||||||
val id = createAndInsertId(value, it)
|
val id = createAndInsertId(value, it)
|
||||||
update(id, value, it as UpdateBuilder<Int>)
|
update(id, value, it as UpdateBuilder<Int>)
|
||||||
}
|
}
|
||||||
@Deprecated(
|
|
||||||
"Replace its \"it\" parameter type with \"UpdateBuilder<Int>\" to actualize method signature. Method with current signature will be removed soon and do not recommended to override anymore"
|
|
||||||
)
|
|
||||||
protected open fun update(id: IdType, value: InputValueType, it: UpdateStatement) = update(
|
|
||||||
id,
|
|
||||||
value,
|
|
||||||
it as UpdateBuilder<Int>
|
|
||||||
)
|
|
||||||
|
|
||||||
protected open suspend fun onBeforeCreate(value: List<InputValueType>) {}
|
protected open suspend fun onBeforeCreate(value: List<InputValueType>) {}
|
||||||
|
|
||||||
@@ -137,9 +129,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
|||||||
override suspend fun deleteById(ids: List<IdType>) {
|
override suspend fun deleteById(ids: List<IdType>) {
|
||||||
onBeforeDelete(ids)
|
onBeforeDelete(ids)
|
||||||
transaction(db = database) {
|
transaction(db = database) {
|
||||||
val deleted = deleteWhere(null, null) {
|
val deleted = deleteWhere(null, null) { selectByIds(it, ids) }
|
||||||
selectByIds(ids)
|
|
||||||
}
|
|
||||||
if (deleted == ids.size) {
|
if (deleted == ids.size) {
|
||||||
ids
|
ids
|
||||||
} else {
|
} else {
|
||||||
|
@@ -4,8 +4,8 @@ import org.jetbrains.exposed.sql.*
|
|||||||
|
|
||||||
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
|
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
|
||||||
val ResultRow.asObject: ObjectType
|
val ResultRow.asObject: ObjectType
|
||||||
val selectById: SqlExpressionBuilder.(IdType) -> Op<Boolean>
|
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
|
||||||
val selectByIds: SqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
||||||
get() = { list ->
|
get() = { list ->
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
Op.FALSE
|
Op.FALSE
|
||||||
|
@@ -27,15 +27,6 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
update(k, v, it as UpdateBuilder<Int>)
|
update(k, v, it as UpdateBuilder<Int>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(
|
|
||||||
"Replace its \"it\" parameter type with \"UpdateBuilder<Int>\" to actualize method signature. Method with current signature will be removed soon and do not recommended to override anymore"
|
|
||||||
)
|
|
||||||
protected open fun update(k: Key, v: Value, it: UpdateStatement) = update(
|
|
||||||
k,
|
|
||||||
v,
|
|
||||||
it as UpdateBuilder<Int>
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun set(toSet: Map<Key, Value>) {
|
override suspend fun set(toSet: Map<Key, Value>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toSet.mapNotNull { (k, v) ->
|
toSet.mapNotNull { (k, v) ->
|
||||||
@@ -59,9 +50,9 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun unset(toUnset: List<Key>) {
|
override suspend fun unset(toUnset: List<Key>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.mapNotNull {
|
toUnset.mapNotNull { item ->
|
||||||
if (deleteWhere { selectById(it) } > 0) {
|
if (deleteWhere { selectById(it, item) } > 0) {
|
||||||
it
|
item
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -75,7 +66,7 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.flatMap {
|
toUnset.flatMap {
|
||||||
val keys = select { selectByValue(it) }.mapNotNull { it.asKey }
|
val keys = select { selectByValue(it) }.mapNotNull { it.asKey }
|
||||||
deleteWhere { selectByIds(keys) }
|
deleteWhere { selectByIds(it, keys) }
|
||||||
keys
|
keys
|
||||||
}
|
}
|
||||||
}.distinct().forEach {
|
}.distinct().forEach {
|
||||||
|
@@ -16,7 +16,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
|||||||
Table(tableName ?: "") {
|
Table(tableName ?: "") {
|
||||||
abstract val keyColumn: Column<*>
|
abstract val keyColumn: Column<*>
|
||||||
abstract val ResultRow.asKey: Key
|
abstract val ResultRow.asKey: Key
|
||||||
abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean>
|
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||||
|
|
||||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||||
select { selectById(k) }.limit(1).firstOrNull() ?.asObject
|
select { selectById(k) }.limit(1).firstOrNull() ?.asObject
|
||||||
|
@@ -4,6 +4,8 @@ import dev.inmo.micro_utils.repos.KeyValueRepo
|
|||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
open class ExposedKeyValueRepo<Key, Value>(
|
open class ExposedKeyValueRepo<Key, Value>(
|
||||||
@@ -47,9 +49,9 @@ open class ExposedKeyValueRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun unset(toUnset: List<Key>) {
|
override suspend fun unset(toUnset: List<Key>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.mapNotNull {
|
toUnset.mapNotNull { item ->
|
||||||
if (deleteWhere { keyColumn.eq(it) } > 0) {
|
if (deleteWhere { keyColumn.eq(item) } > 0) {
|
||||||
it
|
item
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,10 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
val valueColumn: Column<Value> = valueColumnAllocator()
|
val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
override val ResultRow.asKey: Key
|
override val ResultRow.asKey: Key
|
||||||
get() = get(keyColumn)
|
get() = get(keyColumn)
|
||||||
override val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
override val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
||||||
override val ResultRow.asObject: Value
|
override val ResultRow.asObject: Value
|
||||||
get() = get(valueColumn)
|
get() = get(valueColumn)
|
||||||
override val selectById: SqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
override val selectById: ISqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
||||||
override val primaryKey: Table.PrimaryKey
|
override val primaryKey: Table.PrimaryKey
|
||||||
get() = PrimaryKey(keyColumn, valueColumn)
|
get() = PrimaryKey(keyColumn, valueColumn)
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
|||||||
transaction(database) {
|
transaction(database) {
|
||||||
toRemove.keys.flatMap { k ->
|
toRemove.keys.flatMap { k ->
|
||||||
toRemove[k] ?.mapNotNull { v ->
|
toRemove[k] ?.mapNotNull { v ->
|
||||||
if (deleteWhere { selectById(k).and(selectByValue(v)) } > 0 ) {
|
if (deleteWhere { selectById(it, k).and(SqlExpressionBuilder.selectByValue(v)) } > 0 ) {
|
||||||
k to v
|
k to v
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -63,7 +63,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun clear(k: Key) {
|
override suspend fun clear(k: Key) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
deleteWhere { selectById(k) }
|
deleteWhere { selectById(it, k) }
|
||||||
}.also { _onDataCleared.emit(k) }
|
}.also { _onDataCleared.emit(k) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
|
|||||||
Table(tableName ?: "") {
|
Table(tableName ?: "") {
|
||||||
abstract val keyColumn: Column<*>
|
abstract val keyColumn: Column<*>
|
||||||
abstract val ResultRow.asKey: Key
|
abstract val ResultRow.asKey: Key
|
||||||
abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean>
|
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||||
|
|
||||||
override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() }
|
override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() }
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.repos.KeyValuesRepo
|
|||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
typealias ExposedOneToManyKeyValueRepo1<Key, Value> = ExposedKeyValuesRepo<Key, Value>
|
typealias ExposedOneToManyKeyValueRepo1<Key, Value> = ExposedKeyValuesRepo<Key, Value>
|
||||||
|
@@ -15,10 +15,10 @@ open class ExposedReadKeyValuesRepo<Key, Value>(
|
|||||||
override val keyColumn: Column<Key> = keyColumnAllocator()
|
override val keyColumn: Column<Key> = keyColumnAllocator()
|
||||||
override val ResultRow.asKey: Key
|
override val ResultRow.asKey: Key
|
||||||
get() = get(keyColumn)
|
get() = get(keyColumn)
|
||||||
override val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
override val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
||||||
override val ResultRow.asObject: Value
|
override val ResultRow.asObject: Value
|
||||||
get() = get(valueColumn)
|
get() = get(valueColumn)
|
||||||
override val selectById: SqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
override val selectById: ISqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
||||||
val valueColumn: Column<Value> = valueColumnAllocator()
|
val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
|
|
||||||
init { initTable() }
|
init { initTable() }
|
||||||
|
Reference in New Issue
Block a user