-- name: UpdateExpiredOtp :exec UPDATE otps SET otp = $2, used = FALSE, used_at = NULL, expires_at = $3 WHERE user_name = $1 AND expires_at <= NOW(); -- name: CreateOtp :exec INSERT INTO otps (user_name, sent_to, medium, otp_for, otp, used, created_at, expires_at) VALUES ($1, $2, $3, $4, $5, FALSE, $6, $7); -- name: GetOtp :one SELECT id, user_name, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at FROM otps WHERE user_name = $1 ORDER BY created_at DESC LIMIT 1; -- name: MarkOtpAsUsed :exec UPDATE otps SET used = TRUE, used_at = $2 WHERE id = $1;