2022-04-01 15:45:23 -05:00
|
|
|
-- name: GetAPIKeyByID :one
|
|
|
|
|
SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
|
|
|
|
api_keys
|
|
|
|
|
WHERE
|
|
|
|
|
id = $1
|
|
|
|
|
LIMIT
|
|
|
|
|
1;
|
|
|
|
|
|
2022-06-17 00:26:40 -05:00
|
|
|
-- name: GetAPIKeysLastUsedAfter :many
|
|
|
|
|
SELECT * FROM api_keys WHERE last_used > $1;
|
|
|
|
|
|
2022-10-06 15:02:27 -04:00
|
|
|
-- name: GetAPIKeysByLoginType :many
|
|
|
|
|
SELECT * FROM api_keys WHERE login_type = $1;
|
|
|
|
|
|
2022-04-01 15:45:23 -05:00
|
|
|
-- name: InsertAPIKey :one
|
|
|
|
|
INSERT INTO
|
|
|
|
|
api_keys (
|
|
|
|
|
id,
|
2022-06-01 14:58:55 -05:00
|
|
|
lifetime_seconds,
|
2022-04-01 15:45:23 -05:00
|
|
|
hashed_secret,
|
2022-06-22 12:32:21 -05:00
|
|
|
ip_address,
|
2022-04-01 15:45:23 -05:00
|
|
|
user_id,
|
|
|
|
|
last_used,
|
|
|
|
|
expires_at,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at,
|
2022-09-20 03:39:02 +10:00
|
|
|
login_type,
|
|
|
|
|
scope
|
2022-04-01 15:45:23 -05:00
|
|
|
)
|
|
|
|
|
VALUES
|
2022-06-01 14:58:55 -05:00
|
|
|
(@id,
|
|
|
|
|
-- If the lifetime is set to 0, default to 24hrs
|
|
|
|
|
CASE @lifetime_seconds::bigint
|
|
|
|
|
WHEN 0 THEN 86400
|
|
|
|
|
ELSE @lifetime_seconds::bigint
|
|
|
|
|
END
|
2022-09-20 03:39:02 +10:00
|
|
|
, @hashed_secret, @ip_address, @user_id, @last_used, @expires_at, @created_at, @updated_at, @login_type, @scope) RETURNING *;
|
2022-04-01 15:45:23 -05:00
|
|
|
|
|
|
|
|
-- name: UpdateAPIKeyByID :exec
|
|
|
|
|
UPDATE
|
|
|
|
|
api_keys
|
|
|
|
|
SET
|
|
|
|
|
last_used = $2,
|
|
|
|
|
expires_at = $3,
|
2022-08-17 18:00:53 -05:00
|
|
|
ip_address = $4
|
2022-04-01 15:45:23 -05:00
|
|
|
WHERE
|
|
|
|
|
id = $1;
|
2022-05-27 16:47:03 -04:00
|
|
|
|
|
|
|
|
-- name: DeleteAPIKeyByID :exec
|
|
|
|
|
DELETE
|
|
|
|
|
FROM
|
|
|
|
|
api_keys
|
|
|
|
|
WHERE
|
|
|
|
|
id = $1;
|
2022-10-19 21:12:03 -05:00
|
|
|
|
|
|
|
|
-- name: DeleteAPIKeysByUserID :exec
|
|
|
|
|
DELETE FROM
|
|
|
|
|
api_keys
|
|
|
|
|
WHERE
|
|
|
|
|
user_id = $1;
|