mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-23 09:07:14 +00:00
commit
945d2fa284
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.12.5
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Exposed`:
|
||||||
|
* Fixes in `paginate` extensions
|
||||||
|
|
||||||
## 0.12.4
|
## 0.12.4
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.12.4
|
version=0.12.5
|
||||||
android_code_version=143
|
android_code_version=144
|
||||||
|
@ -4,11 +4,7 @@ import org.jetbrains.exposed.sql.*
|
|||||||
|
|
||||||
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
|
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
|
||||||
with.size,
|
with.size,
|
||||||
(if (orderBy ?.second == SortOrder.DESC) {
|
with.firstIndex.toLong()
|
||||||
with.lastIndex
|
|
||||||
} else {
|
|
||||||
with.firstIndex
|
|
||||||
}).toLong()
|
|
||||||
).let {
|
).let {
|
||||||
if (orderBy != null) {
|
if (orderBy != null) {
|
||||||
it.orderBy(
|
it.orderBy(
|
||||||
|
@ -3,6 +3,7 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
|
|||||||
import dev.inmo.micro_utils.pagination.*
|
import dev.inmo.micro_utils.pagination.*
|
||||||
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.*
|
import dev.inmo.micro_utils.repos.exposed.*
|
||||||
|
import dev.inmo.micro_utils.repos.exposed.utils.selectPaginated
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
@ -29,24 +30,32 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
override suspend fun count(): Long = transaction(database) { selectAll().count() }
|
override suspend fun count(): Long = transaction(database) { selectAll().count() }
|
||||||
|
|
||||||
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
|
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key> = transaction(database) {
|
||||||
selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
selectAll().selectPaginated(
|
||||||
|
pagination,
|
||||||
|
keyColumn,
|
||||||
|
reversed
|
||||||
|
) {
|
||||||
it[keyColumn]
|
it[keyColumn]
|
||||||
}
|
}
|
||||||
}.createPaginationResult(pagination, count())
|
}
|
||||||
|
|
||||||
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 { valueColumn.eq(v) }.let {
|
select { valueColumn.eq(v) }.selectPaginated(
|
||||||
it.count() to it.paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
pagination,
|
||||||
it[keyColumn]
|
keyColumn,
|
||||||
}
|
reversed
|
||||||
|
) {
|
||||||
|
it[keyColumn]
|
||||||
}
|
}
|
||||||
}.let { (count, list) ->
|
|
||||||
list.createPaginationResult(pagination, count)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value> = transaction(database) {
|
override suspend fun values(pagination: Pagination, reversed: Boolean): PaginationResult<Value> = transaction(database) {
|
||||||
selectAll().paginate(pagination, keyColumn to if (reversed) SortOrder.DESC else SortOrder.ASC).map {
|
selectAll().selectPaginated(
|
||||||
|
pagination,
|
||||||
|
keyColumn,
|
||||||
|
reversed
|
||||||
|
) {
|
||||||
it[valueColumn]
|
it[valueColumn]
|
||||||
}
|
}
|
||||||
}.createPaginationResult(pagination, count())
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user