41 lines
1.2 KiB
SQL
41 lines
1.2 KiB
SQL
-- name: CreateWallet :one
|
|
INSERT INTO wallets (is_withdraw, is_bettable, is_transferable, 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: GetWalletByUserID :many
|
|
SELECT * FROM wallets WHERE user_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,
|
|
rw.updated_at as regular_updated_at,
|
|
sw.updated_at as static_updated_at,
|
|
cw.created_at
|
|
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;
|
|
|
|
|
|
|