Add views with results grouped by month
This commit is contained in:
@ -63,6 +63,41 @@ func (q *Queries) DeleteAllTransactions(ctx context.Context, budgetID uuid.UUID)
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const getTransactionsByMonthAndCategory = `-- name: GetTransactionsByMonthAndCategory :many
|
||||
SELECT year, month, category_id, budget_id, amount
|
||||
FROM transactions_by_month
|
||||
WHERE transactions_by_month.budget_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTransactionsByMonthAndCategory(ctx context.Context, budgetID uuid.UUID) ([]TransactionsByMonth, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTransactionsByMonthAndCategory, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []TransactionsByMonth
|
||||
for rows.Next() {
|
||||
var i TransactionsByMonth
|
||||
if err := rows.Scan(
|
||||
&i.Year,
|
||||
&i.Month,
|
||||
&i.CategoryID,
|
||||
&i.BudgetID,
|
||||
&i.Amount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
|
||||
accounts.name as account, COALESCE(payees.name, '') as payee, COALESCE(category_groups.name, '') as category_group, COALESCE(categories.name, '') as category
|
||||
|
Reference in New Issue
Block a user