2022-04-22 17:29:24 -04:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
CREATE TABLE history(
|
2022-05-28 09:09:27 -04: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-22 17:29:24 -04:00
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
2022-05-28 09:09:27 -04:00
|
|
|
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
|
2022-04-22 17:29:24 -04:00
|
|
|
|
|
|
|
resetHistoryById:
|
|
|
|
UPDATE history
|
2022-05-28 09:09:27 -04:00
|
|
|
SET last_read = 0
|
|
|
|
WHERE _id = :historyId;
|
2022-04-22 17:29:24 -04:00
|
|
|
|
|
|
|
resetHistoryByMangaId:
|
|
|
|
UPDATE history
|
2022-05-28 09:09:27 -04:00
|
|
|
SET last_read = 0
|
|
|
|
WHERE _id IN (
|
|
|
|
SELECT H._id
|
2022-04-22 17:29:24 -04:00
|
|
|
FROM mangas M
|
|
|
|
INNER JOIN chapters C
|
|
|
|
ON M._id = C.manga_id
|
|
|
|
INNER JOIN history H
|
2022-05-28 09:09:27 -04:00
|
|
|
ON C._id = H.chapter_id
|
2022-04-22 17:29:24 -04:00
|
|
|
WHERE M._id = :mangaId
|
|
|
|
);
|
|
|
|
|
|
|
|
removeAllHistory:
|
|
|
|
DELETE FROM history;
|
|
|
|
|
|
|
|
removeResettedHistory:
|
|
|
|
DELETE FROM history
|
2022-05-28 09:09:27 -04:00
|
|
|
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;
|