komikku/app/src/main/sqldelight/data/history.sq
AntsyLich f0fb91b84b Reader: Save reading progress with SQLDelight (#7185)
* Use SQLDelight in reader to update history

* Move chapter progress to sqldelight

* Review Changes

Co-Authored-By: inorichi <len@kanade.eu>

* Review Changes 2

Co-authored-by: FourTOne5 <59261191+FourTOne5@users.noreply.github.com>
Co-authored-by: inorichi <len@kanade.eu>
(cherry picked from commit 809da49301cceacd433f38354fb04fc616efcc5f)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt
2022-05-29 18:38:40 -04:00

47 lines
997 B
Text

import java.util.Date;
CREATE TABLE history(
_id INTEGER NOT NULL PRIMARY KEY,
chapter_id INTEGER NOT NULL UNIQUE,
last_read INTEGER AS Date,
time_read INTEGER NOT NULL,
FOREIGN KEY(chapter_id) REFERENCES chapters (_id)
ON DELETE CASCADE
);
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
resetHistoryById:
UPDATE history
SET last_read = 0
WHERE _id = :historyId;
resetHistoryByMangaId:
UPDATE history
SET last_read = 0
WHERE _id IN (
SELECT H._id
FROM mangas M
INNER JOIN chapters C
ON M._id = C.manga_id
INNER JOIN history H
ON C._id = H.chapter_id
WHERE M._id = :mangaId
);
removeAllHistory:
DELETE FROM history;
removeResettedHistory:
DELETE FROM history
WHERE last_read = 0;
insert:
INSERT INTO history(chapter_id, last_read, time_read)
VALUES (:chapterId, :readAt, :readDuration);
update:
UPDATE history
SET last_read = :readAt,
time_read = time_read + :sessionReadDuration
WHERE chapter_id = :chapterId;