-- name: CreateTransaction :one
INSERT INTO transactions
(date, memo, amount, account_id, payee_id)
VALUES ($1, $2, $3, $4, $5)
RETURNING *;

-- name: GetTransactionsForBudget :many
SELECT  transactions.id, transactions.date, transactions.memo, transactions.amount,
        accounts.name as account, payees.name as payee
FROM transactions 
INNER JOIN accounts ON accounts.id = transactions.account_id
INNER JOIN payees ON payees.id = transactions.payee_id
WHERE accounts.budget_id = $1
ORDER BY transactions.date DESC
LIMIT 200;

-- name: GetTransactionsForAccount :many
SELECT transactions.* FROM transactions 
WHERE transactions.account_id = $1
ORDER BY transactions.date DESC
LIMIT 200;