43 lines
1.5 KiB
SQL
43 lines
1.5 KiB
SQL
|
|
-- 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 *;
|
|
|
|
-- name: CreateSupportedOperation :one
|
|
INSERT INTO supported_operations (name, description) VALUES ($1, $2) RETURNING *;
|
|
|
|
-- name: CreateBranchOperation :one
|
|
INSERT INTO branch_operations (operation_id, branch_id) VALUES ($1, $2) RETURNING *;
|
|
|
|
-- name: GetAllBranches :many
|
|
SELECT * FROM branch_details;
|
|
|
|
-- name: GetBranchByID :one
|
|
SELECT * FROM branch_details WHERE id = $1;
|
|
|
|
-- name: GetBranchByCompanyID :many
|
|
SELECT * FROM branch_details WHERE company_id = $1;
|
|
|
|
-- name: GetBranchByManagerID :many
|
|
SELECT * FROM branch_details WHERE branch_manager_id = $1;
|
|
|
|
-- name: SearchBranchByName :many
|
|
SELECT * FROM branch_details WHERE name ILIKE '%' || $1 || '%';
|
|
|
|
-- name: GetAllSupportedOperations :many
|
|
SELECT * FROM supported_operations;
|
|
|
|
-- name: GetBranchOperations :many
|
|
SELECT branch_operations.*, 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;
|
|
|
|
-- 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 *;
|
|
|
|
-- name: DeleteBranch :exec
|
|
DELETE FROM branches WHERE id = $1;
|
|
|
|
-- name: DeleteBranchOperation :exec
|
|
DELETE FROM branch_operations WHERE operation_id = $1 AND branch_id = $2;
|