-- name: ListDeviceInfos :many
SELECT *
FROM device_info;

-- name: ListDeviceAssignments :many
SELECT *
FROM device_assignment
ORDER BY created_date;

-- name: ListDeviceAuth :many
SELECT *
FROM device_auth;

-- name: ListDeviceAliases :many
SELECT *
FROM device_alias;

-- name: InsertDeviceAlias :exec
INSERT INTO device_alias (id, alias)
VALUES (?, ?)
ON DUPLICATE KEY UPDATE alias=alias;

-- name: ReplaceDeviceAuth :exec
REPLACE INTO device_auth (id, api_key, extras)
VALUES (?, ?, ?);

-- name: ReplaceDeviceInfo :exec
REPLACE INTO device_info (id, kind, data)
VALUES (?, ?, ?);

-- name: ReplaceDeviceAssignment :exec
REPLACE INTO device_assignment (id, created_date, `match`, effect)
VALUES (?, ?, ?, ?);

-- name: DeleteDeviceInfo :exec
DELETE
FROM device_info
WHERE id = ?
  AND kind = ?;

-- name: DeleteDeviceInfoByID :exec
DELETE
FROM device_info
WHERE id = ?;

-- name: DeleteDeviceInfoLike :exec
DELETE
FROM device_info
WHERE id LIKE ?;

-- name: DeleteDeviceAssignment :exec
DELETE
FROM device_assignment
WHERE id = ?;

-- name: DeleteDeviceAuth :exec
DELETE
FROM device_auth
WHERE id = ?;

-- name: DeleteDeviceAlias :exec
DELETE
FROM device_alias
WHERE id = ?
  AND alias = ?;

-- name: DeleteDeviceAliasByID :exec
DELETE
FROM device_alias
WHERE id = ?;

-- name: DeleteDeviceAliasByIDLike :exec
DELETE
FROM device_alias
WHERE id LIKE ?;
