Implement single account transaction-list
This commit is contained in:
@ -28,6 +28,18 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccount = `-- name: GetAccount :one
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name FROM accounts
|
||||
WHERE accounts.id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccount(ctx context.Context, id uuid.UUID) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAccount, id)
|
||||
var i Account
|
||||
err := row.Scan(&i.ID, &i.BudgetID, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccounts = `-- name: GetAccounts :many
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name FROM accounts
|
||||
WHERE accounts.budget_id = $1
|
||||
|
@ -27,45 +27,3 @@ func Connect(server string, user string, password string, database string) (*Que
|
||||
|
||||
return New(conn), conn, nil
|
||||
}
|
||||
|
||||
func (tx Transaction) GetAmount() float64 {
|
||||
var amount float64
|
||||
err := tx.Amount.AssignTo(&amount)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
func (tx Transaction) GetPositive() bool {
|
||||
amount := tx.GetAmount()
|
||||
return amount >= 0
|
||||
}
|
||||
|
||||
func (tx GetTransactionsForBudgetRow) GetAmount() float64 {
|
||||
var amount float64
|
||||
err := tx.Amount.AssignTo(&amount)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
func (tx GetTransactionsForBudgetRow) GetPositive() bool {
|
||||
amount := tx.GetAmount()
|
||||
return amount >= 0
|
||||
}
|
||||
|
||||
func (tx GetAccountsWithBalanceRow) GetBalance() float64 {
|
||||
var balance float64
|
||||
err := tx.Balance.AssignTo(&balance)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return balance
|
||||
}
|
||||
|
||||
func (tx GetAccountsWithBalanceRow) GetPositive() bool {
|
||||
balance := tx.GetBalance()
|
||||
return balance >= 0
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ INSERT INTO accounts
|
||||
VALUES ($1, $2)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAccount :one
|
||||
SELECT accounts.* FROM accounts
|
||||
WHERE accounts.id = $1;
|
||||
|
||||
-- name: GetAccounts :many
|
||||
SELECT accounts.* FROM accounts
|
||||
WHERE accounts.budget_id = $1;
|
||||
|
Reference in New Issue
Block a user