-- name: UpsertPage :one
INSERT INTO pages (chapter_id, "index", url, image_url)
VALUES ($1, $2, $3, $4)
ON CONFLICT (chapter_id, "index") DO UPDATE
    SET url       = EXCLUDED.url,
        image_url = EXCLUDED.image_url
RETURNING *;

-- name: ListPagesByChapter :many
SELECT * FROM pages WHERE chapter_id = $1 ORDER BY "index";

-- name: UpdatePageImageURL :exec
UPDATE pages SET image_url = $2 WHERE id = $1;
