diff --git a/app/src/main/sqldelight/tachiyomi/view/library_view.sq b/app/src/main/sqldelight/tachiyomi/view/library_view.sq new file mode 100644 index 0000000000..96146ca693 --- /dev/null +++ b/app/src/main/sqldelight/tachiyomi/view/library_view.sq @@ -0,0 +1,23 @@ +CREATE VIEW library_view AS +SELECT + M.*, + coalesce(MC.category_id, 0) AS category +FROM ( + SELECT + MS.*, + coalesce(count(*) - sum(read), 0) AS unread, + sum(read) AS has_read, + sum(bookmark) AS bookmark_count + FROM mangas AS MS + LEFT JOIN chapters AS C + ON C.manga_id = MS._id + LEFT JOIN scanlators_view AS filtered_scanlators + ON C.manga_id = filtered_scanlators._id + AND ifnull(C.scanlator, 'N/A') = ifnull(filtered_scanlators.name, '//') -- I assume if it's N/A it shouldn't be filtered + WHERE MS.favorite = 1 + AND filtered_scanlators.name IS NULL + GROUP BY MS._id + ORDER BY MS.title +) AS M +LEFT JOIN mangas_categories AS MC +ON MC.manga_id = M._id; diff --git a/app/src/main/sqldelight/tachiyomi/view/scanlators_view.sq b/app/src/main/sqldelight/tachiyomi/view/scanlators_view.sq new file mode 100644 index 0000000000..4fed8ff6bf --- /dev/null +++ b/app/src/main/sqldelight/tachiyomi/view/scanlators_view.sq @@ -0,0 +1,10 @@ +CREATE VIEW scanlators_view AS -- Probably should migrate these to a real table +WITH RECURSIVE split(seq, _id, name, str) AS ( + SELECT 0, M._id, NULL, replace(ifnull(M.filtered_scanlators, ''), ' & ', ',')||',' FROM mangas AS M + UNION ALL SELECT + seq+1, + _id, + substr(str, 0, instr(str, ',')), + substr(str, instr(str, ',')+1) + FROM split WHERE str != '' +) SELECT _id, name FROM split WHERE split.seq != 0 ORDER BY split.seq ASC;