CREATE TABLE manga_sync(
    _id INTEGER NOT NULL PRIMARY KEY,
    manga_id INTEGER NOT NULL,
    sync_id INTEGER NOT NULL,
    remote_id INTEGER NOT NULL,
    library_id INTEGER,
    title TEXT NOT NULL,
    last_chapter_read REAL NOT NULL,
    total_chapters INTEGER NOT NULL,
    status INTEGER NOT NULL,
    score REAL AS Float NOT NULL,
    remote_url TEXT NOT NULL,
    start_date INTEGER AS Long NOT NULL,
    finish_date INTEGER AS Long NOT NULL,
    UNIQUE (manga_id, sync_id) ON CONFLICT REPLACE,
    FOREIGN KEY(manga_id) REFERENCES mangas (_id)
    ON DELETE CASCADE
);

delete:
DELETE FROM manga_sync
WHERE manga_id = :mangaId AND sync_id = :syncId;

getTracks:
SELECT *
FROM manga_sync;

getTrackById:
SELECT *
FROM manga_sync
WHERE _id = :id;

getTracksByMangaId:
SELECT *
FROM manga_sync
WHERE manga_id = :mangaId;

insert:
INSERT INTO manga_sync(manga_id,sync_id,remote_id,library_id,title,last_chapter_read,total_chapters,status,score,remote_url,start_date,finish_date)
VALUES (:mangaId,:syncId,:remoteId,:libraryId,:title,:lastChapterRead,:totalChapters,:status,:score,:remoteUrl,:startDate,:finishDate);

update:
UPDATE manga_sync
SET
    manga_id = coalesce(:mangaId, manga_id),
    sync_id = coalesce(:syncId, sync_id),
    remote_id = coalesce(:mediaId, remote_id),
    library_id = coalesce(:libraryId, library_id),
    title = coalesce(:title, title),
    last_chapter_read = coalesce(:lastChapterRead, last_chapter_read),
    total_chapters = coalesce(:totalChapter, total_chapters),
    status = coalesce(:status, status),
    score = coalesce(:score, score),
    remote_url = coalesce(:trackingUrl, remote_url),
    start_date = coalesce(:startDate, start_date),
    finish_date = coalesce(:finishDate, finish_date)
WHERE _id = :id;
