init with pagination

This commit is contained in:
2020-09-15 18:57:41 +06:00
parent 97a83250f4
commit c6d0b0920e
22 changed files with 737 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppJavaProjectPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api internalProject("micro_utils.pagination.common")
}
}
}
}

View File

@@ -0,0 +1,27 @@
package dev.inmo.micro_utils.pagination
import org.jetbrains.exposed.sql.*
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
with.size,
(if (orderBy ?.second == SortOrder.DESC) {
with.lastIndex
} else {
with.firstIndex
}).toLong()
).let {
if (orderBy != null) {
it.orderBy(
orderBy.first,
orderBy.second
)
} else {
it
}
}
fun Query.paginate(with: Pagination, orderBy: Expression<*>?, reversed: Boolean = false) = paginate(
with,
orderBy ?.let { it to if (reversed) SortOrder.DESC else SortOrder.ASC }
)