332 lines
7.1 KiB
Go
332 lines
7.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: wallet.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
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 (
|
|
is_withdraw,
|
|
is_bettable,
|
|
is_transferable,
|
|
user_id
|
|
)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id, balance, is_withdraw, is_bettable, is_transferable, user_id, is_active, created_at, updated_at
|
|
`
|
|
|
|
type CreateWalletParams struct {
|
|
IsWithdraw bool
|
|
IsBettable bool
|
|
IsTransferable bool
|
|
UserID int64
|
|
}
|
|
|
|
func (q *Queries) CreateWallet(ctx context.Context, arg CreateWalletParams) (Wallet, error) {
|
|
row := q.db.QueryRow(ctx, CreateWallet,
|
|
arg.IsWithdraw,
|
|
arg.IsBettable,
|
|
arg.IsTransferable,
|
|
arg.UserID,
|
|
)
|
|
var i Wallet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Balance,
|
|
&i.IsWithdraw,
|
|
&i.IsBettable,
|
|
&i.IsTransferable,
|
|
&i.UserID,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetAllBranchWallets = `-- name: GetAllBranchWallets :many
|
|
SELECT wallets.id,
|
|
wallets.balance,
|
|
wallets.is_active,
|
|
wallets.updated_at,
|
|
wallets.created_at,
|
|
branches.name,
|
|
branches.location,
|
|
branches.branch_manager_id,
|
|
branches.company_id,
|
|
branches.is_self_owned
|
|
FROM branches
|
|
JOIN wallets ON branches.wallet_id = wallets.id
|
|
`
|
|
|
|
type GetAllBranchWalletsRow struct {
|
|
ID int64
|
|
Balance int64
|
|
IsActive bool
|
|
UpdatedAt pgtype.Timestamp
|
|
CreatedAt pgtype.Timestamp
|
|
Name string
|
|
Location string
|
|
BranchManagerID int64
|
|
CompanyID int64
|
|
IsSelfOwned bool
|
|
}
|
|
|
|
func (q *Queries) GetAllBranchWallets(ctx context.Context) ([]GetAllBranchWalletsRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAllBranchWallets)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllBranchWalletsRow
|
|
for rows.Next() {
|
|
var i GetAllBranchWalletsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Balance,
|
|
&i.IsActive,
|
|
&i.UpdatedAt,
|
|
&i.CreatedAt,
|
|
&i.Name,
|
|
&i.Location,
|
|
&i.BranchManagerID,
|
|
&i.CompanyID,
|
|
&i.IsSelfOwned,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetAllWallets = `-- name: GetAllWallets :many
|
|
SELECT id, balance, is_withdraw, is_bettable, is_transferable, 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.IsTransferable,
|
|
&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,
|
|
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
|
|
`
|
|
|
|
type GetCustomerWalletParams struct {
|
|
CustomerID int64
|
|
CompanyID int64
|
|
}
|
|
|
|
type GetCustomerWalletRow struct {
|
|
ID int64
|
|
CustomerID int64
|
|
CompanyID int64
|
|
RegularID int64
|
|
RegularBalance int64
|
|
StaticID int64
|
|
StaticBalance int64
|
|
RegularUpdatedAt pgtype.Timestamp
|
|
StaticUpdatedAt pgtype.Timestamp
|
|
CreatedAt pgtype.Timestamp
|
|
}
|
|
|
|
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,
|
|
&i.RegularUpdatedAt,
|
|
&i.StaticUpdatedAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetWalletByID = `-- name: GetWalletByID :one
|
|
SELECT id, balance, is_withdraw, is_bettable, is_transferable, 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.IsTransferable,
|
|
&i.UserID,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetWalletByUserID = `-- name: GetWalletByUserID :many
|
|
SELECT id, balance, is_withdraw, is_bettable, is_transferable, user_id, is_active, created_at, updated_at
|
|
FROM wallets
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetWalletByUserID(ctx context.Context, userID int64) ([]Wallet, error) {
|
|
rows, err := q.db.Query(ctx, GetWalletByUserID, userID)
|
|
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.IsTransferable,
|
|
&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 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
|
|
}
|