-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
data/src/commonMain/sqldelight/tachiyomi/migrations/27.sqm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
DROP VIEW IF EXISTS scanlators_view; | ||
CREATE VIEW scanlators_view AS | ||
SELECT S.* FROM ( | ||
WITH RECURSIVE split(seq, _id, name, str) AS ( | ||
SELECT 0, mangas._id, NULL, mangas.filtered_scanlators||' [.] ' FROM mangas WHERE mangas._id | ||
UNION ALL SELECT | ||
seq+1, | ||
_id, | ||
substr(str, 0, instr(str, ' [.] ')), | ||
substr(str, instr(str, ' [.] ')+5) | ||
FROM split WHERE str != '' | ||
) | ||
SELECT _id AS manga_id, name FROM split WHERE name != '' ORDER BY split.seq ASC | ||
) AS S; | ||
|
||
DROP VIEW IF EXISTS library_view; | ||
CREATE VIEW library_view AS | ||
SELECT | ||
M.*, | ||
coalesce(C.total, 0) AS total, | ||
coalesce(C.read_count, 0) AS has_read, | ||
coalesce(C.bookmark_count, 0) AS bookmark_count, | ||
coalesce(MC.category_id, 0) AS category, | ||
coalesce(C.latestUpload, 0) AS latestUpload, | ||
coalesce(C.lastRead, 0) AS lastRead, | ||
coalesce(C.lastFetch, 0) AS lastFetch | ||
FROM mangas AS M | ||
LEFT JOIN ( | ||
SELECT | ||
chapters.manga_id, | ||
count(*) AS total, | ||
sum(read) AS read_count, | ||
sum(bookmark) AS bookmark_count, | ||
coalesce(max(chapters.date_upload), 0) AS latestUpload, | ||
coalesce(max(history.history_last_read), 0) AS lastRead, | ||
coalesce(max(chapters.date_fetch), 0) AS lastFetch | ||
FROM chapters | ||
LEFT JOIN scanlators_view AS filtered_scanlators | ||
ON chapters.manga_id = filtered_scanlators.manga_id | ||
AND chapters.scanlator = filtered_scanlators.name | ||
LEFT JOIN history | ||
ON chapters._id = history.history_chapter_id | ||
WHERE filtered_scanlators.name IS NULL | ||
GROUP BY chapters.manga_id | ||
) AS C | ||
ON M._id = C.manga_id | ||
LEFT JOIN (SELECT * FROM mangas_categories) AS MC | ||
ON MC.manga_id = M._id | ||
WHERE M.favorite = 1 | ||
ORDER BY M.title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters