fix: update sqlc queries to match schema and use SQLite conventions

This commit is contained in:
Prad Nukala 2024-12-29 01:22:19 -05:00
parent 014ce98359
commit 26a322a5ea

View File

@ -1,127 +1,139 @@
-- AI! Update the sqlc queries to match the schema and follow sqlite conventions
-- name: InsertCredential :one -- name: InsertCredential :one
INSERT INTO credentials ( INSERT INTO credentials (
id,
created_at,
updated_at,
deleted_at,
handle, handle,
credential_id, credential_id,
authenticator_attachment,
origin, origin,
type, type,
transports transports
) VALUES ($1, $2, $3, $4, $5) ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING *; RETURNING *;
-- name: InsertProfile :one -- name: InsertProfile :one
INSERT INTO profiles ( INSERT INTO profiles (
id,
created_at,
updated_at,
deleted_at,
address, address,
handle, handle,
origin, origin,
name name,
) VALUES ($1, $2, $3, $4) status
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING *; RETURNING *;
-- name: GetProfileByID :one -- name: GetProfileByID :one
SELECT * FROM profiles SELECT * FROM profiles
WHERE id = $1 AND deleted_at IS NULL WHERE id = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetProfileByAddress :one -- name: GetProfileByAddress :one
SELECT * FROM profiles SELECT * FROM profiles
WHERE address = $1 AND deleted_at IS NULL WHERE address = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetChallengeBySessionID :one -- name: GetChallengeBySessionID :one
SELECT challenge FROM sessions SELECT challenge FROM sessions
WHERE id = $1 AND deleted_at IS NULL WHERE id = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetHumanVerificationNumbers :one -- name: GetHumanVerificationNumbers :one
SELECT is_human_first, is_human_last FROM sessions SELECT is_human_first, is_human_last FROM sessions
WHERE id = $1 AND deleted_at IS NULL WHERE id = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetSessionByID :one -- name: GetSessionByID :one
SELECT * FROM sessions SELECT * FROM sessions
WHERE id = $1 AND deleted_at IS NULL WHERE id = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetSessionByClientIP :one -- name: GetSessionByClientIP :one
SELECT * FROM sessions SELECT * FROM sessions
WHERE client_ipaddr = $1 AND deleted_at IS NULL WHERE client_ipaddr = ? AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: UpdateSessionHumanVerification :one -- name: UpdateSessionHumanVerification :one
UPDATE sessions UPDATE sessions
SET SET
is_human_first = $1, is_human_first = ?,
is_human_last = $2, is_human_last = ?,
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE id = $3 WHERE id = ?
RETURNING *; RETURNING *;
-- name: UpdateSessionWithProfileID :one -- name: UpdateSessionWithProfileID :one
UPDATE sessions UPDATE sessions
SET SET
profile_id = $1, profile_id = ?,
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE id = $2 WHERE id = ?
RETURNING *; RETURNING *;
-- name: CheckHandleExists :one -- name: CheckHandleExists :one
SELECT COUNT(*) > 0 as handle_exists FROM profiles SELECT COUNT(*) > 0 as handle_exists FROM profiles
WHERE handle = $1 WHERE handle = ?
AND deleted_at IS NULL; AND deleted_at IS NULL;
-- name: GetCredentialsByHandle :many -- name: GetCredentialsByHandle :many
SELECT * FROM credentials SELECT * FROM credentials
WHERE handle = $1 WHERE handle = ?
AND deleted_at IS NULL; AND deleted_at IS NULL;
-- name: GetCredentialByID :one -- name: GetCredentialByID :one
SELECT * FROM credentials SELECT * FROM credentials
WHERE credential_id = $1 WHERE credential_id = ?
AND deleted_at IS NULL AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: SoftDeleteCredential :exec -- name: SoftDeleteCredential :exec
UPDATE credentials UPDATE credentials
SET deleted_at = CURRENT_TIMESTAMP SET deleted_at = CURRENT_TIMESTAMP
WHERE credential_id = $1; WHERE credential_id = ?;
-- name: SoftDeleteProfile :exec -- name: SoftDeleteProfile :exec
UPDATE profiles UPDATE profiles
SET deleted_at = CURRENT_TIMESTAMP SET deleted_at = CURRENT_TIMESTAMP
WHERE address = $1; WHERE id = ?;
-- name: UpdateProfile :one -- name: UpdateProfile :one
UPDATE profiles UPDATE profiles
SET SET
name = $1, name = ?,
handle = $2, handle = ?,
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE address = $3 WHERE id = ?
AND deleted_at IS NULL AND deleted_at IS NULL
RETURNING *; RETURNING *;
-- name: GetProfileByHandle :one -- name: GetProfileByHandle :one
SELECT * FROM profiles SELECT * FROM profiles
WHERE handle = $1 WHERE handle = ?
AND deleted_at IS NULL AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetVaultConfigByCID :one -- name: GetVaultConfigByCID :one
SELECT * FROM vaults SELECT * FROM vaults
WHERE cid = $1 WHERE cid = ?
AND deleted_at IS NULL AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: GetVaultRedirectURIBySessionID :one -- name: GetVaultRedirectURIBySessionID :one
SELECT redirect_uri FROM vaults SELECT redirect_uri FROM vaults
WHERE session_id = $1 WHERE session_id = ?
AND deleted_at IS NULL AND deleted_at IS NULL
LIMIT 1; LIMIT 1;
-- name: CreateSession :one -- name: CreateSession :one
INSERT INTO sessions ( INSERT INTO sessions (
id, id,
created_at,
updated_at,
deleted_at,
browser_name, browser_name,
browser_version, browser_version,
client_ipaddr, client_ipaddr,
@ -135,5 +147,5 @@ INSERT INTO sessions (
is_human_first, is_human_first,
is_human_last, is_human_last,
profile_id profile_id
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING *; RETURNING *;