// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.13.0 // source: transactions.sql package postgres import ( "context" "database/sql" "time" "git.javil.eu/jacob1123/budgeteer/postgres/numeric" "github.com/google/uuid" ) const createTransaction = `-- 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 ` type CreateTransactionParams struct { Date time.Time Memo string Amount numeric.Numeric AccountID uuid.UUID PayeeID uuid.NullUUID CategoryID uuid.NullUUID GroupID uuid.NullUUID Status TransactionStatus } func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (uuid.UUID, error) { row := q.db.QueryRowContext(ctx, createTransaction, arg.Date, arg.Memo, arg.Amount, arg.AccountID, arg.PayeeID, arg.CategoryID, arg.GroupID, arg.Status, ) var id uuid.UUID err := row.Scan(&id) return id, 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 deleteTransaction = `-- name: DeleteTransaction :exec DELETE FROM transactions WHERE id = $1 ` func (q *Queries) DeleteTransaction(ctx context.Context, id uuid.UUID) error { _, err := q.db.ExecContext(ctx, deleteTransaction, id) return err } const getAllTransactionsForBudget = `-- name: GetAllTransactionsForBudget :many SELECT t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id FROM display_transactions AS t WHERE t.budget_id = $1 ` func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]DisplayTransaction, error) { rows, err := q.db.QueryContext(ctx, getAllTransactionsForBudget, budgetID) if err != nil { return nil, err } defer rows.Close() var items []DisplayTransaction for rows.Next() { var i DisplayTransaction if err := rows.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.GroupID, &i.Status, &i.Account, &i.PayeeID, &i.CategoryID, &i.Payee, &i.CategoryGroup, &i.Category, &i.TransferAccount, &i.BudgetID, &i.AccountID, ); 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 getProblematicTransactions = `-- name: GetProblematicTransactions :many SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.category_id, transactions.payee_id, transactions.group_id, transactions.status, accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled, othergrouptransaction.id, othergrouptransaction.date, othergrouptransaction.memo, othergrouptransaction.amount, othergrouptransaction.account_id, othergrouptransaction.category_id, othergrouptransaction.payee_id, othergrouptransaction.group_id, othergrouptransaction.status, othergroupaccount.id, othergroupaccount.budget_id, othergroupaccount.name, othergroupaccount.on_budget, othergroupaccount.is_open, othergroupaccount.last_reconciled FROM transactions LEFT JOIN accounts ON transactions.account_id = accounts.id LEFT JOIN transactions AS otherGroupTransaction ON transactions.group_id = otherGroupTransaction.group_id AND transactions.id != otherGroupTransaction.id AND transactions.account_id != otherGroupTransaction.account_id LEFT JOIn accounts AS otherGroupAccount ON otherGroupTransaction.account_id = accounts.id WHERE transactions.category_id IS NULL AND accounts.on_budget AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget) AND accounts.budget_id = $1 ` type GetProblematicTransactionsRow struct { ID uuid.UUID Date time.Time Memo string Amount numeric.Numeric AccountID uuid.UUID CategoryID uuid.NullUUID PayeeID uuid.NullUUID GroupID uuid.NullUUID Status TransactionStatus ID_2 uuid.NullUUID BudgetID uuid.NullUUID Name sql.NullString OnBudget sql.NullBool IsOpen sql.NullBool LastReconciled sql.NullTime ID_3 uuid.UUID Date_2 time.Time Memo_2 string Amount_2 numeric.Numeric AccountID_2 uuid.UUID CategoryID_2 uuid.NullUUID PayeeID_2 uuid.NullUUID GroupID_2 uuid.NullUUID Status_2 TransactionStatus ID_4 uuid.NullUUID BudgetID_2 uuid.NullUUID Name_2 sql.NullString OnBudget_2 sql.NullBool IsOpen_2 sql.NullBool LastReconciled_2 sql.NullTime } func (q *Queries) GetProblematicTransactions(ctx context.Context, budgetID uuid.UUID) ([]GetProblematicTransactionsRow, error) { rows, err := q.db.QueryContext(ctx, getProblematicTransactions, budgetID) if err != nil { return nil, err } defer rows.Close() var items []GetProblematicTransactionsRow for rows.Next() { var i GetProblematicTransactionsRow if err := rows.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.AccountID, &i.CategoryID, &i.PayeeID, &i.GroupID, &i.Status, &i.ID_2, &i.BudgetID, &i.Name, &i.OnBudget, &i.IsOpen, &i.LastReconciled, &i.ID_3, &i.Date_2, &i.Memo_2, &i.Amount_2, &i.AccountID_2, &i.CategoryID_2, &i.PayeeID_2, &i.GroupID_2, &i.Status_2, &i.ID_4, &i.BudgetID_2, &i.Name_2, &i.OnBudget_2, &i.IsOpen_2, &i.LastReconciled_2, ); 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 getTransaction = `-- name: GetTransaction :one SELECT id, date, memo, amount, group_id, status, account, payee_id, category_id, payee, category_group, category, transfer_account, budget_id, account_id FROM display_transactions WHERE id = $1 ` func (q *Queries) GetTransaction(ctx context.Context, id uuid.UUID) (DisplayTransaction, error) { row := q.db.QueryRowContext(ctx, getTransaction, id) var i DisplayTransaction err := row.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.GroupID, &i.Status, &i.Account, &i.PayeeID, &i.CategoryID, &i.Payee, &i.CategoryGroup, &i.Category, &i.TransferAccount, &i.BudgetID, &i.AccountID, ) return i, err } const getTransactionsByMonthAndCategory = `-- name: GetTransactionsByMonthAndCategory :many SELECT date, 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.Date, &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 t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id FROM display_transactions AS t WHERE t.account_id = $1 ` func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]DisplayTransaction, error) { rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID) if err != nil { return nil, err } defer rows.Close() var items []DisplayTransaction for rows.Next() { var i DisplayTransaction if err := rows.Scan( &i.ID, &i.Date, &i.Memo, &i.Amount, &i.GroupID, &i.Status, &i.Account, &i.PayeeID, &i.CategoryID, &i.Payee, &i.CategoryGroup, &i.Category, &i.TransferAccount, &i.BudgetID, &i.AccountID, ); 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 setTransactionReconciled = `-- name: SetTransactionReconciled :exec UPDATE transactions SET status = 'Reconciled' WHERE id = $1 ` func (q *Queries) SetTransactionReconciled(ctx context.Context, id uuid.UUID) error { _, err := q.db.ExecContext(ctx, setTransactionReconciled, id) return err } const updateTransaction = `-- name: UpdateTransaction :exec UPDATE transactions SET date = $1, memo = $2, amount = $3, payee_id = $4, category_id = $5 WHERE id = $6 ` type UpdateTransactionParams struct { Date time.Time Memo string Amount numeric.Numeric PayeeID uuid.NullUUID CategoryID uuid.NullUUID ID uuid.UUID } func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionParams) error { _, err := q.db.ExecContext(ctx, updateTransaction, arg.Date, arg.Memo, arg.Amount, arg.PayeeID, arg.CategoryID, arg.ID, ) return err }