-- name: GetUser :one
SELECT * FROM app_user
WHERE user_name = ? LIMIT 1;
--
-- name: ListUsers :many
SELECT * FROM app_user
ORDER BY user_name;

-- name: CreateUser :exec
INSERT INTO app_user (
    user_name, user_pass
)
VALUES (?, ?);

-- name: UpdateUser :exec
UPDATE app_user
SET user_pass = ?
WHERE user_name = ?;

-- name: DeleteUser :exec
DELETE FROM app_user
WHERE user_name = ?;
--
-- name: GetNewsEntry :one
SELECT * FROM news
WHERE id = ? LIMIT 1;

-- name: ListNews :many
SELECT * FROM news
ORDER BY news_date;

-- name: ListActiveNews :many
SELECT * FROM news
WHERE display = 1
ORDER BY news_date;

-- name: CreateNewsEntry :exec
INSERT INTO news (
    news_title, news_text, news_date,
    news_publish, display
) VALUES (?, ?, ?, ?, ?);

-- name: UpdateNewsEntry :exec
UPDATE news
SET
    news_title = ?, news_text = ?,
    news_date = ?, news_publish = ?, display = ?
WHERE id = ?;

-- name: DeleteNewsEntry :exec
DELETE FROM news
WHERE id = ?;
--
-- name: ListRetailers :many
SELECT * FROM retailer
ORDER BY shopname;

-- name: ListActiveRetailers :many
SELECT * FROM retailer
WHERE display = 1
ORDER BY shopname;

-- name: CreateRetailer :exec
INSERT INTO retailer (
    shopname, url, country, display
) VALUES (?, ?, ?, ?);

-- name: UpdateRetailer :exec
UPDATE retailer
SET shopname = ?, url = ?, country = ?, display = ?
WHERE id = ?;

-- name: DeleteRetailer :exec
DELETE FROM news
WHERE id = ?;
