mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-12 07:14:35 -05:00
Feature/update to exposed v0.57.0 (#1150)
* Update to exposed-migrations v3.5.0 * Update to kotlin-logging v7.0.0 * Update to exposed v0.46.0 * Update to exposed v0.47.0 * Update to exposed v0.55.0 * Update to exposed v0.56.0 * Update to exposed v0.57.0
This commit is contained in:
@@ -48,7 +48,7 @@ class CategoryQuery {
|
||||
): CompletableFuture<CategoryType> = dataFetchingEnvironment.getValueFromDataLoader("CategoryDataLoader", id)
|
||||
|
||||
enum class CategoryOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<CategoryType> {
|
||||
ID(CategoryTable.id),
|
||||
NAME(CategoryTable.name),
|
||||
@@ -170,7 +170,7 @@ class CategoryQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class ChapterQuery {
|
||||
): CompletableFuture<ChapterType> = dataFetchingEnvironment.getValueFromDataLoader("ChapterDataLoader", id)
|
||||
|
||||
enum class ChapterOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<ChapterType> {
|
||||
ID(ChapterTable.id),
|
||||
SOURCE_ORDER(ChapterTable.sourceOrder),
|
||||
@@ -254,7 +254,7 @@ class ChapterQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class ExtensionQuery {
|
||||
): CompletableFuture<ExtensionType> = dataFetchingEnvironment.getValueFromDataLoader("ExtensionDataLoader", pkgName)
|
||||
|
||||
enum class ExtensionOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<ExtensionType> {
|
||||
PKG_NAME(ExtensionTable.pkgName),
|
||||
NAME(ExtensionTable.name),
|
||||
@@ -204,7 +204,7 @@ class ExtensionQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.exposed.sql.Op
|
||||
import org.jetbrains.exposed.sql.SortOrder
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.ComparableScalarFilter
|
||||
@@ -29,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
|
||||
@@ -53,7 +51,7 @@ class MangaQuery {
|
||||
): CompletableFuture<MangaType> = dataFetchingEnvironment.getValueFromDataLoader("MangaDataLoader", id)
|
||||
|
||||
enum class MangaOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<MangaType> {
|
||||
ID(MangaTable.id),
|
||||
TITLE(MangaTable.title),
|
||||
@@ -242,11 +240,8 @@ class MangaQuery {
|
||||
val res =
|
||||
MangaTable
|
||||
.leftJoin(CategoryMangaTable)
|
||||
.slice(
|
||||
distinctOn(MangaTable.id),
|
||||
*(MangaTable.columns).toTypedArray(),
|
||||
*(CategoryMangaTable.columns).toTypedArray(),
|
||||
).selectAll()
|
||||
.select(MangaTable.columns)
|
||||
.withDistinctOn(MangaTable.id)
|
||||
|
||||
res.applyOps(condition, filter)
|
||||
|
||||
@@ -274,7 +269,7 @@ class MangaQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class MetaQuery {
|
||||
): CompletableFuture<GlobalMetaType> = dataFetchingEnvironment.getValueFromDataLoader("GlobalMetaDataLoader", key)
|
||||
|
||||
enum class MetaOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<GlobalMetaType> {
|
||||
KEY(GlobalMetaTable.key),
|
||||
VALUE(GlobalMetaTable.value),
|
||||
@@ -154,7 +154,7 @@ class MetaQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class SourceQuery {
|
||||
): CompletableFuture<SourceType> = dataFetchingEnvironment.getValueFromDataLoader("SourceDataLoader", id)
|
||||
|
||||
enum class SourceOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<SourceType> {
|
||||
ID(SourceTable.id),
|
||||
NAME(SourceTable.name),
|
||||
@@ -170,7 +170,7 @@ class SourceQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ class TrackQuery {
|
||||
dataFetchingEnvironment.getValueFromDataLoader<Int, TrackRecordType>("TrackRecordDataLoader", id)
|
||||
|
||||
enum class TrackRecordOrderBy(
|
||||
override val column: Column<out Comparable<*>>,
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<TrackRecordType> {
|
||||
ID(TrackRecordTable.id),
|
||||
MANGA_ID(TrackRecordTable.mangaId),
|
||||
@@ -430,7 +430,7 @@ class TrackQuery {
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first, offset?.toLong() ?: 0)
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
@@ -466,12 +466,12 @@ fun <T : String, S : T?> andFilterWithCompareString(
|
||||
}
|
||||
|
||||
opAnd.andWhere(filter.distinctFromInsensitive, filter.distinctFromInsensitiveAll, filter.distinctFromInsensitiveAny) {
|
||||
DistinctFromOp.distinctFrom(column.upperCase(), it.uppercase() as S)
|
||||
DistinctFromOp.distinctFrom(column.upperCase(), it.uppercase())
|
||||
}
|
||||
opAnd.andWhere(filter.notDistinctFromInsensitive) { DistinctFromOp.notDistinctFrom(column.upperCase(), it.uppercase() as S) }
|
||||
opAnd.andWhere(filter.notDistinctFromInsensitive) { DistinctFromOp.notDistinctFrom(column.upperCase(), it.uppercase()) }
|
||||
|
||||
opAnd.andWhere(filter.inInsensitive) { column.upperCase() inList (it.map { it.uppercase() } as List<S>) }
|
||||
opAnd.andWhere(filter.notInInsensitive) { column.upperCase() notInList (it.map { it.uppercase() } as List<S>) }
|
||||
opAnd.andWhere(filter.inInsensitive) { column.upperCase() inList (it.map { it.uppercase() }) }
|
||||
opAnd.andWhere(filter.notInInsensitive) { column.upperCase() notInList (it.map { it.uppercase() }) }
|
||||
|
||||
opAnd.andWhere(filter.lessThanInsensitive) { column.upperCase() less it.uppercase() }
|
||||
opAnd.andWhere(filter.lessThanOrEqualToInsensitive) { column.upperCase() lessEq it.uppercase() }
|
||||
@@ -539,38 +539,21 @@ class OpAnd(
|
||||
) = andWhere(value) { column eq it }
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Comparable<T>, S : T?> andFilterWithCompare(
|
||||
column: Column<S>,
|
||||
filter: ComparableScalarFilter<T>?,
|
||||
): Op<Boolean>? {
|
||||
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 }
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> andFilterWithCompareEntity(
|
||||
column: Column<EntityID<T>>,
|
||||
filter: ComparableScalarFilter<T>?,
|
||||
): Op<Boolean>? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return andFilterWithCompare(column as Column<T>, filter)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Comparable<T>, S : T?> andFilter(
|
||||
column: Column<S>,
|
||||
filter: ScalarFilter<T>?,
|
||||
): Op<Boolean>? {
|
||||
filter ?: return null
|
||||
val opAnd = OpAnd()
|
||||
|
||||
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) }
|
||||
@@ -581,5 +564,34 @@ fun <T : Comparable<T>, S : T?> andFilter(
|
||||
if (!filter.notIn.isNullOrEmpty()) {
|
||||
opAnd.andWhere(filter.notIn) { column notInList it as List<S> }
|
||||
}
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> andFilterWithCompareEntity(
|
||||
column: Column<EntityID<T>>,
|
||||
filter: ComparableScalarFilter<T>?,
|
||||
): Op<Boolean>? {
|
||||
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 }
|
||||
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 }
|
||||
}
|
||||
if (!filter.notIn.isNullOrEmpty()) {
|
||||
opAnd.andWhere(filter.notIn) { column notInList it }
|
||||
}
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
|
||||
@@ -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<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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user