2022-04-23 05:29:24 +08:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
CREATE TABLE history(
|
2022-05-28 21:09:27 +08:00
|
|
|
_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)
|
2022-04-23 05:29:24 +08:00
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
2022-05-28 21:09:27 +08:00
|
|
|
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
|
2022-04-23 05:29:24 +08:00
|
|
|
|
|
|
|
resetHistoryById:
|
|
|
|
UPDATE history
|
2022-05-28 21:09:27 +08:00
|
|
|
SET last_read = 0
|
|
|
|
WHERE _id = :historyId;
|
2022-04-23 05:29:24 +08:00
|
|
|
|
|
|
|
resetHistoryByMangaId:
|
|
|
|
UPDATE history
|
2022-05-28 21:09:27 +08:00
|
|
|
SET last_read = 0
|
|
|
|
WHERE _id IN (
|
|
|
|
SELECT H._id
|
2022-04-23 05:29:24 +08:00
|
|
|
FROM mangas M
|
|
|
|
INNER JOIN chapters C
|
|
|
|
ON M._id = C.manga_id
|
|
|
|
INNER JOIN history H
|
2022-05-28 21:09:27 +08:00
|
|
|
ON C._id = H.chapter_id
|
2022-04-23 05:29:24 +08:00
|
|
|
WHERE M._id = :mangaId
|
|
|
|
);
|
|
|
|
|
|
|
|
removeAllHistory:
|
|
|
|
DELETE FROM history;
|
|
|
|
|
|
|
|
removeResettedHistory:
|
|
|
|
DELETE FROM history
|
2022-05-28 21:09:27 +08:00
|
|
|
WHERE last_read = 0;
|
|
|
|
|
2022-05-30 00:12:06 +08:00
|
|
|
upsert:
|
2022-05-28 21:09:27 +08:00
|
|
|
INSERT INTO history(chapter_id, last_read, time_read)
|
2022-05-30 00:12:06 +08:00
|
|
|
VALUES (:chapterId, :readAt, :time_read)
|
|
|
|
ON CONFLICT(chapter_id)
|
|
|
|
DO UPDATE
|
|
|
|
SET
|
|
|
|
last_read = :readAt,
|
|
|
|
time_read = time_read + :time_read
|
|
|
|
WHERE chapter_id = :chapterId;
|