From 3d3e4f245b13c7ec4fbbbef9e3a76d1a70e7ffbd Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 17 Nov 2024 17:29:07 +0100 Subject: [PATCH] Update to exposed v0.56.0 --- gradle/libs.versions.toml | 2 +- .../graphql/queries/CategoryQuery.kt | 2 +- .../tachidesk/graphql/queries/ChapterQuery.kt | 2 +- .../graphql/queries/ExtensionQuery.kt | 2 +- .../tachidesk/graphql/queries/MangaQuery.kt | 10 ++--- .../tachidesk/graphql/queries/MetaQuery.kt | 2 +- .../tachidesk/graphql/queries/SourceQuery.kt | 2 +- .../tachidesk/graphql/queries/TrackQuery.kt | 2 +- .../graphql/queries/filter/Filter.kt | 44 ++++++++++++------- .../graphql/queries/util/CustomDistinctOn.kt | 31 ------------- .../graphql/server/primitives/OrderBy.kt | 2 +- 11 files changed, 39 insertions(+), 62 deletions(-) delete mode 100644 server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/util/CustomDistinctOn.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4ce499e0e9..70e62bf302 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ serialization = "1.7.3" okhttp = "5.0.0-alpha.14" # Major version is locked by Tachiyomi extensions javalin = "6.3.0" jackson = "2.18.2" # jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency` -exposed = "0.55.0" +exposed = "0.56.0" dex2jar = "v64" # Stuck until https://github.com/ThexXTURBOXx/dex2jar/issues/27 is fixed polyglot = "24.1.1" settings = "1.3.0" diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/CategoryQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/CategoryQuery.kt index ca16d0cd45..46526bf4aa 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/CategoryQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/CategoryQuery.kt @@ -48,7 +48,7 @@ class CategoryQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("CategoryDataLoader", id) enum class CategoryOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { ID(CategoryTable.id), NAME(CategoryTable.name), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt index 0a5ae6bf83..9f5776acb9 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt @@ -57,7 +57,7 @@ class ChapterQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("ChapterDataLoader", id) enum class ChapterOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { ID(ChapterTable.id), SOURCE_ORDER(ChapterTable.sourceOrder), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ExtensionQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ExtensionQuery.kt index 4abeaf5d9f..10f855ee19 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ExtensionQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ExtensionQuery.kt @@ -49,7 +49,7 @@ class ExtensionQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("ExtensionDataLoader", pkgName) enum class ExtensionOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { PKG_NAME(ExtensionTable.pkgName), NAME(ExtensionTable.name), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt index c8c8714843..d823f90db4 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MangaQuery.kt @@ -28,7 +28,6 @@ import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompare import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString import suwayomi.tachidesk.graphql.queries.filter.applyOps -import suwayomi.tachidesk.graphql.queries.util.distinctOn import suwayomi.tachidesk.graphql.server.primitives.Cursor import suwayomi.tachidesk.graphql.server.primitives.Order import suwayomi.tachidesk.graphql.server.primitives.OrderBy @@ -52,7 +51,7 @@ class MangaQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("MangaDataLoader", id) enum class MangaOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { ID(MangaTable.id), TITLE(MangaTable.title), @@ -241,11 +240,8 @@ class MangaQuery { val res = MangaTable .leftJoin(CategoryMangaTable) - .select( - distinctOn(MangaTable.id), - *(MangaTable.columns).toTypedArray(), - *(CategoryMangaTable.columns).toTypedArray(), - ) + .select(MangaTable.columns) + .withDistinctOn(MangaTable.id) res.applyOps(condition, filter) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MetaQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MetaQuery.kt index 5f8569adee..a00b3a5a19 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MetaQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/MetaQuery.kt @@ -44,7 +44,7 @@ class MetaQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("GlobalMetaDataLoader", key) enum class MetaOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { KEY(GlobalMetaTable.key), VALUE(GlobalMetaTable.value), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/SourceQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/SourceQuery.kt index a31856cecc..8c0667fcb3 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/SourceQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/SourceQuery.kt @@ -48,7 +48,7 @@ class SourceQuery { ): CompletableFuture = dataFetchingEnvironment.getValueFromDataLoader("SourceDataLoader", id) enum class SourceOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { ID(SourceTable.id), NAME(SourceTable.name), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/TrackQuery.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/TrackQuery.kt index fd7be60a71..22ebec1b41 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/TrackQuery.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/TrackQuery.kt @@ -244,7 +244,7 @@ class TrackQuery { dataFetchingEnvironment.getValueFromDataLoader("TrackRecordDataLoader", id) enum class TrackRecordOrderBy( - override val column: Column>, + override val column: Column<*>, ) : OrderBy { ID(TrackRecordTable.id), MANGA_ID(TrackRecordTable.mangaId), diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt index 7fc6f9bca1..19a4c077ba 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/filter/Filter.kt @@ -539,47 +539,59 @@ class OpAnd( ) = andWhere(value) { column eq it } } +@Suppress("UNCHECKED_CAST") fun , S : T?> andFilterWithCompare( column: Column, filter: ComparableScalarFilter?, ): Op? { filter ?: return null - val opAnd = OpAnd(andFilter(column, filter)) + val opAnd = OpAnd() opAnd.andWhere(filter.lessThan) { column less it } opAnd.andWhere(filter.lessThanOrEqualTo) { column lessEq it } opAnd.andWhere(filter.greaterThan) { column greater it } opAnd.andWhere(filter.greaterThanOrEqualTo) { column greaterEq it } + opAnd.andWhere(filter.isNull) { if (it) column.isNull() else column.isNotNull() } + + opAnd.andWhere(filter.equalTo) { column eq it as S } + opAnd.andWhere(filter.notEqualTo, filter.notEqualToAll, filter.notEqualToAny) { column neq it as S } + opAnd.andWhere(filter.distinctFrom, filter.distinctFromAll, filter.distinctFromAny) { DistinctFromOp.distinctFrom(column, it as S) } + opAnd.andWhere(filter.notDistinctFrom) { DistinctFromOp.notDistinctFrom(column, it as S) } + if (!filter.`in`.isNullOrEmpty()) { + opAnd.andWhere(filter.`in`) { column inList it as List } + } + if (!filter.notIn.isNullOrEmpty()) { + opAnd.andWhere(filter.notIn) { column notInList it as List } + } + return opAnd.op } fun > andFilterWithCompareEntity( column: Column>, filter: ComparableScalarFilter?, -): Op? { - @Suppress("UNCHECKED_CAST") - return andFilterWithCompare(column as Column, filter) -} - -@Suppress("UNCHECKED_CAST") -fun , S : T?> andFilter( - column: Column, - filter: ScalarFilter?, ): Op? { filter ?: return null val opAnd = OpAnd() + opAnd.andWhere(filter.lessThan) { column less it } + opAnd.andWhere(filter.lessThanOrEqualTo) { column lessEq it } + opAnd.andWhere(filter.greaterThan) { column greater it } + opAnd.andWhere(filter.greaterThanOrEqualTo) { column greaterEq it } + opAnd.andWhere(filter.isNull) { if (it) column.isNull() else column.isNotNull() } - opAnd.andWhere(filter.equalTo) { column eq it as S } - opAnd.andWhere(filter.notEqualTo, filter.notEqualToAll, filter.notEqualToAny) { column neq it as S } - opAnd.andWhere(filter.distinctFrom, filter.distinctFromAll, filter.distinctFromAny) { DistinctFromOp.distinctFrom(column, it as S) } - opAnd.andWhere(filter.notDistinctFrom) { DistinctFromOp.notDistinctFrom(column, it as S) } + + opAnd.andWhere(filter.equalTo) { column eq it } + opAnd.andWhere(filter.notEqualTo, filter.notEqualToAll, filter.notEqualToAny) { column neq it } + opAnd.andWhere(filter.distinctFrom, filter.distinctFromAll, filter.distinctFromAny) { DistinctFromOp.distinctFrom(column, it) } + opAnd.andWhere(filter.notDistinctFrom) { DistinctFromOp.notDistinctFrom(column, it) } if (!filter.`in`.isNullOrEmpty()) { - opAnd.andWhere(filter.`in`) { column inList it as List } + opAnd.andWhere(filter.`in`) { column inList it } } if (!filter.notIn.isNullOrEmpty()) { - opAnd.andWhere(filter.notIn) { column notInList it as List } + opAnd.andWhere(filter.notIn) { column notInList it } } + return opAnd.op } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/util/CustomDistinctOn.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/util/CustomDistinctOn.kt deleted file mode 100644 index b91122b509..0000000000 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/util/CustomDistinctOn.kt +++ /dev/null @@ -1,31 +0,0 @@ -package suwayomi.tachidesk.graphql.queries.util - -import org.jetbrains.exposed.sql.BooleanColumnType -import org.jetbrains.exposed.sql.CustomFunction -import org.jetbrains.exposed.sql.Expression -import org.jetbrains.exposed.sql.QueryBuilder - -/** - * src: https://github.com/JetBrains/Exposed/issues/500#issuecomment-543574151 (2024-04-02 02:20) - */ - -fun distinctOn(vararg expressions: Expression<*>): CustomFunction = - customBooleanFunction( - functionName = "DISTINCT ON", - postfix = " TRUE", - params = expressions, - ) - -fun customBooleanFunction( - functionName: String, - postfix: String = "", - vararg params: Expression<*>, -): CustomFunction = - object : CustomFunction(functionName, BooleanColumnType(), *params) { - override fun toQueryBuilder(queryBuilder: QueryBuilder) { - super.toQueryBuilder(queryBuilder) - if (postfix.isNotEmpty()) { - queryBuilder.append(postfix) - } - } - } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/OrderBy.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/OrderBy.kt index 2ac1fc4ca0..d0b495c398 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/OrderBy.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/primitives/OrderBy.kt @@ -13,7 +13,7 @@ import org.jetbrains.exposed.sql.andWhere import org.jetbrains.exposed.sql.or interface OrderBy { - val column: Column> + val column: Column<*> fun asCursor(type: T): Cursor