Merge pull request #371 from InsanusMokrassar/0.20.26

0.20.26
This commit is contained in:
InsanusMokrassar 2024-01-11 23:29:05 +06:00 committed by GitHub
commit 23aa2d8917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 48 additions and 26 deletions

View File

@ -1,5 +1,13 @@
# Changelog # Changelog
## 0.20.26
* `Versions`:
* `Exposed`: `0.45.0` -> `0.46.0`. **This update brinds new api deprecations in exposed**
* `Resources`:
* Add opportunity to get default translation by passing `null` as `IetfLang` argument
* Add several useful extensions to get translations in `JS` target
## 0.20.25 ## 0.20.25
* `Colors`: * `Colors`:

View File

@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.20.25 version=0.20.26
android_code_version=231 android_code_version=232

View File

@ -7,7 +7,7 @@ kt-coroutines = "1.7.3"
kslog = "1.3.1" kslog = "1.3.1"
jb-compose = "1.5.11" jb-compose = "1.5.11"
jb-exposed = "0.45.0" jb-exposed = "0.46.0"
jb-dokka = "1.9.10" jb-dokka = "1.9.10"
korlibs = "5.3.0" korlibs = "5.3.0"
@ -26,7 +26,7 @@ kotlin-poet = "1.15.3"
versions = "0.50.0" versions = "0.50.0"
android-gradle = "8.2.0" android-gradle = "8.2.1"
dexcount = "4.0.0" dexcount = "4.0.0"
android-coreKtx = "1.12.0" android-coreKtx = "1.12.0"

View File

