mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 04:47:56 +01:00
Migrate History screen database calls to SQLDelight (#6933)
* Migrate History screen database call to SQLDelight - Move all migrations to SQLDelight - Move all tables to SQLDelight Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com> * Changes from review comments * Add adapters to database * Remove logging of database version in App * Change query name for paging source queries * Update migrations * Make SQLite Callback handle migration - To ensure it updates the database * Use SQLDelight Schema version for Callback database version Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>
This commit is contained in:
46
app/src/main/sqldelight/view/historyView.sq
Normal file
46
app/src/main/sqldelight/view/historyView.sq
Normal file
@@ -0,0 +1,46 @@
|
||||
CREATE VIEW historyView AS
|
||||
SELECT
|
||||
history.history_id AS id,
|
||||
mangas._id AS mangaId,
|
||||
chapters._id AS chapterId,
|
||||
mangas.title,
|
||||
mangas.thumbnail_url AS thumnailUrl,
|
||||
chapters.chapter_number AS chapterNumber,
|
||||
history.history_last_read AS readAt,
|
||||
max_last_read.history_last_read AS maxReadAt,
|
||||
max_last_read.history_chapter_id AS maxReadAtChapterId
|
||||
FROM mangas
|
||||
JOIN chapters
|
||||
ON mangas._id = chapters.manga_id
|
||||
JOIN history
|
||||
ON chapters._id = history.history_chapter_id
|
||||
JOIN (
|
||||
SELECT chapters.manga_id,chapters._id AS history_chapter_id, MAX(history.history_last_read) AS history_last_read
|
||||
FROM chapters JOIN history
|
||||
ON chapters._id = history.history_chapter_id
|
||||
GROUP BY chapters.manga_id
|
||||
) AS max_last_read
|
||||
ON chapters.manga_id = max_last_read.manga_id;
|
||||
|
||||
countHistory:
|
||||
SELECT count(*)
|
||||
FROM historyView
|
||||
WHERE historyView.readAt > 0
|
||||
AND maxReadAtChapterId = historyView.chapterId
|
||||
AND lower(historyView.title) LIKE ('%' || :query || '%');
|
||||
|
||||
history:
|
||||
SELECT
|
||||
id,
|
||||
mangaId,
|
||||
chapterId,
|
||||
title,
|
||||
thumnailUrl,
|
||||
chapterNumber,
|
||||
readAt
|
||||
FROM historyView
|
||||
WHERE historyView.readAt > 0
|
||||
AND maxReadAtChapterId = historyView.chapterId
|
||||
AND lower(historyView.title) LIKE ('%' || :query || '%')
|
||||
ORDER BY readAt DESC
|
||||
LIMIT :limit OFFSET :offset;
|
||||
Reference in New Issue
Block a user