From d56eb6c867a34aff33769ec081e663ed67edaa70 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 8 Nov 2022 12:47:59 +0600 Subject: [PATCH] fixes --- .../repos/exposed/AbstractExposedWriteCRUDRepo.kt | 4 +--- .../inmo/micro_utils/repos/exposed/CommonExposedRepo.kt | 4 ++-- .../repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt | 8 ++++---- .../exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt | 2 +- .../repos/exposed/keyvalue/ExposedKeyValueRepo.kt | 8 +++++--- .../repos/exposed/keyvalue/ExposedReadKeyValueRepo.kt | 4 ++-- .../exposed/onetomany/AbstractExposedKeyValueRepo.kt | 4 ++-- .../exposed/onetomany/AbstractExposedReadKeyValueRepo.kt | 2 +- .../repos/exposed/onetomany/ExposedKeyValuesRepo.kt | 1 + .../repos/exposed/onetomany/ExposedReadKeyValuesRepo.kt | 4 ++-- 10 files changed, 21 insertions(+), 20 deletions(-) diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt index 289adb04f8b..c6587d7d01c 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt @@ -137,9 +137,7 @@ abstract class AbstractExposedWriteCRUDRepo( override suspend fun deleteById(ids: List) { onBeforeDelete(ids) transaction(db = database) { - val deleted = deleteWhere(null, null) { - selectByIds(ids) - } + val deleted = deleteWhere(null, null) { selectByIds(it, ids) } if (deleted == ids.size) { ids } else { diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt index 7501646499e..fe19c54493e 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt @@ -4,8 +4,8 @@ import org.jetbrains.exposed.sql.* interface CommonExposedRepo : ExposedRepo { val ResultRow.asObject: ObjectType - val selectById: SqlExpressionBuilder.(IdType) -> Op - val selectByIds: SqlExpressionBuilder.(List) -> Op + val selectById: ISqlExpressionBuilder.(IdType) -> Op + val selectByIds: ISqlExpressionBuilder.(List) -> Op get() = { list -> if (list.isEmpty()) { Op.FALSE diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt index 42a640ef648..b1e346b451d 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedKeyValueRepo.kt @@ -59,9 +59,9 @@ abstract class AbstractExposedKeyValueRepo( override suspend fun unset(toUnset: List) { transaction(database) { - toUnset.mapNotNull { - if (deleteWhere { selectById(it) } > 0) { - it + toUnset.mapNotNull { item -> + if (deleteWhere { selectById(it, item) } > 0) { + item } else { null } @@ -75,7 +75,7 @@ abstract class AbstractExposedKeyValueRepo( transaction(database) { toUnset.flatMap { val keys = select { selectByValue(it) }.mapNotNull { it.asKey } - deleteWhere { selectByIds(keys) } + deleteWhere { selectByIds(it, keys) } keys } }.distinct().forEach { diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt index 60c142f7a8f..3498bf2685b 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/AbstractExposedReadKeyValueRepo.kt @@ -16,7 +16,7 @@ abstract class AbstractExposedReadKeyValueRepo( Table(tableName ?: "") { abstract val keyColumn: Column<*> abstract val ResultRow.asKey: Key - abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op + abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op override suspend fun get(k: Key): Value? = transaction(database) { select { selectById(k) }.limit(1).firstOrNull() ?.asObject diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt index 8d3588d842f..80c57f7cd4b 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedKeyValueRepo.kt @@ -4,6 +4,8 @@ import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.exposed.ColumnAllocator import kotlinx.coroutines.flow.* 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 open class ExposedKeyValueRepo( @@ -47,9 +49,9 @@ open class ExposedKeyValueRepo( override suspend fun unset(toUnset: List) { transaction(database) { - toUnset.mapNotNull { - if (deleteWhere { keyColumn.eq(it) } > 0) { - it + toUnset.mapNotNull { item -> + if (deleteWhere { keyColumn.eq(item) } > 0) { + item } else { null } diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedReadKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedReadKeyValueRepo.kt index 0e01f00b759..2c3b33a53ac 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedReadKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/keyvalue/ExposedReadKeyValueRepo.kt @@ -20,10 +20,10 @@ open class ExposedReadKeyValueRepo( val valueColumn: Column = valueColumnAllocator() override val ResultRow.asKey: Key get() = get(keyColumn) - override val selectByValue: SqlExpressionBuilder.(Value) -> Op = { valueColumn.eq(it) } + override val selectByValue: ISqlExpressionBuilder.(Value) -> Op = { valueColumn.eq(it) } override val ResultRow.asObject: Value get() = get(valueColumn) - override val selectById: SqlExpressionBuilder.(Key) -> Op = { keyColumn.eq(it) } + override val selectById: ISqlExpressionBuilder.(Key) -> Op = { keyColumn.eq(it) } override val primaryKey: Table.PrimaryKey get() = PrimaryKey(keyColumn, valueColumn) diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedKeyValueRepo.kt index c4ae2cd684a..d63f99bc704 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedKeyValueRepo.kt @@ -49,7 +49,7 @@ abstract class AbstractExposedKeyValuesRepo( transaction(database) { toRemove.keys.flatMap { k -> 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 } else { null @@ -63,7 +63,7 @@ abstract class AbstractExposedKeyValuesRepo( override suspend fun clear(k: Key) { transaction(database) { - deleteWhere { selectById(k) } + deleteWhere { selectById(it, k) } }.also { _onDataCleared.emit(k) } } } diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedReadKeyValueRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedReadKeyValueRepo.kt index 1575c9b0d04..3b0e7313887 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedReadKeyValueRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/AbstractExposedReadKeyValueRepo.kt @@ -17,7 +17,7 @@ abstract class AbstractExposedReadKeyValuesRepo( Table(tableName ?: "") { abstract val keyColumn: Column<*> abstract val ResultRow.asKey: Key - abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op + abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() } diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt index 6bb8bd67a63..9b79231c8bc 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedKeyValuesRepo.kt @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.repos.KeyValuesRepo import dev.inmo.micro_utils.repos.exposed.ColumnAllocator import kotlinx.coroutines.flow.* import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.transactions.transaction typealias ExposedOneToManyKeyValueRepo1 = ExposedKeyValuesRepo diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedReadKeyValuesRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedReadKeyValuesRepo.kt index cb7a6334285..2efcaf6880c 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedReadKeyValuesRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/onetomany/ExposedReadKeyValuesRepo.kt @@ -15,10 +15,10 @@ open class ExposedReadKeyValuesRepo( override val keyColumn: Column = keyColumnAllocator() override val ResultRow.asKey: Key get() = get(keyColumn) - override val selectByValue: SqlExpressionBuilder.(Value) -> Op = { valueColumn.eq(it) } + override val selectByValue: ISqlExpressionBuilder.(Value) -> Op = { valueColumn.eq(it) } override val ResultRow.asObject: Value get() = get(valueColumn) - override val selectById: SqlExpressionBuilder.(Key) -> Op = { keyColumn.eq(it) } + override val selectById: ISqlExpressionBuilder.(Key) -> Op = { keyColumn.eq(it) } val valueColumn: Column = valueColumnAllocator() init { initTable() }