filer/db/queries.sql

48 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

2023-08-25 02:25:38 +02:00
-- name: CreateUser :one
insert into users (username, password) values (@username, @password)
returning *;
-- name: GetUser :one
select * from users where username = @username;
-- name: GetUsers :many
select * from users order by id;
-- name: UpdateUser :one
update users set
username = @username, password = @password, is_admin = @is_admin
where id = @id
returning *;
-- name: DeleteUser :exec
delete from users where id = @id;
-- name: GetUserByToken :one
select u.* from users u join tokens t on u.id = t.user_id
where t.token = @token;
-- name: CreateToken :one
insert into tokens (user_id, token) values (@user_id, @token)
returning *;
-- name: DeleteToken :exec
delete from tokens where id = @id;
-- name: CreateFile :one
insert into files
(id, user_id, filename, content_type, hash, size, created_at, expires)
values (@id, @user_id, @filename, @content_type, @hash, @size, unixepoch(), @expires)
returning *;
-- name: GetFileByID :one
select * from files where id = @id;
-- name: GetFileByName :one
select * from files where filename = @filename and hash = @hash;
-- name: GetExpiredFiles :many
select * from files where expires < unixepoch();
-- name: DeleteFile :exec
delete from files where id = @id;