route/internal/database/migrations/postgres.sql

43 lines
1.5 KiB
SQL

-- name: insert-certificate
INSERT INTO Certificates(domain, data) VALUES ($1, $2);
-- name: find-one-certificate
SELECT id, domain, data, created_at, edited_at, active FROM Certificates WHERE domain = $1 LIMIT 1;
-- name: remove-one-certificate
DELETE FROM Certificates WHERE domain = $1 LIMIT 1;
-- name: get-all-certificates
SELECT id, domain, data, created_at, edited_at, active FROM Certificates;
-- name: insert-route
INSERT INTO Routes(creator, hostname) VALUES ($1, $2);
-- name: find-one-route-by-id
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE id = $1 LIMIT 1;
-- name: find-one-route-by-host
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE hostname = $1 LIMIT 1;
-- name: find-all-routes-for-user
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE creator = $1;
-- name: delete-one-route
DELETE FROM Routes WHERE id = $1 AND domain = $2 LIMIT 1;
-- name: insert-token
INSERT INTO Tokens(body, creator, scopes, expires_at) VALUES ($1, $2, $3, $4);
-- name: get-one-token
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE id = $1 LIMIT 1;
-- name: get-one-token-by-body
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE body = $1 LIMIT 1;
-- name: get-all-tokens-for-user
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE creator = $1;
-- name: remove-one-token
DELETE FROM Tokens WHERE id = $1 LIMIT 1;