Fix column distinct
This commit is contained in:
parent
8dd7c7816f
commit
df7c57d9d9
2 changed files with 28 additions and 1 deletions
|
@ -0,0 +1,24 @@
|
|||
package io.github.wulkanowy.schools.dao
|
||||
|
||||
import org.jetbrains.exposed.sql.BooleanColumnType
|
||||
import org.jetbrains.exposed.sql.CustomFunction
|
||||
import org.jetbrains.exposed.sql.Expression
|
||||
import org.jetbrains.exposed.sql.QueryBuilder
|
||||
|
||||
fun customDistinctOn(vararg expressions: Expression<*>): CustomFunction<Boolean?> = customBooleanFunction(
|
||||
functionName = "DISTINCT ON",
|
||||
postfix = " TRUE",
|
||||
params = expressions
|
||||
)
|
||||
|
||||
fun customBooleanFunction(
|
||||
functionName: String, postfix: String = "", vararg params: Expression<*>
|
||||
): CustomFunction<Boolean?> =
|
||||
object : CustomFunction<Boolean?>(functionName, BooleanColumnType(), *params) {
|
||||
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
|
||||
super.toQueryBuilder(queryBuilder)
|
||||
if (postfix.isNotEmpty()) {
|
||||
queryBuilder.append(postfix)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,8 +29,11 @@ class LoginEventDao {
|
|||
order: SortOrder?,
|
||||
): List<LoginEvent> = dbQuery {
|
||||
LoginEvents
|
||||
.slice(
|
||||
customDistinctOn(LoginEvents.schoolId, LoginEvents.symbol, LoginEvents.scraperBaseUrl),
|
||||
*(LoginEvents.columns).toTypedArray()
|
||||
)
|
||||
.selectAll()
|
||||
.groupBy(LoginEvents.schoolId, LoginEvents.symbol, LoginEvents.scraperBaseUrl)
|
||||
.limit(pageSize, page * pageSize)
|
||||
.let {
|
||||
if (orderBy != null && order != null) {
|
||||
|
|
Loading…
Reference in a new issue