start add standard repo utils
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
package com.insanusmokrassar.postssystem.exposed.commons
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.firstIndex
|
||||
import org.jetbrains.exposed.sql.Query
|
||||
import com.insanusmokrassar.postssystem.utils.repos.pagination.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
|
||||
fun Query.paginate(pagination: Pagination) = limit(pagination.size, pagination.firstIndex.toLong())
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user