budgeteer/postgres/queries/transactions.sql
Jan Bader 4c6d21c2b4
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Improve editing and creating of transactions
2022-02-27 21:15:46 +00:00

49 lines
1.1 KiB
SQL

-- name: GetTransaction :one
SELECT * FROM display_transactions
WHERE id = $1;
-- name: CreateTransaction :one
INSERT INTO transactions
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id;
-- name: UpdateTransaction :exec
UPDATE transactions
SET date = $1,
memo = $2,
amount = $3,
payee_id = $4,
category_id = $5
WHERE id = $6;
-- name: SetTransactionReconciled :exec
UPDATE transactions
SET status = 'Reconciled'
WHERE id = $1;
-- name: DeleteTransaction :exec
DELETE FROM transactions
WHERE id = $1;
-- name: GetAllTransactionsForBudget :many
SELECT t.*
FROM display_transactions AS t
WHERE t.budget_id = $1;
-- name: GetTransactionsForAccount :many
SELECT t.*
FROM display_transactions AS t
WHERE t.account_id = $1
LIMIT 200;
-- name: DeleteAllTransactions :execrows
DELETE FROM transactions
USING accounts
WHERE accounts.budget_id = @budget_id
AND accounts.id = transactions.account_id;
-- name: GetTransactionsByMonthAndCategory :many
SELECT *
FROM transactions_by_month
WHERE transactions_by_month.budget_id = @budget_id;