Yimaru-BackEnd/gen/db/branch.sql.go
2025-04-07 03:45:52 +03:00

348 lines
8.7 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: branch.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const CreateBranch = `-- name: CreateBranch :one
INSERT INTO branches (name, location, wallet_id, branch_manager_id, company_id, is_self_owned) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
`
type CreateBranchParams struct {
Name string
Location string
WalletID int64
BranchManagerID int64
CompanyID int64
IsSelfOwned bool
}
func (q *Queries) CreateBranch(ctx context.Context, arg CreateBranchParams) (Branch, error) {
row := q.db.QueryRow(ctx, CreateBranch,
arg.Name,
arg.Location,
arg.WalletID,
arg.BranchManagerID,
arg.CompanyID,
arg.IsSelfOwned,
)
var i Branch
err := row.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const CreateBranchOperation = `-- name: CreateBranchOperation :one
INSERT INTO branch_operations (operation_id, branch_id) VALUES ($1, $2) RETURNING id, operation_id, branch_id, created_at, updated_at
`
type CreateBranchOperationParams struct {
OperationID int64
BranchID int64
}
func (q *Queries) CreateBranchOperation(ctx context.Context, arg CreateBranchOperationParams) (BranchOperation, error) {
row := q.db.QueryRow(ctx, CreateBranchOperation, arg.OperationID, arg.BranchID)
var i BranchOperation
err := row.Scan(
&i.ID,
&i.OperationID,
&i.BranchID,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const CreateSupportedOperation = `-- name: CreateSupportedOperation :one
INSERT INTO supported_operations (name, description) VALUES ($1, $2) RETURNING id, name, description
`
type CreateSupportedOperationParams struct {
Name string
Description string
}
func (q *Queries) CreateSupportedOperation(ctx context.Context, arg CreateSupportedOperationParams) (SupportedOperation, error) {
row := q.db.QueryRow(ctx, CreateSupportedOperation, arg.Name, arg.Description)
var i SupportedOperation
err := row.Scan(&i.ID, &i.Name, &i.Description)
return i, err
}
const DeleteBranch = `-- name: DeleteBranch :exec
DELETE FROM branches WHERE id = $1
`
func (q *Queries) DeleteBranch(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, DeleteBranch, id)
return err
}
const DeleteBranchOperation = `-- name: DeleteBranchOperation :exec
DELETE FROM branch_operations WHERE operation_id = $1 AND branch_id = $2
`
type DeleteBranchOperationParams struct {
OperationID int64
BranchID int64
}
func (q *Queries) DeleteBranchOperation(ctx context.Context, arg DeleteBranchOperationParams) error {
_, err := q.db.Exec(ctx, DeleteBranchOperation, arg.OperationID, arg.BranchID)
return err
}
const GetAllBranches = `-- name: GetAllBranches :many
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number FROM branch_details
`
func (q *Queries) GetAllBranches(ctx context.Context) ([]BranchDetail, error) {
rows, err := q.db.Query(ctx, GetAllBranches)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BranchDetail
for rows.Next() {
var i BranchDetail
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
&i.ManagerName,
&i.ManagerPhoneNumber,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetAllSupportedOperations = `-- name: GetAllSupportedOperations :many
SELECT id, name, description FROM supported_operations
`
func (q *Queries) GetAllSupportedOperations(ctx context.Context) ([]SupportedOperation, error) {
rows, err := q.db.Query(ctx, GetAllSupportedOperations)
if err != nil {
return nil, err
}
defer rows.Close()
var items []SupportedOperation
for rows.Next() {
var i SupportedOperation
if err := rows.Scan(&i.ID, &i.Name, &i.Description); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetBranchByCompanyID = `-- name: GetBranchByCompanyID :many
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number FROM branch_details WHERE company_id = $1
`
func (q *Queries) GetBranchByCompanyID(ctx context.Context, companyID int64) ([]BranchDetail, error) {
rows, err := q.db.Query(ctx, GetBranchByCompanyID, companyID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BranchDetail
for rows.Next() {
var i BranchDetail
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
&i.ManagerName,
&i.ManagerPhoneNumber,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetBranchByID = `-- name: GetBranchByID :one
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number FROM branch_details WHERE id = $1
`
func (q *Queries) GetBranchByID(ctx context.Context, id int64) (BranchDetail, error) {
row := q.db.QueryRow(ctx, GetBranchByID, id)
var i BranchDetail
err := row.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
&i.ManagerName,
&i.ManagerPhoneNumber,
)
return i, err
}
const GetBranchByManagerID = `-- name: GetBranchByManagerID :many
SELECT id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at, manager_name, manager_phone_number FROM branch_details WHERE branch_manager_id = $1
`
func (q *Queries) GetBranchByManagerID(ctx context.Context, branchManagerID int64) ([]BranchDetail, error) {
rows, err := q.db.Query(ctx, GetBranchByManagerID, branchManagerID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BranchDetail
for rows.Next() {
var i BranchDetail
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
&i.ManagerName,
&i.ManagerPhoneNumber,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetBranchOperations = `-- name: GetBranchOperations :many
SELECT branch_operations.id, branch_operations.operation_id, branch_operations.branch_id, branch_operations.created_at, branch_operations.updated_at, supported_operations.name, supported_operations.description
FROM branch_operations
JOIN supported_operations ON branch_operations.operation_id = supported_operations.id
WHERE branch_operations.branch_id = $1
`
type GetBranchOperationsRow struct {
ID int64
OperationID int64
BranchID int64
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
Name string
Description string
}
func (q *Queries) GetBranchOperations(ctx context.Context, branchID int64) ([]GetBranchOperationsRow, error) {
rows, err := q.db.Query(ctx, GetBranchOperations, branchID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetBranchOperationsRow
for rows.Next() {
var i GetBranchOperationsRow
if err := rows.Scan(
&i.ID,
&i.OperationID,
&i.BranchID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Name,
&i.Description,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const UpdateBranch = `-- name: UpdateBranch :one
UPDATE branches SET name = $1, location = $2, branch_manager_id = $3, company_id = $4, is_self_owned = $5 WHERE id = $6 RETURNING id, name, location, wallet_id, branch_manager_id, company_id, is_self_owned, created_at, updated_at
`
type UpdateBranchParams struct {
Name string
Location string
BranchManagerID int64
CompanyID int64
IsSelfOwned bool
ID int64
}
func (q *Queries) UpdateBranch(ctx context.Context, arg UpdateBranchParams) (Branch, error) {
row := q.db.QueryRow(ctx, UpdateBranch,
arg.Name,
arg.Location,
arg.BranchManagerID,
arg.CompanyID,
arg.IsSelfOwned,
arg.ID,
)
var i Branch
err := row.Scan(
&i.ID,
&i.Name,
&i.Location,
&i.WalletID,
&i.BranchManagerID,
&i.CompanyID,
&i.IsSelfOwned,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}