- Uses the new `asObservable` function to change the database calls to use SQLDelight, which should make the impact minimal when it comes to bugs. - Use interactors where they already exist - The todos are for the Compose rewrite - Removed unused StorIO methods/queries - Tested loading library, move manga to new category, unfavorite multiple manga, move multiple manga from one category to another, change filter, sort and display settings (with and without per category settings), (un)mark chapters, start/delete downloads Thank Syer for asObservable Co-authored-by: jobobby04 <17078382+jobobby04@users.noreply.github.com> Co-authored-by: jobobby04 <17078382+jobobby04@users.noreply.github.com> (cherry picked from commit 05085fe57fe4c3ada497f93b8cd282a5009cdbbb) # Conflicts: # app/src/main/java/eu/kanade/data/manga/MangaRepositoryImpl.kt # app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt # app/src/main/java/eu/kanade/tachiyomi/data/database/queries/CategoryQueries.kt # app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt # app/src/main/java/eu/kanade/tachiyomi/data/database/queries/TrackQueries.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt # app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt
188 lines
4.8 KiB
Text
188 lines
4.8 KiB
Text
import java.lang.String;
|
|
import kotlin.collections.List;
|
|
|
|
CREATE TABLE mangas(
|
|
_id INTEGER NOT NULL PRIMARY KEY,
|
|
source INTEGER NOT NULL,
|
|
url TEXT NOT NULL,
|
|
artist TEXT,
|
|
author TEXT,
|
|
description TEXT,
|
|
genre TEXT AS List<String>,
|
|
title TEXT NOT NULL,
|
|
status INTEGER NOT NULL,
|
|
thumbnail_url TEXT,
|
|
favorite INTEGER AS Boolean NOT NULL,
|
|
last_update INTEGER AS Long,
|
|
next_update INTEGER AS Long,
|
|
initialized INTEGER AS Boolean NOT NULL,
|
|
viewer INTEGER NOT NULL,
|
|
chapter_flags INTEGER NOT NULL,
|
|
cover_last_modified INTEGER AS Long NOT NULL,
|
|
date_added INTEGER AS Long NOT NULL,
|
|
filtered_scanlators TEXT AS List<String>
|
|
);
|
|
|
|
CREATE INDEX library_favorite_index ON mangas(favorite) WHERE favorite = 1;
|
|
CREATE INDEX mangas_url_index ON mangas(url);
|
|
|
|
insert:
|
|
INSERT INTO mangas(source,url,artist,author,description,genre,title,status,thumbnail_url,favorite,last_update,next_update,initialized,viewer,chapter_flags,cover_last_modified,date_added)
|
|
VALUES (:source,:url,:artist,:author,:description,:genre,:title,:status,:thumbnail_url,:favorite,:last_update,:next_update,:initialized,:viewer,:chapter_flags,:cover_last_modified,:date_added);
|
|
|
|
getMangaById:
|
|
SELECT *
|
|
FROM mangas
|
|
WHERE _id = :id;
|
|
|
|
getMangaByUrlAndSource:
|
|
SELECT *
|
|
FROM mangas
|
|
WHERE url = :url AND source = :source;
|
|
|
|
getFavorites:
|
|
SELECT *
|
|
FROM mangas
|
|
WHERE favorite = 1;
|
|
|
|
getReadMangaNotInLibrary:
|
|
SELECT mangas.*
|
|
FROM mangas
|
|
WHERE favorite = 0 AND _id IN(
|
|
SELECT chapters.manga_id FROM chapters WHERE read = 1 OR last_page_read != 0
|
|
);
|
|
|
|
getSourceIdWithFavoriteCount:
|
|
SELECT
|
|
source,
|
|
count(*)
|
|
FROM mangas
|
|
WHERE favorite = 1
|
|
GROUP BY source;
|
|
|
|
getFavoriteBySourceId:
|
|
SELECT *
|
|
FROM mangas
|
|
WHERE favorite = 1
|
|
AND source = :sourceId;
|
|
|
|
getDuplicateLibraryManga:
|
|
SELECT *
|
|
FROM mangas
|
|
WHERE favorite = 1
|
|
AND LOWER(title) = :title
|
|
AND source != :source
|
|
LIMIT 1;
|
|
|
|
resetViewerFlags:
|
|
UPDATE mangas
|
|
SET viewer = 0;
|
|
|
|
getSourceIdsWithNonLibraryManga:
|
|
SELECT source, COUNT(*) AS manga_count
|
|
FROM mangas
|
|
WHERE favorite = 0
|
|
GROUP BY source;
|
|
|
|
getRecentlyUpdated:
|
|
SELECT *
|
|
FROM mangas M
|
|
JOIN chapters C
|
|
ON M._id = C.manga_id
|
|
WHERE M.favorite = 1
|
|
AND C.date_upload > :after
|
|
AND C.date_fetch > M.date_added
|
|
ORDER BY C.date_upload DESC;
|
|
|
|
getLibrary:
|
|
SELECT M.*, COALESCE(MC.category_id, 0) AS category
|
|
FROM (
|
|
SELECT mangas.*, COALESCE(C.unreadCount, 0) AS unread_count, COALESCE(R.readCount, 0) AS read_count
|
|
FROM mangas
|
|
LEFT JOIN (
|
|
SELECT chapters.manga_id, COUNT(*) AS unreadCount
|
|
FROM chapters
|
|
WHERE chapters.read = 0
|
|
GROUP BY chapters.manga_id
|
|
) AS C
|
|
ON mangas._id = C.manga_id
|
|
LEFT JOIN (
|
|
SELECT chapters.manga_id, COUNT(*) AS readCount
|
|
FROM chapters
|
|
WHERE chapters.read = 1
|
|
GROUP BY chapters.manga_id
|
|
) AS R
|
|
WHERE mangas.favorite = 1
|
|
GROUP BY mangas._id
|
|
ORDER BY mangas.title
|
|
) AS M
|
|
LEFT JOIN (
|
|
SELECT *
|
|
FROM mangas_categories
|
|
) AS MC
|
|
ON M._id = MC.manga_id;
|
|
|
|
getLastRead:
|
|
SELECT M.*, MAX(H.last_read) AS max
|
|
FROM mangas M
|
|
JOIN chapters C
|
|
ON M._id = C.manga_id
|
|
JOIN history H
|
|
ON C._id = H.chapter_id
|
|
WHERE M.favorite = 1
|
|
GROUP BY M._id
|
|
ORDER BY max ASC;
|
|
|
|
getLatestByChapterUploadDate:
|
|
SELECT M.*, MAX(C.date_upload) AS max
|
|
FROM mangas M
|
|
JOIN chapters C
|
|
ON M._id = C.manga_id
|
|
GROUP BY M._id
|
|
ORDER BY max ASC;
|
|
|
|
getLatestByChapterFetchDate:
|
|
SELECT M.*, MAX(C.date_fetch) AS max
|
|
FROM mangas M
|
|
JOIN chapters C
|
|
ON M._id = C.manga_id
|
|
GROUP BY M._id
|
|
ORDER BY max ASC;
|
|
|
|
deleteMangasNotInLibraryBySourceIds:
|
|
DELETE FROM mangas
|
|
WHERE favorite = 0 AND source IN :sourceIdsAND AND _id NOT IN (
|
|
SELECT manga_id FROM merged WHERE manga_id != merge_id
|
|
);
|
|
|
|
deleteMangasNotInLibraryAndNotReadBySourceIds:
|
|
DELETE FROM mangas
|
|
WHERE favorite = 0 AND source IN :sourceIdsAND AND _id NOT IN (
|
|
SELECT manga_id FROM merged WHERE manga_id != merge_id
|
|
) AND _id NOT IN (
|
|
SELECT manga_id FROM chapters WHERE read = 1 OR last_page_read != 0
|
|
);
|
|
|
|
update:
|
|
UPDATE mangas SET
|
|
source = coalesce(:source, source),
|
|
url = coalesce(:url, url),
|
|
artist = coalesce(:artist, artist),
|
|
author = coalesce(:author, author),
|
|
description = coalesce(:description, description),
|
|
genre = coalesce(:genre, genre),
|
|
title = coalesce(:title, title),
|
|
status = coalesce(:status, status),
|
|
thumbnail_url = coalesce(:thumbnailUrl, thumbnail_url),
|
|
favorite = coalesce(:favorite, favorite),
|
|
last_update = coalesce(:lastUpdate, last_update),
|
|
initialized = coalesce(:initialized, initialized),
|
|
viewer = coalesce(:viewer, viewer),
|
|
chapter_flags = coalesce(:chapterFlags, chapter_flags),
|
|
cover_last_modified = coalesce(:coverLastModified, cover_last_modified),
|
|
date_added = coalesce(:dateAdded, date_added),
|
|
filtered_scanlators = coalesce(:filteredScanlators, filtered_scanlators)
|
|
WHERE _id = :mangaId;
|
|
|
|
selectLastInsertedRowId:
|
|
SELECT last_insert_rowid();
|