63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// source: budgets.sql
|
|
|
|
package postgres
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createBudget = `-- name: CreateBudget :one
|
|
INSERT INTO budgets
|
|
(name, last_modification)
|
|
VALUES ($1, NOW())
|
|
RETURNING id, name, last_modification
|
|
`
|
|
|
|
func (q *Queries) CreateBudget(ctx context.Context, name string) (Budget, error) {
|
|
row := q.db.QueryRow(ctx, createBudget, name)
|
|
var i Budget
|
|
err := row.Scan(&i.ID, &i.Name, &i.LastModification)
|
|
return i, err
|
|
}
|
|
|
|
const getBudget = `-- name: GetBudget :one
|
|
SELECT id, name, last_modification FROM budgets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBudget(ctx context.Context, id uuid.UUID) (Budget, error) {
|
|
row := q.db.QueryRow(ctx, getBudget, id)
|
|
var i Budget
|
|
err := row.Scan(&i.ID, &i.Name, &i.LastModification)
|
|
return i, err
|
|
}
|
|
|
|
const getBudgetsForUser = `-- name: GetBudgetsForUser :many
|
|
SELECT budgets.id, budgets.name, budgets.last_modification FROM budgets
|
|
LEFT JOIN user_budgets ON budgets.id = user_budgets.budget_id
|
|
WHERE user_budgets.user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBudgetsForUser(ctx context.Context, userID uuid.UUID) ([]Budget, error) {
|
|
rows, err := q.db.Query(ctx, getBudgetsForUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Budget
|
|
for rows.Next() {
|
|
var i Budget
|
|
if err := rows.Scan(&i.ID, &i.Name, &i.LastModification); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|