162 lines
4.1 KiB
Go
162 lines
4.1 KiB
Go
// 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 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
|
|
}
|