Files
motr/internal/db/users/query.sql

235 lines
4.5 KiB
MySQL
Raw Permalink Normal View History

feat/ui (#11) * ui: improve visual consistency across components * feat: simplify task execution with consolidated commands * feat: enable account registration flow * feat: integrate price tracking functionality * feat: add metadata components for improved SEO and web crawling * refactor: improve code organization and consistency * fix: update login template package names * refactor: rename and restructure UI components for clarity * feat: introduce dynamic asset selection for transfer UI * chore: update dependencies and build process * feat: Add KVNamespace interface for Cloudflare KV store operations * refactor: Update JSON operations to use Golang generics with JSON Marshaller interface * feat: Add json import for KVNamespace generic JSON operations * refactor: Update PutJSON method to accept any type for JSON marshaling * refactor: migrate to modular architecture with domain-driven design * fix: directory structure for component routing * refactor: partial routes to htmx * docs: update documentation to reflect UI structure changes * refactor: relocate build artifacts for cleaner project structure * feat: integrate Cloudflare cache for improved performance * build: update import paths for middleware package * feat: implement core authentication flows * refactor: rename view handler to index handler for clarity * feat: introduce devbox for streamlined development environment * feat: introduce deployment and build scripts * feat: introduce radar and worker services with build automation * feat: introduce WASM-based worker and radar services * feat: migrate to standard go build process * fix: correct worker script path in wrangler configuration * feat: enhance service monitoring capabilities * refactor: migrate to new database and KV store context pattern * build: streamline worker builds using devbox scripts * feat: migrate to D1 database bindings for improved data access * feat: introduce session ID middleware * perf: optimize WASM build size by stripping debug information * feat: introduce process-compose for simplified local development * feat: enable direct wrangler commands and simplify deployment
2025-05-28 12:50:38 -04:00
-- PROFILE QUERIES
-- name: InsertProfile :one
INSERT INTO profiles (
address,
handle,
origin,
name
) VALUES (?, ?, ?, ?)
RETURNING *;
-- name: GetProfileByID :one
SELECT * FROM profiles
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetProfileByAddress :one
SELECT * FROM profiles
WHERE address = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetProfileByHandle :one
SELECT * FROM profiles
WHERE handle = ?
AND deleted_at IS NULL
LIMIT 1;
-- name: CheckHandleExists :one
SELECT COUNT(*) > 0 as handle_exists FROM profiles
WHERE handle = ?
AND deleted_at IS NULL;
-- name: UpdateProfile :one
UPDATE profiles
SET
name = ?,
handle = ?,
updated_at = CURRENT_TIMESTAMP
WHERE address = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeleteProfile :exec
UPDATE profiles
SET deleted_at = CURRENT_TIMESTAMP
WHERE address = ?;
-- name: ListProfiles :many
SELECT * FROM profiles
WHERE deleted_at IS NULL
ORDER BY created_at DESC
LIMIT ? OFFSET ?;
-- VAULT QUERIES
-- name: InsertVault :one
INSERT INTO vaults (
handle,
origin,
address,
cid,
config,
session_id,
redirect_uri
) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetVaultByID :one
SELECT * FROM vaults
WHERE id = ?
AND deleted_at IS NULL
LIMIT 1;
-- name: GetVaultsByHandle :many
SELECT * FROM vaults
WHERE handle = ?
AND deleted_at IS NULL
ORDER BY created_at DESC;
-- name: GetVaultConfigByCID :one
SELECT * FROM vaults
WHERE cid = ?
AND deleted_at IS NULL
LIMIT 1;
-- name: GetVaultRedirectURIBySessionID :one
SELECT redirect_uri FROM vaults
WHERE session_id = ?
AND deleted_at IS NULL
LIMIT 1;
-- name: UpdateVault :one
UPDATE vaults
SET
config = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeleteVault :exec
UPDATE vaults
SET deleted_at = CURRENT_TIMESTAMP
WHERE id = ?;
-- ACCOUNT QUERIES
-- name: InsertAccount :one
INSERT INTO accounts (
number,
sequence,
address,
public_key,
chain_id,
block_created,
controller,
label,
is_subsidiary,
is_validator,
is_delegator,
is_accountable
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetAccountByID :one
SELECT * FROM accounts
WHERE id = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountByAddress :one
SELECT * FROM accounts
WHERE address = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountsByHandle :many
SELECT * FROM accounts
WHERE handle = ? AND deleted_at IS NULL
ORDER BY created_at DESC;
-- name: GetAccountByController :one
SELECT * FROM accounts
WHERE controller = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountByPublicKey :one
SELECT * FROM accounts
WHERE public_key = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountByNumber :one
SELECT * FROM accounts
WHERE number = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountBySequence :one
SELECT * FROM accounts
WHERE sequence = ? AND deleted_at IS NULL
LIMIT 1;
-- name: GetAccountsByChainID :many
SELECT * FROM accounts
WHERE chain_id = ? AND deleted_at IS NULL
ORDER BY sequence DESC;
-- name: GetAccountsByController :many
SELECT * FROM accounts
WHERE controller = ? AND deleted_at IS NULL
ORDER BY created_at DESC;
-- name: GetAccountsByLabel :many
SELECT * FROM accounts
WHERE label = ? AND deleted_at IS NULL
ORDER BY created_at DESC;
-- name: UpdateAccountSequence :one
UPDATE accounts
SET
sequence = ?,
updated_at = CURRENT_TIMESTAMP
WHERE address = ?
AND deleted_at IS NULL
RETURNING *;
-- name: UpdateAccountLabel :one
UPDATE accounts
SET
label = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
AND deleted_at IS NULL
RETURNING *;
-- name: SoftDeleteAccount :exec
UPDATE accounts
SET deleted_at = CURRENT_TIMESTAMP
WHERE id = ?;
-- name: ListValidatorAccounts :many
SELECT * FROM accounts
WHERE is_validator = 1
AND deleted_at IS NULL
ORDER BY created_at DESC;
-- name: ListDelegatorAccounts :many
SELECT * FROM accounts
WHERE is_delegator = 1
AND deleted_at IS NULL
ORDER BY created_at DESC;
-- CREDENTIAL QUERIES
-- name: InsertCredential :one
INSERT INTO credentials (
handle,
credential_id,
authenticator_attachment,
origin,
type,
transports
) VALUES (?, ?, ?, ?, ?, ?)
RETURNING *;
-- name: GetCredentialsByHandle :many
SELECT * FROM credentials
WHERE handle = ?
AND deleted_at IS NULL;
-- name: GetCredentialByID :one
SELECT * FROM credentials
WHERE credential_id = ?
AND deleted_at IS NULL
LIMIT 1;
-- name: SoftDeleteCredential :exec
UPDATE credentials
SET deleted_at = CURRENT_TIMESTAMP
WHERE credential_id = ?;