implemented coroutines and exposed utils

This commit is contained in:
000Sanya
2020-09-24 12:27:16 +10:00
parent 1dcf17a35d
commit 5a5519c7cb
17 changed files with 113 additions and 15 deletions

16
exposed/build.gradle Normal file
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 {
}
}
}
}

View File

@@ -0,0 +1,27 @@
package dev.inmo.micro_utils.exposed
import 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 }
)