2022-04-23 05:29:24 +08:00
|
|
|
CREATE TABLE chapters(
|
|
|
|
_id INTEGER NOT NULL PRIMARY KEY,
|
|
|
|
manga_id INTEGER NOT NULL,
|
|
|
|
url TEXT NOT NULL,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
scanlator TEXT,
|
|
|
|
read INTEGER AS Boolean NOT NULL,
|
|
|
|
bookmark INTEGER AS Boolean NOT NULL,
|
|
|
|
last_page_read INTEGER NOT NULL,
|
|
|
|
chapter_number REAL AS Float NOT NULL,
|
|
|
|
source_order INTEGER NOT NULL,
|
|
|
|
date_fetch INTEGER AS Long NOT NULL,
|
|
|
|
date_upload INTEGER AS Long NOT NULL,
|
|
|
|
FOREIGN KEY(manga_id) REFERENCES mangas (_id)
|
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE INDEX chapters_manga_id_index ON chapters(manga_id);
|
|
|
|
CREATE INDEX chapters_unread_by_manga_index ON chapters(manga_id, read) WHERE read = 0;
|
|
|
|
|
|
|
|
getChapterById:
|
|
|
|
SELECT *
|
|
|
|
FROM chapters
|
|
|
|
WHERE _id = :id;
|
|
|
|
|
2022-06-12 23:23:41 +08:00
|
|
|
getChaptersByMangaId:
|
2022-04-23 05:29:24 +08:00
|
|
|
SELECT *
|
|
|
|
FROM chapters
|
2022-05-28 21:09:27 +08:00
|
|
|
WHERE manga_id = :mangaId;
|
|
|
|
|
2022-06-11 23:38:39 +08:00
|
|
|
removeChaptersWithIds:
|
|
|
|
DELETE FROM chapters
|
|
|
|
WHERE _id IN :chapterIds;
|
|
|
|
|
|
|
|
insert:
|
|
|
|
INSERT INTO chapters(
|
|
|
|
manga_id,
|
|
|
|
url,
|
|
|
|
name,
|
|
|
|
scanlator,
|
|
|
|
read,
|
|
|
|
bookmark,
|
|
|
|
last_page_read,
|
|
|
|
chapter_number,
|
|
|
|
source_order,
|
|
|
|
date_fetch,
|
|
|
|
date_upload
|
|
|
|
)
|
|
|
|
VALUES (
|
|
|
|
:mangaId,
|
|
|
|
:url,
|
|
|
|
:name,
|
|
|
|
:scanlator,
|
|
|
|
:read,
|
|
|
|
:bookmark,
|
|
|
|
:lastPageRead,
|
|
|
|
:chapterNumber,
|
|
|
|
:sourceOrder,
|
|
|
|
:dateFetch,
|
|
|
|
:dateUpload
|
|
|
|
);
|
|
|
|
|
2022-05-28 21:09:27 +08:00
|
|
|
update:
|
|
|
|
UPDATE chapters
|
|
|
|
SET manga_id = coalesce(:mangaId, manga_id),
|
|
|
|
url = coalesce(:url, url),
|
|
|
|
name = coalesce(:name, name),
|
|
|
|
scanlator = coalesce(:scanlator, scanlator),
|
|
|
|
read = coalesce(:read, read),
|
|
|
|
bookmark = coalesce(:bookmark, bookmark),
|
|
|
|
last_page_read = coalesce(:lastPageRead, last_page_read),
|
|
|
|
chapter_number = coalesce(:chapterNumber, chapter_number),
|
|
|
|
source_order = coalesce(:sourceOrder, source_order),
|
|
|
|
date_fetch = coalesce(:dateFetch, date_fetch),
|
|
|
|
date_upload = coalesce(:dateUpload, date_upload)
|
2022-06-11 23:38:39 +08:00
|
|
|
WHERE _id = :chapterId;
|
|
|
|
|
|
|
|
selectLastInsertedRowId:
|
|
|
|
SELECT last_insert_rowid();
|