-- name: UpsertSource :one
INSERT INTO sources (id, name, lang, is_nsfw)
VALUES ($1, $2, $3, $4)
ON CONFLICT (id) DO UPDATE
    SET name    = EXCLUDED.name,
        lang    = EXCLUDED.lang,
        is_nsfw = EXCLUDED.is_nsfw
RETURNING *;

-- name: ListSources :many
SELECT * FROM sources ORDER BY id;

-- name: GetSourceByID :one
SELECT * FROM sources WHERE id = $1;

-- name: GetSourceMeta :one
SELECT value FROM source_meta
WHERE source_id = $1 AND key = $2;

-- name: SetSourceMeta :exec
INSERT INTO source_meta (source_id, key, value)
VALUES ($1, $2, $3)
ON CONFLICT (source_id, key) DO UPDATE
    SET value = EXCLUDED.value;
