From 590be4f04b75241f0f626d3207527b83cac3cc80 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Tue, 19 Jan 2021 16:02:23 +0330 Subject: [PATCH] rename tables --- .../ir/armor/tachidesk/database/DBMangaer.kt | 8 +++--- .../tachidesk/database/entity/MangaEntity.kt | 25 +++++++++---------- .../tachidesk/database/entity/SourceEntity.kt | 16 ++++++------ .../table/{MangasTable.kt => MangaTable.kt} | 4 +-- .../table/{SourcesTable.kt => SourceTable.kt} | 2 +- .../kotlin/ir/armor/tachidesk/util/APK.kt | 13 ++++------ .../ir/armor/tachidesk/util/SourceList.kt | 16 ++++++------ 7 files changed, 39 insertions(+), 45 deletions(-) rename server/src/main/kotlin/ir/armor/tachidesk/database/table/{MangasTable.kt => MangaTable.kt} (88%) rename server/src/main/kotlin/ir/armor/tachidesk/database/table/{SourcesTable.kt => SourceTable.kt} (91%) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt index 386f71b..ed833e6 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/DBMangaer.kt @@ -2,8 +2,8 @@ package ir.armor.tachidesk.database import ir.armor.tachidesk.Config import ir.armor.tachidesk.database.table.ExtensionsTable -import ir.armor.tachidesk.database.table.MangasTable -import ir.armor.tachidesk.database.table.SourcesTable +import ir.armor.tachidesk.database.table.MangaTable +import ir.armor.tachidesk.database.table.SourceTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.transactions.transaction @@ -20,7 +20,7 @@ fun makeDataBaseTables() { transaction { SchemaUtils.create(ExtensionsTable) - SchemaUtils.create(SourcesTable) - SchemaUtils.create(MangasTable) + SchemaUtils.create(SourceTable) + SchemaUtils.create(MangaTable) } } \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt index 34fc20b..2124132 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/MangaEntity.kt @@ -1,24 +1,23 @@ package ir.armor.tachidesk.database.entity -import ir.armor.tachidesk.database.table.MangasTable -import ir.armor.tachidesk.database.table.SourcesTable +import ir.armor.tachidesk.database.table.MangaTable import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.dao.id.EntityID class MangaEntity(id: EntityID) : IntEntity(id) { - companion object : IntEntityClass(MangasTable) + companion object : IntEntityClass(MangaTable) - var url by MangasTable.url - var title by MangasTable.title - var initialized by MangasTable.initialized + var url by MangaTable.url + var title by MangaTable.title + var initialized by MangaTable.initialized - var artist by MangasTable.artist - var author by MangasTable.author - var description by MangasTable.description - var genre by MangasTable.genre - var status by MangasTable.status - var thumbnail_url by MangasTable.thumbnail_url + var artist by MangaTable.artist + var author by MangaTable.author + var description by MangaTable.description + var genre by MangaTable.genre + var status by MangaTable.status + var thumbnail_url by MangaTable.thumbnail_url - var sourceReference by MangaEntity referencedOn MangasTable.sourceReference + var sourceReference by MangaEntity referencedOn MangaTable.sourceReference } \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt index 6fe8c1c..6bf6658 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/entity/SourceEntity.kt @@ -1,16 +1,16 @@ package ir.armor.tachidesk.database.entity -import ir.armor.tachidesk.database.table.SourcesTable +import ir.armor.tachidesk.database.table.SourceTable import org.jetbrains.exposed.dao.* import org.jetbrains.exposed.dao.id.EntityID class SourceEntity(id: EntityID) : LongEntity(id) { - companion object : EntityClass(SourcesTable, null) + companion object : EntityClass(SourceTable, null) - var sourceId by SourcesTable.id - var name by SourcesTable.name - var lang by SourcesTable.lang - var extension by ExtensionEntity referencedOn SourcesTable.extension - var partOfFactorySource by SourcesTable.partOfFactorySource - var positionInFactorySource by SourcesTable.positionInFactorySource + var sourceId by SourceTable.id + var name by SourceTable.name + var lang by SourceTable.lang + var extension by ExtensionEntity referencedOn SourceTable.extension + var partOfFactorySource by SourceTable.partOfFactorySource + var positionInFactorySource by SourceTable.positionInFactorySource } \ No newline at end of file diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangasTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt similarity index 88% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/MangasTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt index 7f4fce9..3117e64 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangasTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/table/MangaTable.kt @@ -2,7 +2,7 @@ package ir.armor.tachidesk.database.table import org.jetbrains.exposed.dao.id.IntIdTable -object MangasTable : IntIdTable() { +object MangaTable : IntIdTable() { val url = varchar("url", 2048) val title = varchar("title", 512) val initialized = bool("initialized").default(false) @@ -15,7 +15,7 @@ object MangasTable : IntIdTable() { val thumbnail_url = varchar("thumbnail_url", 2048).nullable() // source is used by some ancestor of IntIdTable - val sourceReference = reference("source", SourcesTable) + val sourceReference = reference("source", SourceTable) } enum class MangaStatus(val status: Int) { diff --git a/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourcesTable.kt b/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt similarity index 91% rename from server/src/main/kotlin/ir/armor/tachidesk/database/table/SourcesTable.kt rename to server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt index f0b7182..fe56431 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourcesTable.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/database/table/SourceTable.kt @@ -2,7 +2,7 @@ package ir.armor.tachidesk.database.table import org.jetbrains.exposed.dao.id.IdTable -object SourcesTable : IdTable() { +object SourceTable : IdTable() { override val id = long("id").entityId() val name= varchar("name", 128) val lang = varchar("lang", 10) diff --git a/server/src/main/kotlin/ir/armor/tachidesk/util/APK.kt b/server/src/main/kotlin/ir/armor/tachidesk/util/APK.kt index a653535..10157eb 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/util/APK.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/util/APK.kt @@ -8,18 +8,15 @@ import eu.kanade.tachiyomi.source.online.HttpSource import ir.armor.tachidesk.APKExtractor import ir.armor.tachidesk.Config import ir.armor.tachidesk.database.table.ExtensionsTable -import ir.armor.tachidesk.database.table.SourcesTable +import ir.armor.tachidesk.database.table.SourceTable import kotlinx.coroutines.runBlocking import okhttp3.Request import okio.buffer import okio.sink -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.update -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.io.File import java.net.URL @@ -71,8 +68,8 @@ fun installAPK(apkName: String): Int { // name = httpSource.name // this.extension = ExtensionEntity.find { ExtensionsTable.name eq extension.name }.first().id // } - if (SourcesTable.select { SourcesTable.id eq httpSource.id }.count() == 0L) { - SourcesTable.insert { + if (SourceTable.select { SourceTable.id eq httpSource.id }.count() == 0L) { + SourceTable.insert { it[this.id] = httpSource.id it[name] = httpSource.name it[this.lang] = httpSource.lang @@ -89,8 +86,8 @@ fun installAPK(apkName: String): Int { transaction { sourceFactory.createSources().forEachIndexed { index, source -> val httpSource = source as HttpSource - if (SourcesTable.select { SourcesTable.id eq httpSource.id }.count() == 0L) { - SourcesTable.insert { + if (SourceTable.select { SourceTable.id eq httpSource.id }.count() == 0L) { + SourceTable.insert { it[this.id] = httpSource.id it[name] = httpSource.name it[this.lang] = httpSource.lang diff --git a/server/src/main/kotlin/ir/armor/tachidesk/util/SourceList.kt b/server/src/main/kotlin/ir/armor/tachidesk/util/SourceList.kt index 15ea359..91b2766 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/util/SourceList.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/util/SourceList.kt @@ -3,13 +3,11 @@ package ir.armor.tachidesk.util import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.online.HttpSource import ir.armor.tachidesk.Config -import ir.armor.tachidesk.Main import ir.armor.tachidesk.database.dataclass.SourceDataClass import ir.armor.tachidesk.database.entity.ExtensionEntity import ir.armor.tachidesk.database.entity.SourceEntity import ir.armor.tachidesk.database.table.ExtensionsTable -import ir.armor.tachidesk.database.table.SourcesTable -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import ir.armor.tachidesk.database.table.SourceTable import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction @@ -71,13 +69,13 @@ fun getHttpSource(sourceId: Long): HttpSource { fun getSourceList(): List { return transaction { - return@transaction SourcesTable.selectAll().map { + return@transaction SourceTable.selectAll().map { SourceDataClass( - it[SourcesTable.id].value.toString(), - it[SourcesTable.name], - Locale(it[SourcesTable.lang]).getDisplayLanguage(Locale(it[SourcesTable.lang])), - ExtensionsTable.select { ExtensionsTable.id eq it[SourcesTable.extension] }.first()[ExtensionsTable.iconUrl], - getHttpSource(it[SourcesTable.id].value).supportsLatest + it[SourceTable.id].value.toString(), + it[SourceTable.name], + Locale(it[SourceTable.lang]).getDisplayLanguage(Locale(it[SourceTable.lang])), + ExtensionsTable.select { ExtensionsTable.id eq it[SourceTable.extension] }.first()[ExtensionsTable.iconUrl], + getHttpSource(it[SourceTable.id].value).supportsLatest ) } }