Import category
This commit is contained in:
117
postgres/categories.sql.go
Normal file
117
postgres/categories.sql.go
Normal file
@ -0,0 +1,117 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// source: categories.sql
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createCategory = `-- name: CreateCategory :one
|
||||
INSERT INTO categories
|
||||
(name, category_group_id)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, category_group_id, name
|
||||
`
|
||||
|
||||
type CreateCategoryParams struct {
|
||||
Name string
|
||||
CategoryGroupID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCategory(ctx context.Context, arg CreateCategoryParams) (Category, error) {
|
||||
row := q.db.QueryRowContext(ctx, createCategory, arg.Name, arg.CategoryGroupID)
|
||||
var i Category
|
||||
err := row.Scan(&i.ID, &i.CategoryGroupID, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createCategoryGroup = `-- name: CreateCategoryGroup :one
|
||||
INSERT INTO category_groups
|
||||
(name, budget_id)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id, budget_id, name
|
||||
`
|
||||
|
||||
type CreateCategoryGroupParams struct {
|
||||
Name string
|
||||
BudgetID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCategoryGroup(ctx context.Context, arg CreateCategoryGroupParams) (CategoryGroup, error) {
|
||||
row := q.db.QueryRowContext(ctx, createCategoryGroup, arg.Name, arg.BudgetID)
|
||||
var i CategoryGroup
|
||||
err := row.Scan(&i.ID, &i.BudgetID, &i.Name)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCategories = `-- name: GetCategories :many
|
||||
SELECT categories.id, categories.category_group_id, categories.name, category_groups.name as group FROM categories
|
||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||
WHERE category_groups.budget_id = $1
|
||||
`
|
||||
|
||||
type GetCategoriesRow struct {
|
||||
ID uuid.UUID
|
||||
CategoryGroupID uuid.UUID
|
||||
Name string
|
||||
Group string
|
||||
}
|
||||
|
||||
func (q *Queries) GetCategories(ctx context.Context, budgetID uuid.UUID) ([]GetCategoriesRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getCategories, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetCategoriesRow
|
||||
for rows.Next() {
|
||||
var i GetCategoriesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CategoryGroupID,
|
||||
&i.Name,
|
||||
&i.Group,
|
||||
); 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 getCategoryGroups = `-- name: GetCategoryGroups :many
|
||||
SELECT category_groups.id, category_groups.budget_id, category_groups.name FROM category_groups
|
||||
WHERE category_groups.budget_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCategoryGroups(ctx context.Context, budgetID uuid.UUID) ([]CategoryGroup, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getCategoryGroups, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []CategoryGroup
|
||||
for rows.Next() {
|
||||
var i CategoryGroup
|
||||
if err := rows.Scan(&i.ID, &i.BudgetID, &i.Name); 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
|
||||
}
|
Reference in New Issue
Block a user