-- name: SelectChannelByName :one
SELECT * FROM data_channel WHERE name = $1 LIMIT 1;

-- name: InsertChannel :exec
INSERT INTO data_channel (name, logged, hub, event_name, location_name)
VALUES (
    sqlc.arg(name)::text,
    sqlc.arg(logged)::boolean, sqlc.arg(hub)::boolean,
    sqlc.arg(event_name)::text, sqlc.arg(location_name)::text
);

-- name: SelectChannels :many
SELECT * FROM data_channel
WHERE (sqlc.arg(filter_name)::bool = false OR name = ANY(sqlc.arg(names)::text[]))
  AND (sqlc.arg(filter_logged)::bool = false OR logged = sqlc.arg(logged))
  AND (sqlc.arg(filter_event_name)::bool = false OR event_name = sqlc.arg(event_name))
  AND (sqlc.arg(filter_location_name)::bool = false OR location_name = sqlc.arg(location_name))
LIMIT sqlc.arg(limit_size)::int;

-- name: UpdateChannel :exec
UPDATE data_channel
SET logged=sqlc.arg(logged)::boolean,
    hub=sqlc.arg(hub)::boolean,
    event_name=sqlc.arg(event_name)::text,
    location_name=sqlc.arg(location_name)::text
WHERE name=sqlc.arg(name)::text;

-- name: DeleteChannel :exec
DELETE FROM data_channel WHERE name=$1;
