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;

getChapterByMangaId:
SELECT *
FROM chapters
WHERE manga_id = :mangaId;