115 lines
2.6 KiB
Go
115 lines
2.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// source: transactions.sql
|
|
|
|
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgtype"
|
|
)
|
|
|
|
const createTransaction = `-- name: CreateTransaction :one
|
|
INSERT INTO transactions
|
|
(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 {
|
|
Date time.Time
|
|
Memo string
|
|
Amount pgtype.Numeric
|
|
AccountID uuid.UUID
|
|
PayeeID uuid.NullUUID
|
|
}
|
|
|
|
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
|
|
row := q.db.QueryRow(ctx, createTransaction,
|
|
arg.Date,
|
|
arg.Memo,
|
|
arg.Amount,
|
|
arg.AccountID,
|
|
arg.PayeeID,
|
|
)
|
|
var i Transaction
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Date,
|
|
&i.Memo,
|
|
&i.Amount,
|
|
&i.AccountID,
|
|
&i.PayeeID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
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
|
|
ORDER BY transactions.date DESC
|
|
`
|
|
|
|
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]Transaction, error) {
|
|
rows, err := q.db.Query(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.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
|
|
ORDER BY transactions.date DESC
|
|
`
|
|
|
|
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]Transaction, error) {
|
|
rows, err := q.db.Query(ctx, getTransactionsForBudget, budgetID)
|
|
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.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|