-- name: CreateBudget :one INSERT INTO budgets (project_id, name, budget_type, category, start_at, end_at, amount, used_amount, remaining_amount, remark, created_user_id) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *; -- name: GetBudget :one SELECT * FROM budgets WHERE id = $1 LIMIT 1; -- name: UpdateBudget :one UPDATE budgets SET project_id = COALESCE(sqlc.narg(project_id), project_id), name = COALESCE(sqlc.narg(name), name), budget_type = COALESCE(sqlc.narg(budget_type), budget_type), category = COALESCE(sqlc.narg(category), category), start_at = COALESCE(sqlc.narg(start_at), start_at), end_at = COALESCE(sqlc.narg(end_at), end_at), amount = COALESCE(sqlc.narg(amount), amount), used_amount = COALESCE(sqlc.narg(used_amount), used_amount), remaining_amount = COALESCE(sqlc.narg(remaining_amount), remaining_amount), remark = COALESCE(sqlc.narg(remark), remark), status = COALESCE(sqlc.narg(status), status), updated_user_id = COALESCE(sqlc.narg(updated_user_id), updated_user_id), updated_at = NOW() WHERE id = $1 RETURNING *; -- name: ListBudgets :many SELECT * FROM budgets WHERE project_id = $1 ORDER BY id;