Merge schemas into one file
This commit is contained in:
@ -13,29 +13,30 @@ import (
|
||||
|
||||
const createTransaction = `-- name: CreateTransaction :one
|
||||
INSERT INTO transactions
|
||||
(budget_id, date, memo, amount)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, budget_id, date, memo, amount, account_id, payee_id
|
||||
(date, memo, amount, account_id, payee_id)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, date, memo, amount, account_id, payee_id
|
||||
`
|
||||
|
||||
type CreateTransactionParams struct {
|
||||
BudgetID uuid.UUID
|
||||
Date time.Time
|
||||
Memo sql.NullString
|
||||
Amount string
|
||||
Date time.Time
|
||||
Memo sql.NullString
|
||||
Amount string
|
||||
AccountID uuid.UUID
|
||||
PayeeID uuid.NullUUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
|
||||
row := q.db.QueryRowContext(ctx, createTransaction,
|
||||
arg.BudgetID,
|
||||
arg.Date,
|
||||
arg.Memo,
|
||||
arg.Amount,
|
||||
arg.AccountID,
|
||||
arg.PayeeID,
|
||||
)
|
||||
var i Transaction
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BudgetID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
@ -45,13 +46,49 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
|
||||
SELECT transactions.id, transactions.budget_id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.payee_id FROM transactions
|
||||
WHERE transactions.budget_id = $1
|
||||
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.payee_id FROM transactions
|
||||
WHERE transactions.account_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]Transaction, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTransactionsForBudget, budgetID)
|
||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]Transaction, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTransactionsForAccount, accountID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Transaction
|
||||
for rows.Next() {
|
||||
var i Transaction
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
&i.AccountID,
|
||||
&i.PayeeID,
|
||||
); 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, transactions.account_id, transactions.payee_id FROM transactions
|
||||
LEFT JOIN accounts ON accounts.id = transactions.account_id
|
||||
WHERE accounts.budget_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]Transaction, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getTransactionsForBudget, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -61,7 +98,6 @@ func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UU
|
||||
var i Transaction
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.BudgetID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
|
Reference in New Issue
Block a user