Skip to content

Commit

Permalink
EVA-PIMP multiple order by in repo (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rattenkrieg committed Feb 28, 2024
1 parent bba995d commit 0b733d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/CI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.lang.Boolean.parseBoolean
object Ci {

private const val SNAPSHOT_BASE = "0.7.0"
private const val RELEASE_VERSION = "0.6.1"
private const val RELEASE_VERSION = "0.6.2"
private val githubSha = System.getenv("GITHUB_SHA") ?: "latest"

val publishRelease = System.getProperty("release", "true").let(::parseBoolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,14 @@ abstract class JooqBaseModelRepository<ID, MID, M, ME, R>(

protected suspend fun findLast(
condition: Condition,
sortField: TableField<R, *>
): M? = findAllWhere(condition, sortField.desc(), 1).singleOrNull()
sortField: TableField<R, *>,
sortFields: Array<TableField<R, *>> = emptyArray(),
): M? = findAllWhere(
condition = condition,
sortField = sortField.desc(),
sortFields = sortFields.map(TableField<R, *>::desc).toTypedArray(),
limit = 1,
).singleOrNull()

/**
* If page is not first, we use JOOQ 'seek' method to find position of page
Expand Down Expand Up @@ -322,18 +328,19 @@ abstract class JooqBaseModelRepository<ID, MID, M, ME, R>(

private fun <N, S, P> SelectConditionStep<R>.page(
page: Page<P>,
pagingStrategy: PagingStrategy<ID, N, S, P, R>
pagingStrategy: PagingStrategy<ID, N, S, P, R>,
) where S : N, P : Comparable<P> = pagingStrategy.select(this, page)

protected suspend fun findAllWhere(
condition: Condition,
sortField: SortField<*>? = null,
limit: Int = MAX_RETURNED_RECORDS
sortFields: Array<SortField<*>> = emptyArray(),
limit: Int = MAX_RETURNED_RECORDS,
): List<M> {
val select = dslContext.selectFrom(table)
.where(condition)
return if (sortField != null) {
findAll(select.orderBy(sortField).limit(limit))
findAll(select.orderBy(sortField, *sortFields).limit(limit))
} else {
findAll(select.limit(limit))
}
Expand Down

0 comments on commit 0b733d6

Please sign in to comment.