60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.13.0
|
|
// source: cumultative-balances.sql
|
|
|
|
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const getCumultativeBalances = `-- name: GetCumultativeBalances :many
|
|
SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
|
|
COALESCE(ass.amount, 0)::decimal(12,2) as assignments,
|
|
COALESCE(tra.amount, 0)::decimal(12,2) as transactions
|
|
FROM assignments_by_month as ass
|
|
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
|
|
WHERE COALESCE(ass.budget_id, tra.budget_id) = $1
|
|
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount)
|
|
`
|
|
|
|
type GetCumultativeBalancesRow struct {
|
|
Date time.Time
|
|
CategoryID uuid.UUID
|
|
Assignments numeric.Numeric
|
|
Transactions numeric.Numeric
|
|
}
|
|
|
|
func (q *Queries) GetCumultativeBalances(ctx context.Context, budgetID uuid.UUID) ([]GetCumultativeBalancesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getCumultativeBalances, budgetID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetCumultativeBalancesRow
|
|
for rows.Next() {
|
|
var i GetCumultativeBalancesRow
|
|
if err := rows.Scan(
|
|
&i.Date,
|
|
&i.CategoryID,
|
|
&i.Assignments,
|
|
&i.Transactions,
|
|
); 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
|
|
}
|