-- name: CreateFile :one
INSERT INTO files (
  name, description, mimetype, size, blake2
) VALUES (
  $1,$2,$3,$4,$5
)
ON CONFLICT DO NOTHING -- Handle this in application code
RETURNING *;

-- name: GetFileByUUID :one
SELECT * 
FROM files 
WHERE id = $1;

-- name: GetFileByBlake2 :one
SELECT *
FROM files
WHERE blake2 = $1;

-- name: UpdateFileDescription :exec
UPDATE files 
SET description = $1
WHERE id = $2;

-- name: DeleteFile :exec
DELETE 
FROM files
WHERE id = $1;

-- name: UpdateFile :exec
UPDATE files
SET updated = NOW()
WHERE id = $1;

-- name: GetFileMime :one
SELECT mimetype FROM files
WHERE id = $1;

-- name: GetAllFiles :many
SELECT * FROM files
ORDER BY created DESC;
