diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt index 10e102a250..7e1a53445e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DbOpenHelper.kt @@ -21,21 +21,21 @@ class DbOpenHelper(context: Context) } override fun onCreate(db: SQLiteDatabase) = with(db) { - execSQL(MangaTable.getCreateTableQuery()) - execSQL(ChapterTable.getCreateTableQuery()) - execSQL(MangaSyncTable.getCreateTableQuery()) - execSQL(CategoryTable.getCreateTableQuery()) - execSQL(MangaCategoryTable.getCreateTableQuery()) + execSQL(MangaTable.createTableQuery) + execSQL(ChapterTable.createTableQuery) + execSQL(MangaSyncTable.createTableQuery) + execSQL(CategoryTable.createTableQuery) + execSQL(MangaCategoryTable.createTableQuery) // DB indexes - execSQL(MangaTable.getCreateUrlIndexQuery()) - execSQL(MangaTable.getCreateFavoriteIndexQuery()) - execSQL(ChapterTable.getCreateMangaIdIndexQuery()) + execSQL(MangaTable.createUrlIndexQuery) + execSQL(MangaTable.createFavoriteIndexQuery) + execSQL(ChapterTable.createMangaIdIndexQuery) } override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { if (oldVersion < 2) { - db.execSQL(ChapterTable.getSourceOrderUpdateQuery()) + db.execSQL(ChapterTable.sourceOrderUpdateQuery) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.java index 91eaa09f17..e6de5e1ca3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.java @@ -10,16 +10,16 @@ import eu.kanade.tachiyomi.data.database.tables.CategoryTable; @StorIOSQLiteType(table = CategoryTable.TABLE) public class Category implements Serializable { - @StorIOSQLiteColumn(name = CategoryTable.COLUMN_ID, key = true) + @StorIOSQLiteColumn(name = CategoryTable.COL_ID, key = true) public Integer id; - @StorIOSQLiteColumn(name = CategoryTable.COLUMN_NAME) + @StorIOSQLiteColumn(name = CategoryTable.COL_NAME) public String name; - @StorIOSQLiteColumn(name = CategoryTable.COLUMN_ORDER) + @StorIOSQLiteColumn(name = CategoryTable.COL_ORDER) public int order; - @StorIOSQLiteColumn(name = CategoryTable.COLUMN_FLAGS) + @StorIOSQLiteColumn(name = CategoryTable.COL_FLAGS) public int flags; public Category() {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.java index 4d739686fd..f3b46681d5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Chapter.java @@ -14,34 +14,34 @@ import eu.kanade.tachiyomi.util.UrlUtil; @StorIOSQLiteType(table = ChapterTable.TABLE) public class Chapter implements Serializable { - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_ID, key = true) + @StorIOSQLiteColumn(name = ChapterTable.COL_ID, key = true) public Long id; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_MANGA_ID) + @StorIOSQLiteColumn(name = ChapterTable.COL_MANGA_ID) public Long manga_id; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_URL) + @StorIOSQLiteColumn(name = ChapterTable.COL_URL) public String url; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_NAME) + @StorIOSQLiteColumn(name = ChapterTable.COL_NAME) public String name; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_READ) + @StorIOSQLiteColumn(name = ChapterTable.COL_READ) public boolean read; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_LAST_PAGE_READ) + @StorIOSQLiteColumn(name = ChapterTable.COL_LAST_PAGE_READ) public int last_page_read; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_FETCH) + @StorIOSQLiteColumn(name = ChapterTable.COL_DATE_FETCH) public long date_fetch; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_DATE_UPLOAD) + @StorIOSQLiteColumn(name = ChapterTable.COL_DATE_UPLOAD) public long date_upload; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_CHAPTER_NUMBER) + @StorIOSQLiteColumn(name = ChapterTable.COL_CHAPTER_NUMBER) public float chapter_number; - @StorIOSQLiteColumn(name = ChapterTable.COLUMN_SOURCE_ORDER) + @StorIOSQLiteColumn(name = ChapterTable.COL_SOURCE_ORDER) public int source_order; public int status; diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java index 97c42c5528..e8f8a24f99 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.java @@ -14,49 +14,49 @@ import eu.kanade.tachiyomi.util.UrlUtil; @StorIOSQLiteType(table = MangaTable.TABLE) public class Manga implements Serializable { - @StorIOSQLiteColumn(name = MangaTable.COLUMN_ID, key = true) + @StorIOSQLiteColumn(name = MangaTable.COL_ID, key = true) public Long id; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_SOURCE) + @StorIOSQLiteColumn(name = MangaTable.COL_SOURCE) public int source; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_URL) + @StorIOSQLiteColumn(name = MangaTable.COL_URL) public String url; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_ARTIST) + @StorIOSQLiteColumn(name = MangaTable.COL_ARTIST) public String artist; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_AUTHOR) + @StorIOSQLiteColumn(name = MangaTable.COL_AUTHOR) public String author; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_DESCRIPTION) + @StorIOSQLiteColumn(name = MangaTable.COL_DESCRIPTION) public String description; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_GENRE) + @StorIOSQLiteColumn(name = MangaTable.COL_GENRE) public String genre; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_TITLE) + @StorIOSQLiteColumn(name = MangaTable.COL_TITLE) public String title; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_STATUS) + @StorIOSQLiteColumn(name = MangaTable.COL_STATUS) public int status; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_THUMBNAIL_URL) + @StorIOSQLiteColumn(name = MangaTable.COL_THUMBNAIL_URL) public String thumbnail_url; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_FAVORITE) + @StorIOSQLiteColumn(name = MangaTable.COL_FAVORITE) public boolean favorite; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_LAST_UPDATE) + @StorIOSQLiteColumn(name = MangaTable.COL_LAST_UPDATE) public long last_update; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_INITIALIZED) + @StorIOSQLiteColumn(name = MangaTable.COL_INITIALIZED) public boolean initialized; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_VIEWER) + @StorIOSQLiteColumn(name = MangaTable.COL_VIEWER) public int viewer; - @StorIOSQLiteColumn(name = MangaTable.COLUMN_CHAPTER_FLAGS) + @StorIOSQLiteColumn(name = MangaTable.COL_CHAPTER_FLAGS) public int chapter_flags; public transient int unread; diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaCategory.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaCategory.java index 062039b297..96230b54a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaCategory.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaCategory.java @@ -8,13 +8,13 @@ import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable; @StorIOSQLiteType(table = MangaCategoryTable.TABLE) public class MangaCategory { - @StorIOSQLiteColumn(name = MangaCategoryTable.COLUMN_ID, key = true) + @StorIOSQLiteColumn(name = MangaCategoryTable.COL_ID, key = true) public Long id; - @StorIOSQLiteColumn(name = MangaCategoryTable.COLUMN_MANGA_ID) + @StorIOSQLiteColumn(name = MangaCategoryTable.COL_MANGA_ID) public long manga_id; - @StorIOSQLiteColumn(name = MangaCategoryTable.COLUMN_CATEGORY_ID) + @StorIOSQLiteColumn(name = MangaCategoryTable.COL_CATEGORY_ID) public int category_id; public MangaCategory() {} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaSync.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaSync.java index 92a5a64042..7e7ee1b7ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaSync.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaSync.java @@ -11,31 +11,31 @@ import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService; @StorIOSQLiteType(table = MangaSyncTable.TABLE) public class MangaSync implements Serializable { - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_ID, key = true) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_ID, key = true) public Long id; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_MANGA_ID) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_MANGA_ID) public long manga_id; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_SYNC_ID) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_SYNC_ID) public int sync_id; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_REMOTE_ID) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_REMOTE_ID) public int remote_id; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_TITLE) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_TITLE) public String title; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_LAST_CHAPTER_READ) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_LAST_CHAPTER_READ) public int last_chapter_read; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_TOTAL_CHAPTERS) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_TOTAL_CHAPTERS) public int total_chapters; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_SCORE) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_SCORE) public float score; - @StorIOSQLiteColumn(name = MangaSyncTable.COLUMN_STATUS) + @StorIOSQLiteColumn(name = MangaSyncTable.COL_STATUS) public int status; public boolean update; diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt index b873bc6319..edf839d8fa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt @@ -13,7 +13,7 @@ interface CategoryQueries : DbProvider { .listOfObjects(Category::class.java) .withQuery(Query.builder() .table(CategoryTable.TABLE) - .orderBy(CategoryTable.COLUMN_ORDER) + .orderBy(CategoryTable.COL_ORDER) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt index 95b7350c65..1f340dceca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt @@ -19,7 +19,7 @@ interface ChapterQueries : DbProvider { .listOfObjects(Chapter::class.java) .withQuery(Query.builder() .table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_MANGA_ID} = ?") + .where("${ChapterTable.COL_MANGA_ID} = ?") .whereArgs(manga.id) .build()) .prepare() @@ -43,11 +43,11 @@ interface ChapterQueries : DbProvider { .`object`(Chapter::class.java) .withQuery(Query.builder() .table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_MANGA_ID} = ? AND " + - "${ChapterTable.COLUMN_CHAPTER_NUMBER} > ? AND " + - "${ChapterTable.COLUMN_CHAPTER_NUMBER} <= ?") + .where("${ChapterTable.COL_MANGA_ID} = ? AND " + + "${ChapterTable.COL_CHAPTER_NUMBER} > ? AND " + + "${ChapterTable.COL_CHAPTER_NUMBER} <= ?") .whereArgs(chapter.manga_id, chapterNumber, chapterNumber + 1) - .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER) + .orderBy(ChapterTable.COL_CHAPTER_NUMBER) .limit(1) .build()) .prepare() @@ -61,11 +61,11 @@ interface ChapterQueries : DbProvider { return db.get() .`object`(Chapter::class.java) .withQuery(Query.builder().table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_MANGA_ID} = ? AND " + - "${ChapterTable.COLUMN_CHAPTER_NUMBER} < ? AND " + - "${ChapterTable.COLUMN_CHAPTER_NUMBER} >= ?") + .where("${ChapterTable.COL_MANGA_ID} = ? AND " + + "${ChapterTable.COL_CHAPTER_NUMBER} < ? AND " + + "${ChapterTable.COL_CHAPTER_NUMBER} >= ?") .whereArgs(chapter.manga_id, chapterNumber, chapterNumber - 1) - .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER + " DESC") + .orderBy(ChapterTable.COL_CHAPTER_NUMBER + " DESC") .limit(1) .build()) .prepare() @@ -75,11 +75,11 @@ interface ChapterQueries : DbProvider { .`object`(Chapter::class.java) .withQuery(Query.builder() .table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_MANGA_ID} = ? AND " + - "${ChapterTable.COLUMN_READ} = ? AND " + - "${ChapterTable.COLUMN_CHAPTER_NUMBER} >= ?") + .where("${ChapterTable.COL_MANGA_ID} = ? AND " + + "${ChapterTable.COL_READ} = ? AND " + + "${ChapterTable.COL_CHAPTER_NUMBER} >= ?") .whereArgs(manga.id, 0, 0) - .orderBy(ChapterTable.COLUMN_CHAPTER_NUMBER) + .orderBy(ChapterTable.COL_CHAPTER_NUMBER) .limit(1) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt index dfe3352686..7ad7f937e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaCategoryQueries.kt @@ -17,7 +17,7 @@ interface MangaCategoryQueries : DbProvider { fun deleteOldMangasCategories(mangas: List) = db.delete() .byQuery(DeleteQuery.builder() .table(MangaCategoryTable.TABLE) - .where("${MangaCategoryTable.COLUMN_MANGA_ID} IN (${Queries.placeholders(mangas.size)})") + .where("${MangaCategoryTable.COL_MANGA_ID} IN (${Queries.placeholders(mangas.size)})") .whereArgs(*mangas.map { it.id }.toTypedArray()) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt index dc6866e26a..cd66c0a9d2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt @@ -32,9 +32,9 @@ interface MangaQueries : DbProvider { .listOfObjects(Manga::class.java) .withQuery(Query.builder() .table(MangaTable.TABLE) - .where("${MangaTable.COLUMN_FAVORITE} = ?") + .where("${MangaTable.COL_FAVORITE} = ?") .whereArgs(1) - .orderBy(MangaTable.COLUMN_TITLE) + .orderBy(MangaTable.COL_TITLE) .build()) .prepare() @@ -42,7 +42,7 @@ interface MangaQueries : DbProvider { .`object`(Manga::class.java) .withQuery(Query.builder() .table(MangaTable.TABLE) - .where("${MangaTable.COLUMN_URL} = ? AND ${MangaTable.COLUMN_SOURCE} = ?") + .where("${MangaTable.COL_URL} = ? AND ${MangaTable.COL_SOURCE} = ?") .whereArgs(url, sourceId) .build()) .prepare() @@ -51,7 +51,7 @@ interface MangaQueries : DbProvider { .`object`(Manga::class.java) .withQuery(Query.builder() .table(MangaTable.TABLE) - .where("${MangaTable.COLUMN_ID} = ?") + .where("${MangaTable.COL_ID} = ?") .whereArgs(id) .build()) .prepare() @@ -67,7 +67,7 @@ interface MangaQueries : DbProvider { fun deleteMangasNotInLibrary() = db.delete() .byQuery(DeleteQuery.builder() .table(MangaTable.TABLE) - .where("${MangaTable.COLUMN_FAVORITE} = ?") + .where("${MangaTable.COL_FAVORITE} = ?") .whereArgs(0) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaSyncQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaSyncQueries.kt index 47995ab82e..2119dfde97 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaSyncQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaSyncQueries.kt @@ -14,8 +14,8 @@ interface MangaSyncQueries : DbProvider { .`object`(MangaSync::class.java) .withQuery(Query.builder() .table(MangaSyncTable.TABLE) - .where("${MangaSyncTable.COLUMN_MANGA_ID} = ? AND " + - "${MangaSyncTable.COLUMN_SYNC_ID} = ?") + .where("${MangaSyncTable.COL_MANGA_ID} = ? AND " + + "${MangaSyncTable.COL_SYNC_ID} = ?") .whereArgs(manga.id, sync.id) .build()) .prepare() @@ -24,7 +24,7 @@ interface MangaSyncQueries : DbProvider { .listOfObjects(MangaSync::class.java) .withQuery(Query.builder() .table(MangaSyncTable.TABLE) - .where("${MangaSyncTable.COLUMN_MANGA_ID} = ?") + .where("${MangaSyncTable.COL_MANGA_ID} = ?") .whereArgs(manga.id) .build()) .prepare() @@ -38,7 +38,7 @@ interface MangaSyncQueries : DbProvider { fun deleteMangaSyncForManga(manga: Manga) = db.delete() .byQuery(DeleteQuery.builder() .table(MangaSyncTable.TABLE) - .where("${MangaSyncTable.COLUMN_MANGA_ID} = ?") + .where("${MangaSyncTable.COL_MANGA_ID} = ?") .whereArgs(manga.id) .build()) .prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt index 99cfffae4a..305fd3824e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt @@ -8,41 +8,44 @@ import eu.kanade.tachiyomi.data.database.tables.MangaTable as Manga /** * Query to get the manga from the library, with their categories and unread count. */ -val libraryQuery = - "SELECT M.*, COALESCE(MC.${MangaCategory.COLUMN_CATEGORY_ID}, 0) AS ${Manga.COLUMN_CATEGORY} " + - "FROM (" + - "SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COLUMN_UNREAD} " + - "FROM ${Manga.TABLE} " + - "LEFT JOIN (" + - "SELECT ${Chapter.COLUMN_MANGA_ID}, COUNT(*) AS unread " + - "FROM ${Chapter.TABLE} " + - "WHERE ${Chapter.COLUMN_READ} = 0 " + - "GROUP BY ${Chapter.COLUMN_MANGA_ID}" + - ") AS C " + - "ON ${Manga.COLUMN_ID} = C.${Chapter.COLUMN_MANGA_ID} " + - "WHERE ${Manga.COLUMN_FAVORITE} = 1 " + - "GROUP BY ${Manga.COLUMN_ID} " + - "ORDER BY ${Manga.COLUMN_TITLE}" + - ") AS M " + - "LEFT JOIN (" + - "SELECT * FROM ${MangaCategory.TABLE}) AS MC " + - "ON MC.${MangaCategory.COLUMN_MANGA_ID} = M.${Manga.COLUMN_ID}" +val libraryQuery = """ + SELECT M.*, COALESCE(MC.${MangaCategory.COL_CATEGORY_ID}, 0) AS ${Manga.COL_CATEGORY} + FROM ( + SELECT ${Manga.TABLE}.*, COALESCE(C.unread, 0) AS ${Manga.COL_UNREAD} + FROM ${Manga.TABLE} + LEFT JOIN ( + SELECT ${Chapter.COL_MANGA_ID}, COUNT(*) AS unread + FROM ${Chapter.TABLE} + WHERE ${Chapter.COL_READ} = 0 + GROUP BY ${Chapter.COL_MANGA_ID} + ) AS C + ON ${Manga.COL_ID} = C.${Chapter.COL_MANGA_ID} + WHERE ${Manga.COL_FAVORITE} = 1 + GROUP BY ${Manga.COL_ID} + ORDER BY ${Manga.COL_TITLE} + ) AS M + LEFT JOIN ( + SELECT * FROM ${MangaCategory.TABLE}) AS MC + ON MC.${MangaCategory.COL_MANGA_ID} = M.${Manga.COL_ID} +""" /** * Query to get the recent chapters of manga from the library up to a date. */ -fun getRecentsQuery() = - "SELECT ${Manga.TABLE}.${Manga.COLUMN_URL} as mangaUrl, * FROM ${Manga.TABLE} JOIN ${Chapter.TABLE} " + - "ON ${Manga.TABLE}.${Manga.COLUMN_ID} = ${Chapter.TABLE}.${Chapter.COLUMN_MANGA_ID} " + - "WHERE ${Manga.COLUMN_FAVORITE} = 1 AND ${Chapter.COLUMN_DATE_UPLOAD} > ? " + - "ORDER BY ${Chapter.COLUMN_DATE_UPLOAD} DESC" +fun getRecentsQuery() = """ + SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, * FROM ${Manga.TABLE} JOIN ${Chapter.TABLE} + ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} + WHERE ${Manga.COL_FAVORITE} = 1 AND ${Chapter.COL_DATE_UPLOAD} > ? + ORDER BY ${Chapter.COL_DATE_UPLOAD} DESC +""" /** * Query to get the categories for a manga. */ -fun getCategoriesForMangaQuery() = - "SELECT ${Category.TABLE}.* FROM ${Category.TABLE} " + - "JOIN ${MangaCategory.TABLE} ON ${Category.TABLE}.${Category.COLUMN_ID} = " + - "${MangaCategory.TABLE}.${MangaCategory.COLUMN_CATEGORY_ID} " + - "WHERE ${MangaCategory.COLUMN_MANGA_ID} = ?" \ No newline at end of file +fun getCategoriesForMangaQuery() = """ + SELECT ${Category.TABLE}.* FROM ${Category.TABLE} + JOIN ${MangaCategory.TABLE} ON ${Category.TABLE}.${Category.COL_ID} = + ${MangaCategory.TABLE}.${MangaCategory.COL_CATEGORY_ID} + WHERE ${MangaCategory.COL_MANGA_ID} = ? +""" \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterProgressPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterProgressPutResolver.kt index d322931d7a..f7fb670846 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterProgressPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterProgressPutResolver.kt @@ -21,13 +21,13 @@ class ChapterProgressPutResolver : PutResolver() { fun mapToUpdateQuery(chapter: Chapter) = UpdateQuery.builder() .table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_ID} = ?") + .where("${ChapterTable.COL_ID} = ?") .whereArgs(chapter.id) .build() fun mapToContentValues(chapter: Chapter) = ContentValues(2).apply { - put(ChapterTable.COLUMN_READ, chapter.read) - put(ChapterTable.COLUMN_LAST_PAGE_READ, chapter.last_page_read) + put(ChapterTable.COL_READ, chapter.read) + put(ChapterTable.COL_LAST_PAGE_READ, chapter.last_page_read) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterSourceOrderPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterSourceOrderPutResolver.kt index bd870f670f..04d7ac2753 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterSourceOrderPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/ChapterSourceOrderPutResolver.kt @@ -21,12 +21,12 @@ class ChapterSourceOrderPutResolver : PutResolver() { fun mapToUpdateQuery(chapter: Chapter) = UpdateQuery.builder() .table(ChapterTable.TABLE) - .where("${ChapterTable.COLUMN_URL} = ? AND ${ChapterTable.COLUMN_MANGA_ID} = ?") + .where("${ChapterTable.COL_URL} = ? AND ${ChapterTable.COL_MANGA_ID} = ?") .whereArgs(chapter.url, chapter.manga_id) .build() fun mapToContentValues(chapter: Chapter) = ContentValues(1).apply { - put(ChapterTable.COLUMN_SOURCE_ORDER, chapter.source_order) + put(ChapterTable.COL_SOURCE_ORDER, chapter.source_order) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt index 3a0ac84bc9..70f43c4a8e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt @@ -15,10 +15,10 @@ class LibraryMangaGetResolver : MangaStorIOSQLiteGetResolver() { override fun mapFromCursor(cursor: Cursor): Manga { val manga = super.mapFromCursor(cursor) - val unreadColumn = cursor.getColumnIndex(MangaTable.COLUMN_UNREAD) + val unreadColumn = cursor.getColumnIndex(MangaTable.COL_UNREAD) manga.unread = cursor.getInt(unreadColumn) - val categoryColumn = cursor.getColumnIndex(MangaTable.COLUMN_CATEGORY) + val categoryColumn = cursor.getColumnIndex(MangaTable.COL_CATEGORY) manga.category = cursor.getInt(categoryColumn) return manga diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.java deleted file mode 100644 index a84db50666..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.java +++ /dev/null @@ -1,39 +0,0 @@ -package eu.kanade.tachiyomi.data.database.tables; - -import android.support.annotation.NonNull; - -public class CategoryTable { - - @NonNull - public static final String TABLE = "categories"; - - @NonNull - public static final String COLUMN_ID = "_id"; - - @NonNull - public static final String COLUMN_NAME = "name"; - - @NonNull - public static final String COLUMN_ORDER = "sort"; - - @NonNull - public static final String COLUMN_FLAGS = "flags"; - - // This is just class with Meta Data, we don't need instances - private CategoryTable() { - throw new IllegalStateException("No instances please"); - } - - // Better than static final field -> allows VM to unload useless String - // Because you need this string only once per application life on the device - @NonNull - public static String getCreateTableQuery() { - return "CREATE TABLE " + TABLE + "(" - + COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, " - + COLUMN_NAME + " TEXT NOT NULL, " - + COLUMN_ORDER + " INTEGER NOT NULL, " - + COLUMN_FLAGS + " INTEGER NOT NULL" - + ");"; - - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.kt new file mode 100644 index 0000000000..65af41013e --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/CategoryTable.kt @@ -0,0 +1,23 @@ +package eu.kanade.tachiyomi.data.database.tables + +object CategoryTable { + + const val TABLE = "categories" + + const val COL_ID = "_id" + + const val COL_NAME = "name" + + const val COL_ORDER = "sort" + + const val COL_FLAGS = "flags" + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_NAME TEXT NOT NULL, + $COL_ORDER INTEGER NOT NULL, + $COL_FLAGS INTEGER NOT NULL + )""" + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.java deleted file mode 100644 index d5b46dadab..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.java +++ /dev/null @@ -1,73 +0,0 @@ -package eu.kanade.tachiyomi.data.database.tables; - -import android.support.annotation.NonNull; - -public final class ChapterTable { - - @NonNull - public static final String TABLE = "chapters"; - - @NonNull - public static final String COLUMN_ID = "_id"; - - @NonNull - public static final String COLUMN_MANGA_ID = "manga_id"; - - @NonNull - public static final String COLUMN_URL = "url"; - - @NonNull - public static final String COLUMN_NAME = "name"; - - @NonNull - public static final String COLUMN_READ = "read"; - - @NonNull - public static final String COLUMN_DATE_FETCH = "date_fetch"; - - @NonNull - public static final String COLUMN_DATE_UPLOAD = "date_upload"; - - @NonNull - public static final String COLUMN_LAST_PAGE_READ = "last_page_read"; - - @NonNull - public static final String COLUMN_CHAPTER_NUMBER = "chapter_number"; - - @NonNull - public static final String COLUMN_SOURCE_ORDER = "source_order"; - - private ChapterTable() throws InstantiationException { - throw new InstantiationException("This class is not for instantiation"); - } - - @NonNull - public static String getCreateTableQuery() { - return "CREATE TABLE " + TABLE + "(" - + COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, " - + COLUMN_MANGA_ID + " INTEGER NOT NULL, " - + COLUMN_URL + " TEXT NOT NULL, " - + COLUMN_NAME + " TEXT NOT NULL, " - + COLUMN_READ + " BOOLEAN NOT NULL, " - + COLUMN_LAST_PAGE_READ + " INT NOT NULL, " - + COLUMN_CHAPTER_NUMBER + " FLOAT NOT NULL, " - + COLUMN_SOURCE_ORDER + " INTEGER NOT NULL, " - + COLUMN_DATE_FETCH + " LONG NOT NULL, " - + COLUMN_DATE_UPLOAD + " LONG NOT NULL, " - + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " - + "ON DELETE CASCADE" - + ");"; - } - - @NonNull - public static String getCreateMangaIdIndexQuery() { - return "CREATE INDEX " + TABLE + "_" + COLUMN_MANGA_ID + "_index ON " + TABLE + "(" + COLUMN_MANGA_ID + ");"; - - } - - @NonNull - public static String getSourceOrderUpdateQuery() { - return "ALTER TABLE " + TABLE + " ADD COLUMN " + COLUMN_SOURCE_ORDER + " INTEGER DEFAULT 0"; - } - -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt new file mode 100644 index 0000000000..d3795a15a2 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/ChapterTable.kt @@ -0,0 +1,49 @@ +package eu.kanade.tachiyomi.data.database.tables + +object ChapterTable { + + const val TABLE = "chapters" + + const val COL_ID = "_id" + + const val COL_MANGA_ID = "manga_id" + + const val COL_URL = "url" + + const val COL_NAME = "name" + + const val COL_READ = "read" + + const val COL_DATE_FETCH = "date_fetch" + + const val COL_DATE_UPLOAD = "date_upload" + + const val COL_LAST_PAGE_READ = "last_page_read" + + const val COL_CHAPTER_NUMBER = "chapter_number" + + const val COL_SOURCE_ORDER = "source_order" + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_MANGA_ID INTEGER NOT NULL, + $COL_URL TEXT NOT NULL, + $COL_NAME TEXT NOT NULL, + $COL_READ BOOLEAN NOT NULL, + $COL_LAST_PAGE_READ INT NOT NULL, + $COL_CHAPTER_NUMBER FLOAT NOT NULL, + $COL_SOURCE_ORDER INTEGER NOT NULL, + $COL_DATE_FETCH LONG NOT NULL, + $COL_DATE_UPLOAD LONG NOT NULL, + FOREIGN KEY($COL_MANGA_ID) REFERENCES ${MangaTable.TABLE} (${MangaTable.COL_ID}) + ON DELETE CASCADE + )""" + + val createMangaIdIndexQuery: String + get() = "CREATE INDEX ${TABLE}_${COL_MANGA_ID}_index ON $TABLE($COL_MANGA_ID)" + + val sourceOrderUpdateQuery: String + get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SOURCE_ORDER INTEGER DEFAULT 0" + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.java deleted file mode 100644 index e31086603e..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.java +++ /dev/null @@ -1,40 +0,0 @@ -package eu.kanade.tachiyomi.data.database.tables; - -import android.support.annotation.NonNull; - -public class MangaCategoryTable { - - @NonNull - public static final String TABLE = "mangas_categories"; - - @NonNull - public static final String COLUMN_ID = "_id"; - - @NonNull - public static final String COLUMN_MANGA_ID = "manga_id"; - - @NonNull - public static final String COLUMN_CATEGORY_ID = "category_id"; - - // This is just class with Meta Data, we don't need instances - private MangaCategoryTable() { - throw new IllegalStateException("No instances please"); - } - - // Better than static final field -> allows VM to unload useless String - // Because you need this string only once per application life on the device - @NonNull - public static String getCreateTableQuery() { - return "CREATE TABLE " + TABLE + "(" - + COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, " - + COLUMN_MANGA_ID + " INTEGER NOT NULL, " - + COLUMN_CATEGORY_ID + " INTEGER NOT NULL, " - + "FOREIGN KEY(" + COLUMN_CATEGORY_ID + ") REFERENCES " + CategoryTable.TABLE + "(" + CategoryTable.COLUMN_ID + ") " - + "ON DELETE CASCADE, " - + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " - + "ON DELETE CASCADE" - + ");"; - - } - -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.kt new file mode 100644 index 0000000000..a42e91e925 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaCategoryTable.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.data.database.tables + +object MangaCategoryTable { + + const val TABLE = "mangas_categories" + + const val COL_ID = "_id" + + const val COL_MANGA_ID = "manga_id" + + const val COL_CATEGORY_ID = "category_id" + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_MANGA_ID INTEGER NOT NULL, + $COL_CATEGORY_ID INTEGER NOT NULL, + FOREIGN KEY($COL_CATEGORY_ID) REFERENCES ${CategoryTable.TABLE} (${CategoryTable.COL_ID}) + ON DELETE CASCADE, + FOREIGN KEY($COL_MANGA_ID) REFERENCES ${MangaTable.TABLE} (${MangaTable.COL_ID}) + ON DELETE CASCADE + )""" + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.java deleted file mode 100644 index 0c4861fefe..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.java +++ /dev/null @@ -1,49 +0,0 @@ -package eu.kanade.tachiyomi.data.database.tables; - -import android.support.annotation.NonNull; - -public final class MangaSyncTable { - - public static final String TABLE = "manga_sync"; - - public static final String COLUMN_ID = "_id"; - - public static final String COLUMN_MANGA_ID = "manga_id"; - - public static final String COLUMN_SYNC_ID = "sync_id"; - - public static final String COLUMN_REMOTE_ID = "remote_id"; - - public static final String COLUMN_TITLE = "title"; - - public static final String COLUMN_LAST_CHAPTER_READ = "last_chapter_read"; - - public static final String COLUMN_STATUS = "status"; - - public static final String COLUMN_SCORE = "score"; - - public static final String COLUMN_TOTAL_CHAPTERS = "total_chapters"; - - private MangaSyncTable() throws InstantiationException { - throw new InstantiationException("This class is not for instantiation"); - } - - @NonNull - public static String getCreateTableQuery() { - return "CREATE TABLE " + TABLE + "(" - + COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, " - + COLUMN_MANGA_ID + " INTEGER NOT NULL, " - + COLUMN_SYNC_ID + " INTEGER NOT NULL, " - + COLUMN_REMOTE_ID + " INTEGER NOT NULL, " - + COLUMN_TITLE + " TEXT NOT NULL, " - + COLUMN_LAST_CHAPTER_READ + " INTEGER NOT NULL, " - + COLUMN_TOTAL_CHAPTERS + " INTEGER NOT NULL, " - + COLUMN_STATUS + " INTEGER NOT NULL, " - + COLUMN_SCORE + " FLOAT NOT NULL, " - + "UNIQUE (" + COLUMN_MANGA_ID + ", " + COLUMN_SYNC_ID + ") ON CONFLICT REPLACE, " - + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " - + "ON DELETE CASCADE" - + ");"; - } - -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.kt new file mode 100644 index 0000000000..4a42d5fb99 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaSyncTable.kt @@ -0,0 +1,41 @@ +package eu.kanade.tachiyomi.data.database.tables + +object MangaSyncTable { + + const val TABLE = "manga_sync" + + const val COL_ID = "_id" + + const val COL_MANGA_ID = "manga_id" + + const val COL_SYNC_ID = "sync_id" + + const val COL_REMOTE_ID = "remote_id" + + const val COL_TITLE = "title" + + const val COL_LAST_CHAPTER_READ = "last_chapter_read" + + const val COL_STATUS = "status" + + const val COL_SCORE = "score" + + const val COL_TOTAL_CHAPTERS = "total_chapters" + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_MANGA_ID INTEGER NOT NULL, + $COL_SYNC_ID INTEGER NOT NULL, + $COL_REMOTE_ID INTEGER NOT NULL, + $COL_TITLE TEXT NOT NULL, + $COL_LAST_CHAPTER_READ INTEGER NOT NULL, + $COL_TOTAL_CHAPTERS INTEGER NOT NULL, + $COL_STATUS INTEGER NOT NULL, + $COL_SCORE FLOAT NOT NULL, + UNIQUE ($COL_MANGA_ID, $COL_SYNC_ID) ON CONFLICT REPLACE, + FOREIGN KEY($COL_MANGA_ID) REFERENCES ${MangaTable.TABLE} (${MangaTable.COL_ID}) + ON DELETE CASCADE + )""" + +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.java deleted file mode 100644 index 7b99bcd398..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.java +++ /dev/null @@ -1,98 +0,0 @@ -package eu.kanade.tachiyomi.data.database.tables; - -import android.support.annotation.NonNull; - -public class MangaTable { - - @NonNull - public static final String TABLE = "mangas"; - - @NonNull - public static final String COLUMN_ID = "_id"; - - @NonNull - public static final String COLUMN_SOURCE = "source"; - - @NonNull - public static final String COLUMN_URL = "url"; - - @NonNull - public static final String COLUMN_ARTIST = "artist"; - - @NonNull - public static final String COLUMN_AUTHOR = "author" ; - - @NonNull - public static final String COLUMN_DESCRIPTION = "description"; - - @NonNull - public static final String COLUMN_GENRE = "genre"; - - @NonNull - public static final String COLUMN_TITLE = "title"; - - @NonNull - public static final String COLUMN_STATUS = "status"; - - @NonNull - public static final String COLUMN_THUMBNAIL_URL = "thumbnail_url"; - - @NonNull - public static final String COLUMN_FAVORITE = "favorite"; - - @NonNull - public static final String COLUMN_LAST_UPDATE = "last_update"; - - @NonNull - public static final String COLUMN_INITIALIZED = "initialized"; - - @NonNull - public static final String COLUMN_VIEWER = "viewer"; - - @NonNull - public static final String COLUMN_CHAPTER_FLAGS = "chapter_flags"; - - @NonNull - public static final String COLUMN_UNREAD = "unread"; - - @NonNull - public static final String COLUMN_CATEGORY = "category"; - - // This is just class with Meta Data, we don't need instances - private MangaTable() { - throw new IllegalStateException("No instances please"); - } - - // Better than static final field -> allows VM to unload useless String - // Because you need this string only once per application life on the device - @NonNull - public static String getCreateTableQuery() { - return "CREATE TABLE " + TABLE + "(" - + COLUMN_ID + " INTEGER NOT NULL PRIMARY KEY, " - + COLUMN_SOURCE + " INTEGER NOT NULL, " - + COLUMN_URL + " TEXT NOT NULL, " - + COLUMN_ARTIST + " TEXT, " - + COLUMN_AUTHOR + " TEXT, " - + COLUMN_DESCRIPTION + " TEXT, " - + COLUMN_GENRE + " TEXT, " - + COLUMN_TITLE + " TEXT NOT NULL, " - + COLUMN_STATUS + " INTEGER NOT NULL, " - + COLUMN_THUMBNAIL_URL + " TEXT, " - + COLUMN_FAVORITE + " INTEGER NOT NULL, " - + COLUMN_LAST_UPDATE + " LONG, " - + COLUMN_INITIALIZED + " BOOLEAN NOT NULL, " - + COLUMN_VIEWER + " INTEGER NOT NULL, " - + COLUMN_CHAPTER_FLAGS + " INTEGER NOT NULL" - + ");"; - - } - - public static String getCreateUrlIndexQuery() { - return "CREATE INDEX " + TABLE + "_" + COLUMN_URL + "_index ON " + TABLE + "(" + COLUMN_URL + ");"; - } - - public static String getCreateFavoriteIndexQuery() { - return "CREATE INDEX " + TABLE + "_" + COLUMN_FAVORITE + "_index ON " + TABLE + "(" + COLUMN_FAVORITE + ");"; - - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt new file mode 100644 index 0000000000..199e86f71d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/tables/MangaTable.kt @@ -0,0 +1,65 @@ +package eu.kanade.tachiyomi.data.database.tables + +object MangaTable { + + const val TABLE = "mangas" + + const val COL_ID = "_id" + + const val COL_SOURCE = "source" + + const val COL_URL = "url" + + const val COL_ARTIST = "artist" + + const val COL_AUTHOR = "author" + + const val COL_DESCRIPTION = "description" + + const val COL_GENRE = "genre" + + const val COL_TITLE = "title" + + const val COL_STATUS = "status" + + const val COL_THUMBNAIL_URL = "thumbnail_url" + + const val COL_FAVORITE = "favorite" + + const val COL_LAST_UPDATE = "last_update" + + const val COL_INITIALIZED = "initialized" + + const val COL_VIEWER = "viewer" + + const val COL_CHAPTER_FLAGS = "chapter_flags" + + const val COL_UNREAD = "unread" + + const val COL_CATEGORY = "category" + + val createTableQuery: String + get() = """CREATE TABLE $TABLE( + $COL_ID INTEGER NOT NULL PRIMARY KEY, + $COL_SOURCE INTEGER NOT NULL, + $COL_URL TEXT NOT NULL, + $COL_ARTIST TEXT, + $COL_AUTHOR TEXT, + $COL_DESCRIPTION TEXT, + $COL_GENRE TEXT, + $COL_TITLE TEXT NOT NULL, + $COL_STATUS INTEGER NOT NULL, + $COL_THUMBNAIL_URL TEXT, + $COL_FAVORITE INTEGER NOT NULL, + $COL_LAST_UPDATE LONG, + $COL_INITIALIZED BOOLEAN NOT NULL, + $COL_VIEWER INTEGER NOT NULL, + $COL_CHAPTER_FLAGS INTEGER NOT NULL + )""" + + val createUrlIndexQuery: String + get() = "CREATE INDEX ${TABLE}_${COL_URL}_index ON $TABLE($COL_URL)" + + val createFavoriteIndexQuery: String + get() = "CREATE INDEX ${TABLE}_${COL_FAVORITE}_index ON $TABLE($COL_FAVORITE)" +}