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:
schroda
2024-12-08 05:49:11 +01:00
committed by GitHub
parent f926714544
commit 1d541a30ae
87 changed files with 463 additions and 359 deletions

View File

@@ -2,7 +2,7 @@ package suwayomi.tachidesk.graphql
import com.expediagroup.graphql.server.extensions.toGraphQLError
import graphql.execution.DataFetcherResult
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
val logger = KotlinLogging.logger { }

View File

@@ -13,7 +13,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.CategoryNodeList
import suwayomi.tachidesk.graphql.types.CategoryNodeList.Companion.toNodeList
@@ -32,7 +32,8 @@ class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
addLogger(Slf4jSqlDebugLogger)
val categories =
CategoryTable
.select { CategoryTable.id inList ids }
.selectAll()
.where { CategoryTable.id inList ids }
.map { CategoryType(it) }
.associateBy { it.id }
ids.map { categories[it] }
@@ -50,7 +51,7 @@ class CategoryForIdsDataLoader : KotlinDataLoader<List<Int>, CategoryNodeList> {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = categoryIds.flatten().distinct()
val categories = CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
val categories = CategoryTable.selectAll().where { CategoryTable.id inList ids }.map { CategoryType(it) }
categoryIds.map { categoryIds ->
categories.filter { it.id in categoryIds }.toNodeList()
}
@@ -70,7 +71,8 @@ class CategoriesForMangaDataLoader : KotlinDataLoader<Int, CategoryNodeList> {
val itemsByRef =
CategoryMangaTable
.innerJoin(CategoryTable)
.select { CategoryMangaTable.manga inList ids }
.selectAll()
.where { CategoryMangaTable.manga inList ids }
.map { Pair(it[CategoryMangaTable.manga].value, CategoryType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }

View File

@@ -16,7 +16,7 @@ import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.count
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.ChapterNodeList
import suwayomi.tachidesk.graphql.types.ChapterNodeList.Companion.toNodeList
@@ -34,7 +34,8 @@ class ChapterDataLoader : KotlinDataLoader<Int, ChapterType?> {
addLogger(Slf4jSqlDebugLogger)
val chapters =
ChapterTable
.select { ChapterTable.id inList ids }
.selectAll()
.where { ChapterTable.id inList ids }
.map { ChapterType(it) }
.associateBy { it.id }
ids.map { chapters[it] }
@@ -53,7 +54,8 @@ class ChaptersForMangaDataLoader : KotlinDataLoader<Int, ChapterNodeList> {
addLogger(Slf4jSqlDebugLogger)
val chaptersByMangaId =
ChapterTable
.select { ChapterTable.manga inList ids }
.selectAll()
.where { ChapterTable.manga inList ids }
.map { ChapterType(it) }
.groupBy { it.mangaId }
ids.map { (chaptersByMangaId[it] ?: emptyList()).toNodeList() }
@@ -72,9 +74,11 @@ class DownloadedChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val downloadedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isDownloaded.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isDownloaded eq true) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isDownloaded.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isDownloaded eq true)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isDownloaded.count()] }
ids.map { downloadedChapterCountByMangaId[it]?.toInt() ?: 0 }
}
@@ -92,9 +96,11 @@ class UnreadChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val unreadChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isRead.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isRead.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isRead eq false)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isRead.count()] }
ids.map { unreadChapterCountByMangaId[it]?.toInt() ?: 0 }
}
@@ -112,9 +118,11 @@ class BookmarkedChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
addLogger(Slf4jSqlDebugLogger)
val bookmarkedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isBookmarked.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isBookmarked eq true) }
.groupBy(ChapterTable.manga)
.select(ChapterTable.manga, ChapterTable.isBookmarked.count())
.where {
(ChapterTable.manga inList ids) and
(ChapterTable.isBookmarked eq true)
}.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isBookmarked.count()] }
ids.map { bookmarkedChapterCountByMangaId[it]?.toInt() ?: 0 }
}
@@ -132,9 +140,14 @@ class HasDuplicateChaptersForMangaDataLoader : KotlinDataLoader<Int, Boolean> {
addLogger(Slf4jSqlDebugLogger)
val duplicatedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.chapter_number, ChapterTable.chapter_number.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.chapter_number greaterEq 0f) }
.groupBy(ChapterTable.manga, ChapterTable.chapter_number)
.select(ChapterTable.manga, ChapterTable.chapter_number, ChapterTable.chapter_number.count())
.where {
(
ChapterTable.manga inList
ids
) and
(ChapterTable.chapter_number greaterEq 0f)
}.groupBy(ChapterTable.manga, ChapterTable.chapter_number)
.having { ChapterTable.chapter_number.count() greater 1 }
.associate { it[ChapterTable.manga].value to it[ChapterTable.chapter_number.count()] }
@@ -154,7 +167,8 @@ class LastReadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?> {
addLogger(Slf4jSqlDebugLogger)
val lastReadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.lastReadAt to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> lastReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
@@ -173,7 +187,8 @@ class LatestReadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?>
addLogger(Slf4jSqlDebugLogger)
val latestReadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.selectAll()
.where { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
@@ -192,7 +207,8 @@ class LatestFetchedChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType
addLogger(Slf4jSqlDebugLogger)
val latestFetchedChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.fetchedAt to SortOrder.DESC, ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestFetchedChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
@@ -211,7 +227,8 @@ class LatestUploadedChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterTyp
addLogger(Slf4jSqlDebugLogger)
val latestUploadedChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) }
.selectAll()
.where { (ChapterTable.manga inList ids) }
.orderBy(ChapterTable.date_upload to SortOrder.DESC, ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> latestUploadedChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
@@ -230,7 +247,8 @@ class FirstUnreadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?>
addLogger(Slf4jSqlDebugLogger)
val firstUnreadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.selectAll()
.where { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.orderBy(ChapterTable.sourceOrder to SortOrder.ASC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> firstUnreadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }

View File

@@ -13,7 +13,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.ExtensionType
import suwayomi.tachidesk.manga.model.table.ExtensionTable
@@ -30,7 +30,8 @@ class ExtensionDataLoader : KotlinDataLoader<String, ExtensionType?> {
addLogger(Slf4jSqlDebugLogger)
val extensions =
ExtensionTable
.select { ExtensionTable.pkgName inList ids }
.selectAll()
.where { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
.associateBy { it.pkgName }
ids.map { extensions[it] }
@@ -50,7 +51,8 @@ class ExtensionForSourceDataLoader : KotlinDataLoader<Long, ExtensionType?> {
val extensions =
ExtensionTable
.innerJoin(SourceTable)
.select { SourceTable.id inList ids }
.selectAll()
.where { SourceTable.id inList ids }
.toList()
.map { Triple(it[SourceTable.id].value, it[ExtensionTable.pkgName], it) }
.let { triples ->

View File

@@ -15,7 +15,7 @@ import org.dataloader.DataLoaderOptions
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.andWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.cache.CustomCacheMap
import suwayomi.tachidesk.graphql.types.MangaNodeList
@@ -35,7 +35,8 @@ class MangaDataLoader : KotlinDataLoader<Int, MangaType?> {
addLogger(Slf4jSqlDebugLogger)
val manga =
MangaTable
.select { MangaTable.id inList ids }
.selectAll()
.where { MangaTable.id inList ids }
.map { MangaType(it) }
.associateBy { it.id }
ids.map { manga[it] }
@@ -56,7 +57,8 @@ class MangaForCategoryDataLoader : KotlinDataLoader<Int, MangaNodeList> {
if (ids.contains(0)) {
MangaTable
.leftJoin(CategoryMangaTable)
.select { MangaTable.inLibrary eq true }
.selectAll()
.where { MangaTable.inLibrary eq true }
.andWhere { CategoryMangaTable.manga.isNull() }
.map { MangaType(it) }
.let {
@@ -67,7 +69,8 @@ class MangaForCategoryDataLoader : KotlinDataLoader<Int, MangaNodeList> {
} +
CategoryMangaTable
.innerJoin(MangaTable)
.select { CategoryMangaTable.category inList ids }
.selectAll()
.where { CategoryMangaTable.category inList ids }
.map { Pair(it[CategoryMangaTable.category].value, MangaType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
@@ -88,7 +91,8 @@ class MangaForSourceDataLoader : KotlinDataLoader<Long, MangaNodeList> {
addLogger(Slf4jSqlDebugLogger)
val mangaBySourceId =
MangaTable
.select { MangaTable.sourceReference inList ids }
.selectAll()
.where { MangaTable.sourceReference inList ids }
.map { MangaType(it) }
.groupBy { it.sourceId }
ids.map { (mangaBySourceId[it] ?: emptyList()).toNodeList() }
@@ -109,7 +113,8 @@ class MangaForIdsDataLoader : KotlinDataLoader<List<Int>, MangaNodeList> {
val ids = mangaIds.flatten().distinct()
val manga =
MangaTable
.select { MangaTable.id inList ids }
.selectAll()
.where { MangaTable.id inList ids }
.map { MangaType(it) }
mangaIds.map { mangaIds ->
manga.filter { it.id in mangaIds }.toNodeList()

View File

@@ -6,7 +6,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.global.model.table.GlobalMetaTable
import suwayomi.tachidesk.graphql.types.CategoryMetaType
@@ -30,7 +30,8 @@ class GlobalMetaDataLoader : KotlinDataLoader<String, GlobalMetaType?> {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
GlobalMetaTable
.select { GlobalMetaTable.key inList ids }
.selectAll()
.where { GlobalMetaTable.key inList ids }
.map { GlobalMetaType(it) }
.associateBy { it.key }
ids.map { metasByRefId[it] }
@@ -49,7 +50,8 @@ class ChapterMetaDataLoader : KotlinDataLoader<Int, List<ChapterMetaType>> {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
ChapterMetaTable
.select { ChapterMetaTable.ref inList ids }
.selectAll()
.where { ChapterMetaTable.ref inList ids }
.map { ChapterMetaType(it) }
.groupBy { it.chapterId }
ids.map { metasByRefId[it].orEmpty() }
@@ -68,7 +70,8 @@ class MangaMetaDataLoader : KotlinDataLoader<Int, List<MangaMetaType>> {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
MangaMetaTable
.select { MangaMetaTable.ref inList ids }
.selectAll()
.where { MangaMetaTable.ref inList ids }
.map { MangaMetaType(it) }
.groupBy { it.mangaId }
ids.map { metasByRefId[it].orEmpty() }
@@ -87,7 +90,8 @@ class CategoryMetaDataLoader : KotlinDataLoader<Int, List<CategoryMetaType>> {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
CategoryMetaTable
.select { CategoryMetaTable.ref inList ids }
.selectAll()
.where { CategoryMetaTable.ref inList ids }
.map { CategoryMetaType(it) }
.groupBy { it.categoryId }
ids.map { metasByRefId[it].orEmpty() }
@@ -106,7 +110,8 @@ class SourceMetaDataLoader : KotlinDataLoader<Long, List<SourceMetaType>> {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
SourceMetaTable
.select { SourceMetaTable.ref inList ids }
.selectAll()
.where { SourceMetaTable.ref inList ids }
.map { SourceMetaType(it) }
.groupBy { it.sourceId }
ids.map { metasByRefId[it].orEmpty() }

View File

@@ -13,7 +13,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.SourceNodeList
import suwayomi.tachidesk.graphql.types.SourceNodeList.Companion.toNodeList
@@ -32,7 +32,8 @@ class SourceDataLoader : KotlinDataLoader<Long, SourceType?> {
addLogger(Slf4jSqlDebugLogger)
val source =
SourceTable
.select { SourceTable.id inList ids }
.selectAll()
.where { SourceTable.id inList ids }
.mapNotNull { SourceType(it) }
.associateBy { it.id }
ids.map { source[it] }
@@ -53,7 +54,8 @@ class SourcesForExtensionDataLoader : KotlinDataLoader<String, SourceNodeList> {
val sourcesByExtensionPkg =
SourceTable
.innerJoin(ExtensionTable)
.select { ExtensionTable.pkgName inList ids }
.selectAll()
.where { ExtensionTable.pkgName inList ids }
.map { Pair(it[ExtensionTable.pkgName], SourceType(it)) }
.groupBy { it.first }
.mapValues { it.value.mapNotNull { pair -> pair.second } }

View File

@@ -13,7 +13,7 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.jetbrains.exposed.sql.Slf4jSqlDebugLogger
import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.types.TrackRecordNodeList
import suwayomi.tachidesk.graphql.types.TrackRecordNodeList.Companion.toNodeList
@@ -91,7 +91,8 @@ class TrackRecordsForMangaIdDataLoader : KotlinDataLoader<Int, TrackRecordNodeLi
addLogger(Slf4jSqlDebugLogger)
val trackRecordsByMangaId =
TrackRecordTable
.select { TrackRecordTable.mangaId inList ids }
.selectAll()
.where { TrackRecordTable.mangaId inList ids }
.map { TrackRecordType(it) }
.groupBy { it.mangaId }
ids.map { (trackRecordsByMangaId[it] ?: emptyList()).toNodeList() }
@@ -110,7 +111,8 @@ class DisplayScoreForTrackRecordDataLoader : KotlinDataLoader<Int, String> {
addLogger(Slf4jSqlDebugLogger)
val trackRecords =
TrackRecordTable
.select { TrackRecordTable.id inList ids }
.selectAll()
.where { TrackRecordTable.id inList ids }
.toList()
.map { it.toTrack() }
.associateBy { it.id!! }
@@ -132,7 +134,8 @@ class TrackRecordsForTrackerIdDataLoader : KotlinDataLoader<Int, TrackRecordNode
addLogger(Slf4jSqlDebugLogger)
val trackRecordsBySyncId =
TrackRecordTable
.select { TrackRecordTable.trackerId inList ids }
.selectAll()
.where { TrackRecordTable.trackerId inList ids }
.map { TrackRecordType(it) }
.groupBy { it.trackerId }
ids.map { (trackRecordsBySyncId[it] ?: emptyList()).toNodeList() }
@@ -151,7 +154,8 @@ class TrackRecordDataLoader : KotlinDataLoader<Int, TrackRecordType> {
addLogger(Slf4jSqlDebugLogger)
val trackRecordsId =
TrackRecordTable
.select { TrackRecordTable.id inList ids }
.selectAll()
.where { TrackRecordTable.id inList ids }
.map { TrackRecordType(it) }
.associateBy { it.id }
ids.map { trackRecordsId[it] }

View File

@@ -9,7 +9,6 @@ import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.batchInsert
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
@@ -67,14 +66,15 @@ class CategoryMutation {
transaction {
val meta =
CategoryMetaTable
.select { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
.selectAll()
.where { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
.firstOrNull()
CategoryMetaTable.deleteWhere { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
val category =
transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq categoryId }.first())
CategoryType(CategoryTable.selectAll().where { CategoryTable.id eq categoryId }.first())
}
if (meta != null) {
@@ -160,7 +160,7 @@ class CategoryMutation {
val category =
transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
CategoryType(CategoryTable.selectAll().where { CategoryTable.id eq id }.first())
}
UpdateCategoryPayload(
@@ -177,7 +177,7 @@ class CategoryMutation {
val categories =
transaction {
CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
CategoryTable.selectAll().where { CategoryTable.id inList ids }.map { CategoryType(it) }
}
UpdateCategoriesPayload(
@@ -207,7 +207,8 @@ class CategoryMutation {
transaction {
val currentOrder =
CategoryTable
.select { CategoryTable.id eq categoryId }
.selectAll()
.where { CategoryTable.id eq categoryId }
.first()[CategoryTable.order]
if (currentOrder != position) {
@@ -258,7 +259,7 @@ class CategoryMutation {
asDataFetcherResult {
val (clientMutationId, name, order, default, includeInUpdate, includeInDownload) = input
transaction {
require(CategoryTable.select { CategoryTable.name eq input.name }.isEmpty()) {
require(CategoryTable.selectAll().where { CategoryTable.name eq input.name }.isEmpty()) {
"'name' must be unique"
}
}
@@ -296,7 +297,7 @@ class CategoryMutation {
Category.normalizeCategories()
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
CategoryType(CategoryTable.selectAll().where { CategoryTable.id eq id }.first())
}
CreateCategoryPayload(clientMutationId, category)
@@ -328,14 +329,16 @@ class CategoryMutation {
transaction {
val category =
CategoryTable
.select { CategoryTable.id eq categoryId }
.selectAll()
.where { CategoryTable.id eq categoryId }
.firstOrNull()
val mangas =
transaction {
MangaTable
.innerJoin(CategoryMangaTable)
.select { CategoryMangaTable.category eq categoryId }
.selectAll()
.where { CategoryMangaTable.category eq categoryId }
.map { MangaType(it) }
}
@@ -401,7 +404,8 @@ class CategoryMutation {
patch.addToCategories.forEach { categoryId ->
val existingMapping =
CategoryMangaTable
.select {
.selectAll()
.where {
(CategoryMangaTable.manga eq mangaId) and (CategoryMangaTable.category eq categoryId)
}.isNotEmpty()
@@ -428,7 +432,7 @@ class CategoryMutation {
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
MangaType(MangaTable.selectAll().where { MangaTable.id eq id }.first())
}
UpdateMangaCategoriesPayload(
@@ -445,7 +449,7 @@ class CategoryMutation {
val mangas =
transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
MangaTable.selectAll().where { MangaTable.id inList ids }.map { MangaType(it) }
}
UpdateMangasCategoriesPayload(

View File

@@ -5,7 +5,7 @@ import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.statements.BatchUpdateStatement
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
@@ -65,8 +65,8 @@ class ChapterMutation {
val chapterIdToPageCount =
if (patch.lastPageRead != null) {
ChapterTable
.slice(ChapterTable.id, ChapterTable.pageCount)
.select { ChapterTable.id inList ids }
.select(ChapterTable.id, ChapterTable.pageCount)
.where { ChapterTable.id inList ids }
.groupBy { it[ChapterTable.id].value }
.mapValues { it.value.firstOrNull()?.let { it[ChapterTable.pageCount] } }
} else {
@@ -103,7 +103,7 @@ class ChapterMutation {
val chapter =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq id }.first())
ChapterType(ChapterTable.selectAll().where { ChapterTable.id eq id }.first())
}
UpdateChapterPayload(
@@ -120,7 +120,7 @@ class ChapterMutation {
val chapters =
transaction {
ChapterTable.select { ChapterTable.id inList ids }.map { ChapterType(it) }
ChapterTable.selectAll().where { ChapterTable.id inList ids }.map { ChapterType(it) }
}
UpdateChaptersPayload(
@@ -149,7 +149,8 @@ class ChapterMutation {
val chapters =
transaction {
ChapterTable
.select { ChapterTable.manga eq mangaId }
.selectAll()
.where { ChapterTable.manga eq mangaId }
.orderBy(ChapterTable.sourceOrder)
.map { ChapterType(it) }
}
@@ -201,14 +202,15 @@ class ChapterMutation {
transaction {
val meta =
ChapterMetaTable
.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
.selectAll()
.where { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
.firstOrNull()
ChapterMetaTable.deleteWhere { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
val chapter =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapterId }.first())
ChapterType(ChapterTable.selectAll().where { ChapterTable.id eq chapterId }.first())
}
if (meta != null) {

View File

@@ -3,7 +3,7 @@ package suwayomi.tachidesk.graphql.mutations
import graphql.execution.DataFetcherResult
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withTimeout
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.types.ChapterType
@@ -39,7 +39,8 @@ class DownloadMutation {
chapters =
transaction {
ChapterTable
.select { ChapterTable.id inList chapters }
.selectAll()
.where { ChapterTable.id inList chapters }
.map { ChapterType(it) }
},
)
@@ -66,7 +67,7 @@ class DownloadMutation {
clientMutationId = clientMutationId,
chapters =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapter }.first())
ChapterType(ChapterTable.selectAll().where { ChapterTable.id eq chapter }.first())
},
)
}

View File

@@ -3,7 +3,7 @@ package suwayomi.tachidesk.graphql.mutations
import eu.kanade.tachiyomi.source.local.LocalSource
import graphql.execution.DataFetcherResult
import io.javalin.http.UploadedFile
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.types.ExtensionType
@@ -49,7 +49,8 @@ class ExtensionMutation {
val extensions =
transaction {
ExtensionTable
.select { ExtensionTable.pkgName inList ids }
.selectAll()
.where { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
@@ -82,7 +83,8 @@ class ExtensionMutation {
val extension =
transaction {
ExtensionTable
.select { ExtensionTable.pkgName eq id }
.selectAll()
.where { ExtensionTable.pkgName eq id }
.firstOrNull()
?.let { ExtensionType(it) }
}
@@ -105,7 +107,8 @@ class ExtensionMutation {
val extensions =
transaction {
ExtensionTable
.select { ExtensionTable.pkgName inList ids }
.selectAll()
.where { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
@@ -136,7 +139,8 @@ class ExtensionMutation {
val extensions =
transaction {
ExtensionTable
.select { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
.selectAll()
.where { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
.map { ExtensionType(it) }
}
@@ -167,7 +171,8 @@ class ExtensionMutation {
asDataFetcherResult {
Extension.installExternalExtension(extensionFile.content(), extensionFile.filename())
val dbExtension = transaction { ExtensionTable.select { ExtensionTable.apkName eq extensionFile.filename() }.first() }
val dbExtension =
transaction { ExtensionTable.selectAll().where { ExtensionTable.apkName eq extensionFile.filename() }.first() }
InstallExternalExtensionPayload(
clientMutationId,

View File

@@ -4,7 +4,7 @@ import graphql.execution.DataFetcherResult
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.graphql.asDataFetcherResult
@@ -75,7 +75,8 @@ class MangaMutation {
val mangas =
transaction {
MangaTable
.select { (MangaTable.id inList ids) and (MangaTable.initialized eq false) }
.selectAll()
.where { (MangaTable.id inList ids) and (MangaTable.initialized eq false) }
.map { MangaTable.toDataClass(it) }
}
@@ -98,7 +99,7 @@ class MangaMutation {
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
MangaType(MangaTable.selectAll().where { MangaTable.id eq id }.first())
}
UpdateMangaPayload(
@@ -118,7 +119,7 @@ class MangaMutation {
val mangas =
transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
MangaTable.selectAll().where { MangaTable.id inList ids }.map { MangaType(it) }
}
UpdateMangasPayload(
@@ -148,7 +149,7 @@ class MangaMutation {
val manga =
transaction {
MangaTable.select { MangaTable.id eq id }.first()
MangaTable.selectAll().where { MangaTable.id eq id }.first()
}
FetchMangaPayload(
clientMutationId = clientMutationId,
@@ -198,14 +199,15 @@ class MangaMutation {
transaction {
val meta =
MangaMetaTable
.select { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
.selectAll()
.where { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
.firstOrNull()
MangaMetaTable.deleteWhere { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq mangaId }.first())
MangaType(MangaTable.selectAll().where { MangaTable.id eq mangaId }.first())
}
if (meta != null) {

View File

@@ -3,7 +3,7 @@ package suwayomi.tachidesk.graphql.mutations
import graphql.execution.DataFetcherResult
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.global.impl.GlobalMeta
import suwayomi.tachidesk.global.model.table.GlobalMetaTable
@@ -49,7 +49,8 @@ class MetaMutation {
transaction {
val meta =
GlobalMetaTable
.select { GlobalMetaTable.key eq key }
.selectAll()
.where { GlobalMetaTable.key eq key }
.firstOrNull()
GlobalMetaTable.deleteWhere { GlobalMetaTable.key eq key }

View File

@@ -9,7 +9,7 @@ import graphql.execution.DataFetcherResult
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.types.FilterChange
@@ -69,7 +69,8 @@ class SourceMutation {
transaction {
val meta =
SourceMetaTable
.select { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
.selectAll()
.where { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
.firstOrNull()
SourceMetaTable.deleteWhere { (SourceMetaTable.ref eq sourceId) and (SourceMetaTable.key eq key) }
@@ -77,7 +78,8 @@ class SourceMutation {
val source =
transaction {
SourceTable
.select { SourceTable.id eq sourceId }
.selectAll()
.where { SourceTable.id eq sourceId }
.firstOrNull()
?.let { SourceType(it) }
}
@@ -143,7 +145,8 @@ class SourceMutation {
val mangas =
transaction {
MangaTable
.select { MangaTable.id inList mangaIds }
.selectAll()
.where { MangaTable.id inList mangaIds }
.map { MangaType(it) }
}.sortedBy {
mangaIds.indexOf(it.id)
@@ -199,7 +202,7 @@ class SourceMutation {
preferences = Source.getSourcePreferencesRaw(sourceId).map { preferenceOf(it) },
source =
transaction {
SourceType(SourceTable.select { SourceTable.id eq sourceId }.first())!!
SourceType(SourceTable.selectAll().where { SourceTable.id eq sourceId }.first())!!
},
)
}

View File

@@ -4,7 +4,7 @@ import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
import com.expediagroup.graphql.generator.annotations.GraphQLDescription
import graphql.execution.DataFetcherResult
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.types.TrackRecordType
@@ -127,7 +127,8 @@ class TrackMutation {
val trackRecord =
transaction {
TrackRecordTable
.select {
.selectAll()
.where {
TrackRecordTable.mangaId eq mangaId and (TrackRecordTable.trackerId eq trackerId)
}.first()
}
@@ -156,7 +157,8 @@ class TrackMutation {
val trackRecord =
transaction {
TrackRecordTable
.select {
.selectAll()
.where {
TrackRecordTable.id eq recordId
}.first()
}
@@ -187,7 +189,8 @@ class TrackMutation {
val trackRecord =
transaction {
TrackRecordTable
.select {
.selectAll()
.where {
TrackRecordTable.id eq recordId
}.firstOrNull()
}
@@ -217,7 +220,8 @@ class TrackMutation {
val trackRecords =
transaction {
TrackRecordTable
.select { TrackRecordTable.mangaId eq mangaId }
.selectAll()
.where { TrackRecordTable.mangaId eq mangaId }
.toList()
}
TrackProgressPayload(
@@ -262,7 +266,8 @@ class TrackMutation {
val trackRecord =
transaction {
TrackRecordTable
.select {
.selectAll()
.where {
TrackRecordTable.id eq input.recordId
}.firstOrNull()
}

View File

@@ -3,7 +3,7 @@ package suwayomi.tachidesk.graphql.mutations
import graphql.execution.DataFetcherResult
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withTimeout
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.graphql.asDataFetcherResult
import suwayomi.tachidesk.graphql.types.UpdateStatus
@@ -61,7 +61,7 @@ class UpdateMutation {
fun updateCategoryManga(input: UpdateCategoryMangaInput): CompletableFuture<DataFetcherResult<UpdateCategoryMangaPayload?>> {
val categories =
transaction {
CategoryTable.select { CategoryTable.id inList input.categories }.map {
CategoryTable.selectAll().where { CategoryTable.id inList input.categories }.map {
CategoryTable.toDataClass(it)
}
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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)
}
}
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.exposed.sql.andWhere
import org.jetbrains.exposed.sql.or
interface OrderBy<T> {
val column: Column<out Comparable<*>>
val column: Column<*>
fun asCursor(type: T): Cursor

View File

@@ -12,6 +12,7 @@ import com.expediagroup.graphql.server.types.GraphQLRequest
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.convertValue
import com.fasterxml.jackson.module.kotlin.readValue
import io.github.oshai.kotlinlogging.KotlinLogging
import io.javalin.websocket.WsContext
import io.javalin.websocket.WsMessageContext
import kotlinx.coroutines.currentCoroutineContext
@@ -24,7 +25,6 @@ import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.job
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import org.eclipse.jetty.websocket.api.CloseStatus
import suwayomi.tachidesk.graphql.server.TachideskGraphQLContextFactory
import suwayomi.tachidesk.graphql.server.subscriptions.SubscriptionOperationMessage.ClientMessages.GQL_CONNECTION_INIT

View File

@@ -68,7 +68,7 @@ class ChapterType(
row[ChapterTable.fetchedAt],
row[ChapterTable.isDownloaded],
row[ChapterTable.pageCount],
// transaction { ChapterTable.select { manga eq chapterEntry[manga].value }.count().toInt() },
// transaction { ChapterTable.selectAll().where { Manga eq chapterEntry[manga].value }.count().toInt() },
)
constructor(dataClass: ChapterDataClass) : this(

View File

@@ -13,7 +13,7 @@ import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.FilterList
import graphql.schema.DataFetchingEnvironment
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import suwayomi.tachidesk.graphql.server.primitives.Cursor
import suwayomi.tachidesk.graphql.server.primitives.Edge
import suwayomi.tachidesk.graphql.server.primitives.Node
@@ -92,7 +92,8 @@ fun SourceType(row: ResultRow): SourceType? {
row
} else {
ExtensionTable
.select { ExtensionTable.id eq row[SourceTable.extension] }
.selectAll()
.where { ExtensionTable.id eq row[SourceTable.extension] }
.first()
}