Files
sonr/internal/database/sink/query_highway.sql
T

139 lines
2.7 KiB
SQL
Raw Normal View History

2024-12-16 15:29:54 -05:00
-- name: InsertCredential :one
INSERT INTO credentials (
handle,
credential_id,
origin,
type,
transports
2024-12-18 15:53:45 -05:00
) VALUES ($1, $2, $3, $4, $5)
2024-12-16 15:29:54 -05:00
RETURNING *;
-- name: InsertProfile :one
INSERT INTO profiles (
address,
handle,
origin,
name
2024-12-18 15:53:45 -05:00
) VALUES ($1, $2, $3, $4)
2024-12-16 15:29:54 -05:00
RETURNING *;
-- name: GetProfileByID :one
SELECT * FROM profiles
2024-12-18 15:53:45 -05:00
WHERE id = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: GetProfileByAddress :one
SELECT * FROM profiles
2024-12-18 15:53:45 -05:00
WHERE address = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: GetChallengeBySessionID :one
SELECT challenge FROM sessions
2024-12-18 15:53:45 -05:00
WHERE id = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: GetHumanVerificationNumbers :one
SELECT is_human_first, is_human_last FROM sessions
2024-12-18 15:53:45 -05:00
WHERE id = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: GetSessionByID :one
SELECT * FROM sessions
2024-12-18 15:53:45 -05:00
WHERE id = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: GetSessionByClientIP :one
SELECT * FROM sessions
2024-12-18 15:53:45 -05:00
WHERE client_ipaddr = $1 AND deleted_at IS NULL
2024-12-16 15:29:54 -05:00
LIMIT 1;
-- name: UpdateSessionHumanVerification :one
UPDATE sessions
SET
2024-12-18 15:53:45 -05:00
is_human_first = $1,
is_human_last = $2,
2024-12-16 15:29:54 -05:00
updated_at = CURRENT_TIMESTAMP
2024-12-18 15:53:45 -05:00
WHERE id = $3
2024-12-16 15:29:54 -05:00
RETURNING *;
-- name: UpdateSessionWithProfileID :one
UPDATE sessions
SET
2024-12-18 15:53:45 -05:00
profile_id = $1,
2024-12-16 15:29:54 -05:00
updated_at = CURRENT_TIMESTAMP
2024-12-18 15:53:45 -05:00
WHERE id = $2
2024-12-16 15:29:54 -05:00
RETURNING *;
-- name: CheckHandleExists :one
SELECT COUNT(*) > 0 as handle_exists FROM profiles
2024-12-18 15:53:45 -05:00
WHERE handle = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL;
-- name: GetCredentialsByHandle :many
SELECT * FROM credentials
2024-12-18 15:53:45 -05:00
WHERE handle = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL;
-- name: GetCredentialByID :one
SELECT * FROM credentials
2024-12-18 15:53:45 -05:00
WHERE credential_id = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL
LIMIT 1;
-- name: SoftDeleteCredential :exec
UPDATE credentials
SET deleted_at = CURRENT_TIMESTAMP
2024-12-18 15:53:45 -05:00
WHERE credential_id = $1;
2024-12-16 15:29:54 -05:00
-- name: SoftDeleteProfile :exec
UPDATE profiles
SET deleted_at = CURRENT_TIMESTAMP
2024-12-18 15:53:45 -05:00
WHERE address = $1;
2024-12-16 15:29:54 -05:00
-- name: UpdateProfile :one
UPDATE profiles
SET
2024-12-18 15:53:45 -05:00
name = $1,
handle = $2,
2024-12-16 15:29:54 -05:00
updated_at = CURRENT_TIMESTAMP
2024-12-18 15:53:45 -05:00
WHERE address = $3
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL
RETURNING *;
-- name: GetProfileByHandle :one
SELECT * FROM profiles
2024-12-18 15:53:45 -05:00
WHERE handle = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL
LIMIT 1;
-- name: GetVaultConfigByCID :one
SELECT * FROM vaults
2024-12-18 15:53:45 -05:00
WHERE cid = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL
LIMIT 1;
-- name: GetVaultRedirectURIBySessionID :one
SELECT redirect_uri FROM vaults
2024-12-18 15:53:45 -05:00
WHERE session_id = $1
2024-12-16 15:29:54 -05:00
AND deleted_at IS NULL
LIMIT 1;
-- name: CreateSession :one
INSERT INTO sessions (
id,
browser_name,
browser_version,
client_ipaddr,
platform,
is_desktop,
is_mobile,
is_tablet,
is_tv,
is_bot,
challenge,
is_human_first,
is_human_last,
profile_id
2024-12-18 15:53:45 -05:00
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
2024-12-16 15:29:54 -05:00
RETURNING *;