-- name: SelectPagesOfSite :many
SELECT * FROM pages
WHERE site_id = ? ORDER BY sort_order ASC;

-- name: SelectPage :one
SELECT * FROM pages WHERE id = ? LIMIT 1;

-- name: SelectPageByGUID :one
SELECT * FROM pages WHERE guid = ? LIMIT 1;

-- name: SelectPageBySlugAndSite :one
SELECT * FROM pages WHERE site_id = ? AND slug = ? LIMIT 1;

-- name: InsertPage :one
INSERT INTO pages (
    site_id, guid, title, slug, body, page_type, show_in_nav, sort_order, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id;

-- name: UpdatePage :exec
UPDATE pages SET
    title = ?,
    slug = ?,
    body = ?,
    page_type = ?,
    show_in_nav = ?,
    updated_at = ?
WHERE id = ?;

-- name: UpdatePageSortOrder :exec
UPDATE pages SET sort_order = ? WHERE id = ?;

-- name: DeletePage :exec
DELETE FROM pages WHERE id = ?;
