From 26a322a5eae8f019d9f8c70feac9f1166d4c0c0d Mon Sep 17 00:00:00 2001 From: "Prad Nukala (aider)" Date: Sun, 29 Dec 2024 01:22:19 -0500 Subject: [PATCH] fix: update sqlc queries to match schema and use SQLite conventions --- internal/database/sink/highway/query.sql | 74 ++++++++++++++---------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/internal/database/sink/highway/query.sql b/internal/database/sink/highway/query.sql index 0de000fdb..8130158d7 100644 --- a/internal/database/sink/highway/query.sql +++ b/internal/database/sink/highway/query.sql @@ -1,127 +1,139 @@ --- AI! Update the sqlc queries to match the schema and follow sqlite conventions -- name: InsertCredential :one INSERT INTO credentials ( + id, + created_at, + updated_at, + deleted_at, handle, credential_id, + authenticator_attachment, origin, type, transports -) VALUES ($1, $2, $3, $4, $5) +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *; -- name: InsertProfile :one INSERT INTO profiles ( + id, + created_at, + updated_at, + deleted_at, address, handle, origin, - name -) VALUES ($1, $2, $3, $4) + name, + status +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *; -- name: GetProfileByID :one SELECT * FROM profiles -WHERE id = $1 AND deleted_at IS NULL +WHERE id = ? AND deleted_at IS NULL LIMIT 1; -- name: GetProfileByAddress :one SELECT * FROM profiles -WHERE address = $1 AND deleted_at IS NULL +WHERE address = ? AND deleted_at IS NULL LIMIT 1; -- name: GetChallengeBySessionID :one SELECT challenge FROM sessions -WHERE id = $1 AND deleted_at IS NULL +WHERE id = ? AND deleted_at IS NULL LIMIT 1; -- name: GetHumanVerificationNumbers :one 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; -- name: GetSessionByID :one SELECT * FROM sessions -WHERE id = $1 AND deleted_at IS NULL +WHERE id = ? AND deleted_at IS NULL LIMIT 1; -- name: GetSessionByClientIP :one SELECT * FROM sessions -WHERE client_ipaddr = $1 AND deleted_at IS NULL +WHERE client_ipaddr = ? AND deleted_at IS NULL LIMIT 1; -- name: UpdateSessionHumanVerification :one UPDATE sessions -SET - is_human_first = $1, - is_human_last = $2, +SET + is_human_first = ?, + is_human_last = ?, updated_at = CURRENT_TIMESTAMP -WHERE id = $3 +WHERE id = ? RETURNING *; -- name: UpdateSessionWithProfileID :one UPDATE sessions -SET - profile_id = $1, +SET + profile_id = ?, updated_at = CURRENT_TIMESTAMP -WHERE id = $2 +WHERE id = ? RETURNING *; -- name: CheckHandleExists :one -SELECT COUNT(*) > 0 as handle_exists FROM profiles -WHERE handle = $1 +SELECT COUNT(*) > 0 as handle_exists FROM profiles +WHERE handle = ? AND deleted_at IS NULL; -- name: GetCredentialsByHandle :many SELECT * FROM credentials -WHERE handle = $1 +WHERE handle = ? AND deleted_at IS NULL; -- name: GetCredentialByID :one SELECT * FROM credentials -WHERE credential_id = $1 +WHERE credential_id = ? AND deleted_at IS NULL LIMIT 1; -- name: SoftDeleteCredential :exec UPDATE credentials SET deleted_at = CURRENT_TIMESTAMP -WHERE credential_id = $1; +WHERE credential_id = ?; -- name: SoftDeleteProfile :exec UPDATE profiles SET deleted_at = CURRENT_TIMESTAMP -WHERE address = $1; +WHERE id = ?; -- name: UpdateProfile :one UPDATE profiles -SET - name = $1, - handle = $2, +SET + name = ?, + handle = ?, updated_at = CURRENT_TIMESTAMP -WHERE address = $3 +WHERE id = ? AND deleted_at IS NULL RETURNING *; -- name: GetProfileByHandle :one SELECT * FROM profiles -WHERE handle = $1 +WHERE handle = ? AND deleted_at IS NULL LIMIT 1; -- name: GetVaultConfigByCID :one SELECT * FROM vaults -WHERE cid = $1 +WHERE cid = ? AND deleted_at IS NULL LIMIT 1; -- name: GetVaultRedirectURIBySessionID :one SELECT redirect_uri FROM vaults -WHERE session_id = $1 +WHERE session_id = ? AND deleted_at IS NULL LIMIT 1; -- name: CreateSession :one INSERT INTO sessions ( id, + created_at, + updated_at, + deleted_at, browser_name, browser_version, client_ipaddr, @@ -135,5 +147,5 @@ INSERT INTO sessions ( is_human_first, is_human_last, profile_id -) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *;