Merge pull request #202 from InsanusMokrassar/0.14.0

0.14.0
This commit is contained in:
InsanusMokrassar 2022-11-08 14:20:12 +06:00 committed by GitHub
commit 22343c0731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 38 additions and 44 deletions

View File

@ -1,5 +1,15 @@
# Changelog
## 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
* `Versions`:

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.13.2
android_code_version=160
version=0.14.0
android_code_version=161

View File

@ -1,14 +1,14 @@
[versions]
kt = "1.7.10"
kt = "1.7.20"
kt-serialization = "1.4.1"
kt-coroutines = "1.6.4"
jb-compose = "1.2.0"
jb-exposed = "0.39.2"
jb-dokka = "1.7.10"
jb-compose = "1.2.1"
jb-exposed = "0.40.1"
jb-dokka = "1.7.20"
klock = "3.3.0"
klock = "3.3.1"
uuid = "0.5.0"
ktor = "2.1.3"

View File

@ -50,14 +50,6 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
val id = createAndInsertId(value, it)
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>) {}
@ -137,9 +129,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
override suspend fun deleteById(ids: List<IdType>) {
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 {

View File

@ -4,8 +4,8 @@ import org.jetbrains.exposed.sql.*
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
val ResultRow.asObject: ObjectType
val selectById: SqlExpressionBuilder.(IdType) -> Op<Boolean>
val selectByIds: SqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
get() = { list ->
if (list.isEmpty()) {
Op.FALSE

View File

@ -27,15 +27,6 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
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>) {
transaction(database) {
toSet.mapNotNull { (k, v) ->
@ -59,9 +50,9 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
override suspend fun unset(toUnset: List<Key>) {
transaction(database) {
toUnset.mapNotNull {
if (deleteWhere { selectById(it) } > 0) {
it
toUnset.mapNotNull { item ->
if (deleteWhere { selectById(it, item) } > 0) {
item
} else {
null
}
@ -75,7 +66,7 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
transaction(database) {
toUnset.flatMap {
val keys = select { selectByValue(it) }.mapNotNull { it.asKey }
deleteWhere { selectByIds(keys) }
deleteWhere { selectByIds(it, keys) }
keys
}
}.distinct().forEach {

View File

@ -16,7 +16,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
Table(tableName ?: "") {
abstract val keyColumn: Column<*>
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) {
select { selectById(k) }.limit(1).firstOrNull() ?.asObject

View File

@ -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<Key, Value>(
@ -47,9 +49,9 @@ open class ExposedKeyValueRepo<Key, Value>(
override suspend fun unset(toUnset: List<Key>) {
transaction(database) {
toUnset.mapNotNull {
if (deleteWhere { keyColumn.eq(it) } > 0) {
it
toUnset.mapNotNull { item ->
if (deleteWhere { keyColumn.eq(item) } > 0) {
item
} else {
null
}

View File

@ -20,10 +20,10 @@ open class ExposedReadKeyValueRepo<Key, Value>(
val valueColumn: Column<Value> = valueColumnAllocator()
override val ResultRow.asKey: Key
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
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
get() = PrimaryKey(keyColumn, valueColumn)

View File

@ -49,7 +49,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
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<Key, Value>(
override suspend fun clear(k: Key) {
transaction(database) {
deleteWhere { selectById(k) }
deleteWhere { selectById(it, k) }
}.also { _onDataCleared.emit(k) }
}
}

View File

@ -17,7 +17,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
Table(tableName ?: "") {
abstract val keyColumn: Column<*>
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() }

View File

@ -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<Key, Value> = ExposedKeyValuesRepo<Key, Value>

View File

@ -15,10 +15,10 @@ open class ExposedReadKeyValuesRepo<Key, Value>(
override val keyColumn: Column<Key> = keyColumnAllocator()
override val ResultRow.asKey: Key
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
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()
init { initTable() }