Yimaru-BackEnd/gen/db/wallet.sql.go

200 lines
4.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: wallet.sql
package dbgen
import (
"context"
)
const CreateCustomerWallet = `-- name: CreateCustomerWallet :one
INSERT INTO customer_wallets (customer_id, company_id, regular_wallet_id, static_wallet_id) VALUES ($1, $2, $3, $4) RETURNING id, customer_id, company_id, regular_wallet_id, static_wallet_id, created_at, updated_at
`
type CreateCustomerWalletParams struct {
CustomerID int64
CompanyID int64
RegularWalletID int64
StaticWalletID int64
}
func (q *Queries) CreateCustomerWallet(ctx context.Context, arg CreateCustomerWalletParams) (CustomerWallet, error) {
row := q.db.QueryRow(ctx, CreateCustomerWallet,
arg.CustomerID,
arg.CompanyID,
arg.RegularWalletID,
arg.StaticWalletID,
)
var i CustomerWallet
err := row.Scan(
&i.ID,
&i.CustomerID,
&i.CompanyID,
&i.RegularWalletID,
&i.StaticWalletID,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const CreateWallet = `-- name: CreateWallet :one
INSERT INTO wallets (balance, is_withdraw, is_bettable, user_id) VALUES ($1, $2, $3, $4) RETURNING id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at
`
type CreateWalletParams struct {
Balance int64
IsWithdraw bool
IsBettable bool
UserID int64
}
func (q *Queries) CreateWallet(ctx context.Context, arg CreateWalletParams) (Wallet, error) {
row := q.db.QueryRow(ctx, CreateWallet,
arg.Balance,
arg.IsWithdraw,
arg.IsBettable,
arg.UserID,
)
var i Wallet
err := row.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetAllWallets = `-- name: GetAllWallets :many
SELECT id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at FROM wallets
`
func (q *Queries) GetAllWallets(ctx context.Context) ([]Wallet, error) {
rows, err := q.db.Query(ctx, GetAllWallets)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Wallet
for rows.Next() {
var i Wallet
if err := rows.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetCustomerWallet = `-- 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
`
type GetCustomerWalletParams struct {
CustomerID int64
CompanyID int64
}
type GetCustomerWalletRow struct {
ID int64
CustomerID int64
CompanyID int64
RegularID int64
RegularBalance int64
StaticID int64
StaticBalance int64
}
func (q *Queries) GetCustomerWallet(ctx context.Context, arg GetCustomerWalletParams) (GetCustomerWalletRow, error) {
row := q.db.QueryRow(ctx, GetCustomerWallet, arg.CustomerID, arg.CompanyID)
var i GetCustomerWalletRow
err := row.Scan(
&i.ID,
&i.CustomerID,
&i.CompanyID,
&i.RegularID,
&i.RegularBalance,
&i.StaticID,
&i.StaticBalance,
)
return i, err
}
const GetWalletByID = `-- name: GetWalletByID :one
SELECT id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at FROM wallets WHERE id = $1
`
func (q *Queries) GetWalletByID(ctx context.Context, id int64) (Wallet, error) {
row := q.db.QueryRow(ctx, GetWalletByID, id)
var i Wallet
err := row.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const UpdateBalance = `-- name: UpdateBalance :exec
UPDATE wallets SET balance = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateBalanceParams struct {
Balance int64
ID int64
}
func (q *Queries) UpdateBalance(ctx context.Context, arg UpdateBalanceParams) error {
_, err := q.db.Exec(ctx, UpdateBalance, arg.Balance, arg.ID)
return err
}
const UpdateWalletActive = `-- name: UpdateWalletActive :exec
UPDATE wallets SET is_active = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateWalletActiveParams struct {
IsActive bool
ID int64
}
func (q *Queries) UpdateWalletActive(ctx context.Context, arg UpdateWalletActiveParams) error {
_, err := q.db.Exec(ctx, UpdateWalletActive, arg.IsActive, arg.ID)
return err
}