Add accounts
This commit is contained in:
49
postgres/accounts.sql.go
Normal file
49
postgres/accounts.sql.go
Normal file
@ -0,0 +1,49 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// source: accounts.sql
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createAccount = `-- name: CreateAccount :one
|
||||
INSERT INTO accounts
|
||||
(name)
|
||||
VALUES ($1)
|
||||
RETURNING id, budget_id, name
|
||||
`
|
||||
|
||||
func (q *Queries) CreateAccount(ctx context.Context, name string) (Account, error) {
|
||||
row := q.db.QueryRow(ctx, createAccount, name)
|
||||
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
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccounts(ctx context.Context, budgetID uuid.UUID) ([]Account, error) {
|
||||
rows, err := q.db.Query(ctx, getAccounts, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Account
|
||||
for rows.Next() {
|
||||
var i Account
|
||||
if err := rows.Scan(&i.ID, &i.BudgetID, &i.Name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
9
postgres/queries/accounts.sql
Normal file
9
postgres/queries/accounts.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- name: CreateAccount :one
|
||||
INSERT INTO accounts
|
||||
(name)
|
||||
VALUES ($1)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAccounts :many
|
||||
SELECT accounts.* FROM accounts
|
||||
WHERE accounts.budget_id = $1;
|
Reference in New Issue
Block a user