// Code generated by sqlc. DO NOT EDIT. // source: transactions.sql package postgres import ( "context" "time" "github.com/google/uuid" ) const createTransaction = `-- name: CreateTransaction :one INSERT INTO transactions (date, memo, amount, account_id, payee_id, category_id) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id, date, memo, amount, account_id, category_id, payee_id ` type CreateTransactionParams struct { Date time.Time Memo string Amount Numeric AccountID uuid.UUID PayeeID uuid.NullUUID CategoryID uuid.NullUUID } func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) { row := q.db.QueryRowContext(ctx, createTransaction, arg.Date, arg.Memo, arg.Amount, arg.AccountID, arg.PayeeID, arg.CategoryID, ) var i Transaction err := row.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.AccountID, &i.CategoryID, &i.PayeeID, ) return i, err } const deleteAllTransactions = `-- name: DeleteAllTransactions :execrows DELETE FROM transactions USING accounts WHERE accounts.budget_id = $1 AND accounts.id = transactions.account_id ` func (q *Queries) DeleteAllTransactions(ctx context.Context, budgetID uuid.UUID) (int64, error) { result, err := q.db.ExecContext(ctx, deleteAllTransactions, budgetID) if err != nil { return 0, err } 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 FROM transactions INNER JOIN accounts ON accounts.id = transactions.account_id LEFT JOIN payees ON payees.id = transactions.payee_id LEFT JOIN categories ON categories.id = transactions.category_id LEFT JOIN category_groups ON category_groups.id = categories.category_group_id WHERE transactions.account_id = $1 ORDER BY transactions.date DESC LIMIT 200 ` type GetTransactionsForAccountRow struct { ID uuid.UUID Date time.Time Memo string Amount Numeric Account string Payee string CategoryGroup string Category string } func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) { rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID) if err != nil { return nil, err } defer rows.Close() var items []GetTransactionsForAccountRow for rows.Next() { var i GetTransactionsForAccountRow if err := rows.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.Account, &i.Payee, &i.CategoryGroup, &i.Category, ); 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 getTransactionsForBudget = `-- name: GetTransactionsForBudget :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 FROM transactions INNER JOIN accounts ON accounts.id = transactions.account_id LEFT JOIN payees ON payees.id = transactions.payee_id LEFT JOIN categories ON categories.id = transactions.category_id LEFT JOIN category_groups ON category_groups.id = categories.category_group_id WHERE accounts.budget_id = $1 ORDER BY transactions.date DESC LIMIT 200 ` type GetTransactionsForBudgetRow struct { ID uuid.UUID Date time.Time Memo string Amount Numeric Account string Payee string CategoryGroup string Category string } func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetTransactionsForBudgetRow, error) { rows, err := q.db.QueryContext(ctx, getTransactionsForBudget, budgetID) if err != nil { return nil, err } defer rows.Close() var items []GetTransactionsForBudgetRow for rows.Next() { var i GetTransactionsForBudgetRow if err := rows.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.Account, &i.Payee, &i.CategoryGroup, &i.Category, ); 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 }