@ -35,14 +35,14 @@ abstract class AbstractExposedReadCRUDRepo<ObjectType, IdType>(
} }
override suspend fun getById(id: IdType): ObjectType? { override suspend fun getById(id: IdType): ObjectType? {
return transaction(db = database) { return transaction(db = database) {
select { selectAll().where {
selectById(id) selectById(id)
}.limit(1).firstOrNull() ?.asObject }.limit(1).firstOrNull() ?.asObject
} }
} }
override suspend fun contains(id: IdType): Boolean = transaction(db = database) { override suspend fun contains(id: IdType): Boolean = transaction(db = database) {
select { selectById(id) }.limit(1).any() selectAll().where { selectById(id) }.limit(1).any()
} }
override suspend fun getAll(): Map<IdType, ObjectType> = transaction(database) { override suspend fun getAll(): Map<IdType, ObjectType> = transaction(database) {

View File

@ -101,7 +101,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
}.let { }.let {
if (it > 0) { if (it > 0) {
transaction(db = database) { transaction(db = database) {
select { selectAll().where {
selectById(this, id) selectById(this, id)
}.limit(1).firstOrNull() ?.asObject }.limit(1).firstOrNull() ?.asObject
} }
@ -142,7 +142,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
ids ids
} else { } else {
ids.filter { ids.filter {
select { selectById(it) }.limit(1).none() selectAll().where { selectById(it) }.limit(1).none()
} }
} }
}.forEach { }.forEach {

View File

@ -65,7 +65,7 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
override suspend fun unsetWithValues(toUnset: List<Value>) { override suspend fun unsetWithValues(toUnset: List<Value>) {
transaction(database) { transaction(database) {
toUnset.flatMap { toUnset.flatMap {
val keys = select { selectByValue(it) }.mapNotNull { it.asKey } val keys = selectAll().where { selectByValue(it) }.mapNotNull { it.asKey }
deleteWhere { selectByIds(it, keys) } deleteWhere { selectByIds(it, keys) }
keys keys
} }

View File

@ -24,11 +24,11 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
abstract val selectByValue: ISqlExpressionBuilder.(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 selectAll().where { selectById(k) }.limit(1).firstOrNull() ?.asObject
} }
override suspend fun contains(key: Key): Boolean = transaction(database) { override suspend fun contains(key: Key): Boolean = transaction(database) {
select { selectById(key) }.limit(1).any() selectAll().where { selectById(key) }.limit(1).any()
} }
override suspend fun getAll(): Map<Key, Value> = transaction(database) { selectAll().associate { it.asKey to it.asObject } } override suspend fun getAll(): Map<Key, Value> = transaction(database) { selectAll().associate { it.asKey to it.asObject } }
@ -46,7 +46,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
} }
override suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) { override suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
select { selectByValue(v) }.selectPaginated( selectAll().where { selectByValue(v) }.selectPaginated(
pagination, pagination,
keyColumn, keyColumn,
reversed reversed

View File

@ -65,7 +65,7 @@ open class ExposedKeyValueRepo<Key, Value>(
override suspend fun unsetWithValues(toUnset: List<Value>) { override suspend fun unsetWithValues(toUnset: List<Value>) {
transaction(database) { transaction(database) {
toUnset.flatMap { toUnset.flatMap {
val keys = select { valueColumn.eq(it) }.mapNotNull { it[keyColumn] } val keys = selectAll().where { valueColumn.eq(it) }.mapNotNull { it[keyColumn] }
deleteWhere { keyColumn.inList(keys) } deleteWhere { keyColumn.inList(keys) }
keys keys
} }

View File

@ -29,7 +29,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
transaction(database) { transaction(database) {
toAdd.keys.flatMap { k -> toAdd.keys.flatMap { k ->
toAdd[k] ?.mapNotNull { v -> toAdd[k] ?.mapNotNull { v ->
if (select { selectById(k).and(selectByValue(v)) }.limit(1).any()) { if (selectAll().where { selectById(k).and(selectByValue(v)) }.limit(1).any()) {
return@mapNotNull null return@mapNotNull null
} }
val insertResult = insert { val insertResult = insert {

View File

@ -19,7 +19,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
get() = asKey get() = asKey
abstract val selectByValue: ISqlExpressionBuilder.(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) { selectAll().where { selectById(k) }.count() }
override suspend fun count(): Long = transaction(database) { selectAll().count() } override suspend fun count(): Long = transaction(database) { selectAll().count() }
@ -28,7 +28,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
pagination: Pagination, pagination: Pagination,
reversed: Boolean reversed: Boolean
): PaginationResult<Value> = transaction(database) { ): PaginationResult<Value> = transaction(database) {
select { selectById(k) }.selectPaginated( selectAll().where { selectById(k) }.selectPaginated(
pagination, pagination,
keyColumn, keyColumn,
reversed reversed
@ -55,7 +55,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
pagination: Pagination, pagination: Pagination,
reversed: Boolean reversed: Boolean
): PaginationResult<Key> = transaction(database) { ): PaginationResult<Key> = transaction(database) {
select { selectByValue(v) }.selectPaginated( selectAll().where { selectByValue(v) }.selectPaginated(
pagination, pagination,
keyColumn, keyColumn,
reversed reversed
@ -65,11 +65,11 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
} }
override suspend fun contains(k: Key): Boolean = transaction(database) { override suspend fun contains(k: Key): Boolean = transaction(database) {
select { selectById(k) }.limit(1).any() selectAll().where { selectById(k) }.limit(1).any()
} }
override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) { override suspend fun contains(k: Key, v: Value): Boolean = transaction(database) {
select { selectById(k).and(selectByValue(v)) }.limit(1).any() selectAll().where { selectById(k).and(selectByValue(v)) }.limit(1).any()
} }
override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> = transaction(database) { override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> = transaction(database) {
@ -85,9 +85,9 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
override suspend fun getAll(k: Key, reverseLists: Boolean): List<Value> = transaction(database) { override suspend fun getAll(k: Key, reverseLists: Boolean): List<Value> = transaction(database) {
val query = if (reverseLists) { val query = if (reverseLists) {
select { selectById(k) }.orderBy(keyColumn, SortOrder.DESC) selectAll().where { selectById(k) }.orderBy(keyColumn, SortOrder.DESC)
} else { } else {
select { selectById(k) } selectAll().where { selectById(k) }
} }
query.map { query.map {
it.asObject it.asObject

View File

@ -34,7 +34,7 @@ open class ExposedKeyValuesRepo<Key, Value>(
transaction(database) { transaction(database) {
toAdd.keys.flatMap { k -> toAdd.keys.flatMap { k ->
toAdd[k] ?.mapNotNull { v -> toAdd[k] ?.mapNotNull { v ->
if (select { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).count() > 0) { if (selectAll().where { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).count() > 0) {
return@mapNotNull null return@mapNotNull null
} }
val insertResult = insert { val insertResult = insert {
@ -69,7 +69,7 @@ open class ExposedKeyValuesRepo<Key, Value>(
override suspend fun removeWithValue(v: Value) { override suspend fun removeWithValue(v: Value) {
transaction(database) { transaction(database) {
val keys = select { selectByValue(v) }.map { it.asKey } val keys = selectAll().where { selectByValue(v) }.map { it.asKey }
deleteWhere { SqlExpressionBuilder.selectByValue(v) } deleteWhere { SqlExpressionBuilder.selectByValue(v) }
keys keys
}.forEach { }.forEach {
@ -85,7 +85,7 @@ open class ExposedKeyValuesRepo<Key, Value>(
override suspend fun clearWithValue(v: Value) { override suspend fun clearWithValue(v: Value) {
transaction(database) { transaction(database) {
val toClear = select { selectByValue(v) } val toClear = selectAll().where { selectByValue(v) }
.asSequence() .asSequence()
.map { it.asKey to it.asObject } .map { it.asKey to it.asObject }
.groupBy { it.first } .groupBy { it.first }

View File

@ -26,7 +26,7 @@ class ExposedStandardVersionsRepoProxy(
} }
override suspend fun getTableVersion(tableName: String): Int? = transaction(database) { override suspend fun getTableVersion(tableName: String): Int? = transaction(database) {
select { tableNameColumn.eq(tableName) }.limit(1).firstOrNull() ?.getOrNull(tableVersionColumn) selectAll().where { tableNameColumn.eq(tableName) }.limit(1).firstOrNull() ?.getOrNull(tableVersionColumn)
} }
override suspend fun updateTableVersion(tableName: String, version: Int) { override suspend fun updateTableVersion(tableName: String, version: Int) {

View File

@ -39,7 +39,10 @@ class StringResource(
fun build() = StringResource(default, map.toMap()) fun build() = StringResource(default, map.toMap())
} }
fun translation(languageCode: IetfLang): String { fun translation(languageCode: IetfLang?): String {
if (languageCode == null) {
return default
}
map[languageCode] ?.let { return it.value } map[languageCode] ?.let { return it.value }
return languageCode.parentLang ?.let { return languageCode.parentLang ?.let {

View File

@ -0,0 +1,11 @@
package dev.inmo.micro_utils.strings
import dev.inmo.micro_utils.language_codes.IetfLang
import kotlinx.browser.window
import org.w3c.dom.NavigatorLanguage
fun StringResource.translation(language: NavigatorLanguage) = translation(
language.language.unsafeCast<String?>() ?.let { IetfLang(it) }
)
fun StringResource.translation() = translation(window.navigator)