-- name: CreateWallet :one INSERT INTO wallets (balance, is_withdraw, is_bettable, user_id) VALUES ($1, $2, $3, $4) RETURNING *; -- name: CreateCustomerWallet :one INSERT INTO customer_wallets (customer_id, company_id, regular_wallet_id, static_wallet_id) VALUES ($1, $2, $3, $4) RETURNING *; -- name: GetAllWallets :many SELECT * FROM wallets; -- name: GetWalletByID :one SELECT * FROM wallets WHERE id = $1; -- name: GetCustomerWallet :one SELECT cw.id, cw.customer_id, cw.company_id, rw.id AS regular_id, rw.balance AS regular_balance, sw.id AS static_id, sw.balance AS static_balance FROM customer_wallets cw JOIN wallets rw ON cw.regular_wallet_id = rw.id JOIN wallets sw ON cw.static_wallet_id = sw.id WHERE cw.customer_id = $1 AND cw.company_id = $2; -- name: UpdateBalance :exec UPDATE wallets SET balance = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2; -- name: UpdateWalletActive :exec UPDATE wallets SET is_active = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2;