mirror of https://github.com/usbharu/Hideout.git
feat: 修正した実装を追加
This commit is contained in:
parent
2efae6f6da
commit
e028da5925
|
@ -1,9 +1,6 @@
|
||||||
package dev.usbharu.hideout.application.infrastructure.exposed
|
package dev.usbharu.hideout.application.infrastructure.exposed
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.ExpressionWithColumnType
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.Query
|
|
||||||
import org.jetbrains.exposed.sql.SortOrder
|
|
||||||
import org.jetbrains.exposed.sql.andWhere
|
|
||||||
|
|
||||||
fun <S> Query.pagination(page: Page, exp: ExpressionWithColumnType<S>): Query {
|
fun <S> Query.pagination(page: Page, exp: ExpressionWithColumnType<S>): Query {
|
||||||
if (page.minId != null) {
|
if (page.minId != null) {
|
||||||
|
@ -17,3 +14,19 @@ fun <S> Query.pagination(page: Page, exp: ExpressionWithColumnType<S>): Query {
|
||||||
page.limit?.let { limit(it) }
|
page.limit?.let { limit(it) }
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <S> Query.withPagination(page: Page, exp: ExpressionWithColumnType<S>): PaginationList<ResultRow, S> {
|
||||||
|
page.limit?.let { limit(it) }
|
||||||
|
val resultRows = if (page.minId != null) {
|
||||||
|
page.maxId?.let { andWhere { exp.less(it) } }
|
||||||
|
page.minId?.let { andWhere { exp.greater(it) } }
|
||||||
|
reversed()
|
||||||
|
} else {
|
||||||
|
page.maxId?.let { andWhere { exp.less(it) } }
|
||||||
|
page.sinceId?.let { andWhere { exp.greater(it) } }
|
||||||
|
orderBy(exp, SortOrder.DESC)
|
||||||
|
toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
return PaginationList(resultRows, resultRows.firstOrNull()?.getOrNull(exp), resultRows.lastOrNull()?.getOrNull(exp))
|
||||||
|
}
|
Loading…
Reference in New Issue