Files
descrybe/apps/api/sql/queries/api_keys.sql
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

25 lines
684 B
SQL

-- name: CreateAPIKey :one
INSERT INTO api_keys (company_id, user_id, name, key_hash, key_prefix)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;
-- name: ListAPIKeysByCompany :many
SELECT id, company_id, user_id, name, key_prefix, last_used_at, revoked_at, created_at, updated_at
FROM api_keys
WHERE company_id = $1 AND revoked_at IS NULL
ORDER BY created_at DESC;
-- name: GetAPIKeyByHash :one
SELECT * FROM api_keys
WHERE key_hash = $1 AND revoked_at IS NULL
LIMIT 1;
-- name: RevokeAPIKey :one
UPDATE api_keys
SET revoked_at = now(), updated_at = now()
WHERE id = $1 AND company_id = $2
RETURNING *;
-- name: TouchAPIKey :exec
UPDATE api_keys SET last_used_at = now() WHERE id = $1;