344 lines
8.7 KiB
Go
344 lines
8.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: project.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const allProjects = `-- name: AllProjects :many
|
|
SELECT id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, sort, created_at, created_user_id, updated_at, updated_user_id FROM projects
|
|
WHERE status > -1
|
|
ORDER BY id DESC
|
|
`
|
|
|
|
func (q *Queries) AllProjects(ctx context.Context) ([]*Project, error) {
|
|
rows, err := q.db.Query(ctx, allProjects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Project{}
|
|
for rows.Next() {
|
|
var i Project
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.CustomerID,
|
|
&i.TotalMoney,
|
|
&i.Description,
|
|
&i.ApplyAt,
|
|
&i.ApplyUserID,
|
|
&i.ManagerID,
|
|
&i.Members,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedUserID,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedUserID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const countProjects = `-- name: CountProjects :one
|
|
SELECT COUNT(1)
|
|
FROM projects
|
|
WHERE status = $1
|
|
`
|
|
|
|
func (q *Queries) CountProjects(ctx context.Context, status int16) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countProjects, status)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createProject = `-- name: CreateProject :one
|
|
INSERT INTO projects (id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, created_user_id)
|
|
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
|
RETURNING id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, sort, created_at, created_user_id, updated_at, updated_user_id
|
|
`
|
|
|
|
type CreateProjectParams struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
StartAt time.Time `json:"start_at"`
|
|
EndAt time.Time `json:"end_at"`
|
|
CustomerID int64 `json:"customer_id"`
|
|
TotalMoney pgtype.Numeric `json:"total_money"`
|
|
Description string `json:"description"`
|
|
ApplyAt time.Time `json:"apply_at"`
|
|
ApplyUserID int32 `json:"apply_user_id"`
|
|
ManagerID int32 `json:"manager_id"`
|
|
Members string `json:"members"`
|
|
Status int16 `json:"status"`
|
|
CreatedUserID int32 `json:"created_user_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateProject(ctx context.Context, arg *CreateProjectParams) (*Project, error) {
|
|
row := q.db.QueryRow(ctx, createProject,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.StartAt,
|
|
arg.EndAt,
|
|
arg.CustomerID,
|
|
arg.TotalMoney,
|
|
arg.Description,
|
|
arg.ApplyAt,
|
|
arg.ApplyUserID,
|
|
arg.ManagerID,
|
|
arg.Members,
|
|
arg.Status,
|
|
arg.CreatedUserID,
|
|
)
|
|
var i Project
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.CustomerID,
|
|
&i.TotalMoney,
|
|
&i.Description,
|
|
&i.ApplyAt,
|
|
&i.ApplyUserID,
|
|
&i.ManagerID,
|
|
&i.Members,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedUserID,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedUserID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getProject = `-- name: GetProject :one
|
|
SELECT id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, sort, created_at, created_user_id, updated_at, updated_user_id
|
|
FROM projects
|
|
WHERE id = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetProject(ctx context.Context, id int64) (*Project, error) {
|
|
row := q.db.QueryRow(ctx, getProject, id)
|
|
var i Project
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.CustomerID,
|
|
&i.TotalMoney,
|
|
&i.Description,
|
|
&i.ApplyAt,
|
|
&i.ApplyUserID,
|
|
&i.ManagerID,
|
|
&i.Members,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedUserID,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedUserID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listProjects = `-- name: ListProjects :many
|
|
SELECT id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, sort, created_at, created_user_id, updated_at, updated_user_id
|
|
FROM projects
|
|
WHERE status = $1
|
|
ORDER BY id DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListProjectsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListProjects(ctx context.Context, arg *ListProjectsParams) ([]*Project, error) {
|
|
rows, err := q.db.Query(ctx, listProjects, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Project{}
|
|
for rows.Next() {
|
|
var i Project
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.CustomerID,
|
|
&i.TotalMoney,
|
|
&i.Description,
|
|
&i.ApplyAt,
|
|
&i.ApplyUserID,
|
|
&i.ManagerID,
|
|
&i.Members,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedUserID,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedUserID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const statisticsProjectItem = `-- name: StatisticsProjectItem :one
|
|
select name,
|
|
(select sum(amount)::numeric from incomes where project_id = projects.id) income,
|
|
(select sum(amount)::numeric from expenses where project_id = projects.id) expense
|
|
from projects
|
|
where projects.id = $1
|
|
`
|
|
|
|
type StatisticsProjectItemRow struct {
|
|
Name string `json:"name"`
|
|
Income pgtype.Numeric `json:"income"`
|
|
Expense pgtype.Numeric `json:"expense"`
|
|
}
|
|
|
|
func (q *Queries) StatisticsProjectItem(ctx context.Context, id int64) (*StatisticsProjectItemRow, error) {
|
|
row := q.db.QueryRow(ctx, statisticsProjectItem, id)
|
|
var i StatisticsProjectItemRow
|
|
err := row.Scan(&i.Name, &i.Income, &i.Expense)
|
|
return &i, err
|
|
}
|
|
|
|
const statisticsProjects = `-- name: StatisticsProjects :many
|
|
select name,
|
|
(select sum(amount)::numeric from incomes where project_id = projects.id) income,
|
|
(select sum(amount)::numeric from expenses where project_id = projects.id) expense
|
|
from projects
|
|
`
|
|
|
|
type StatisticsProjectsRow struct {
|
|
Name string `json:"name"`
|
|
Income pgtype.Numeric `json:"income"`
|
|
Expense pgtype.Numeric `json:"expense"`
|
|
}
|
|
|
|
func (q *Queries) StatisticsProjects(ctx context.Context) ([]*StatisticsProjectsRow, error) {
|
|
rows, err := q.db.Query(ctx, statisticsProjects)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*StatisticsProjectsRow{}
|
|
for rows.Next() {
|
|
var i StatisticsProjectsRow
|
|
if err := rows.Scan(&i.Name, &i.Income, &i.Expense); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateProject = `-- name: UpdateProject :one
|
|
UPDATE projects
|
|
SET
|
|
name = COALESCE($2, name),
|
|
start_at = COALESCE($3, start_at),
|
|
end_at = COALESCE($4, end_at),
|
|
customer_id = COALESCE($5, customer_id),
|
|
total_money = COALESCE($6, total_money),
|
|
description = COALESCE($7, description),
|
|
apply_at = COALESCE($8, apply_at),
|
|
apply_user_id = COALESCE($9, apply_user_id),
|
|
manager_id = COALESCE($10, manager_id),
|
|
members = COALESCE($11, members),
|
|
status = COALESCE($12, status),
|
|
updated_user_id = COALESCE($13, updated_user_id),
|
|
updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING id, name, start_at, end_at, customer_id, total_money, description, apply_at, apply_user_id, manager_id, members, status, sort, created_at, created_user_id, updated_at, updated_user_id
|
|
`
|
|
|
|
type UpdateProjectParams struct {
|
|
ID int64 `json:"id"`
|
|
Name pgtype.Text `json:"name"`
|
|
StartAt pgtype.Timestamptz `json:"start_at"`
|
|
EndAt pgtype.Timestamptz `json:"end_at"`
|
|
CustomerID pgtype.Int8 `json:"customer_id"`
|
|
TotalMoney pgtype.Numeric `json:"total_money"`
|
|
Description pgtype.Text `json:"description"`
|
|
ApplyAt pgtype.Timestamptz `json:"apply_at"`
|
|
ApplyUserID pgtype.Int4 `json:"apply_user_id"`
|
|
ManagerID pgtype.Int4 `json:"manager_id"`
|
|
Members pgtype.Text `json:"members"`
|
|
Status pgtype.Int2 `json:"status"`
|
|
UpdatedUserID pgtype.Int4 `json:"updated_user_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProject(ctx context.Context, arg *UpdateProjectParams) (*Project, error) {
|
|
row := q.db.QueryRow(ctx, updateProject,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.StartAt,
|
|
arg.EndAt,
|
|
arg.CustomerID,
|
|
arg.TotalMoney,
|
|
arg.Description,
|
|
arg.ApplyAt,
|
|
arg.ApplyUserID,
|
|
arg.ManagerID,
|
|
arg.Members,
|
|
arg.Status,
|
|
arg.UpdatedUserID,
|
|
)
|
|
var i Project
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.StartAt,
|
|
&i.EndAt,
|
|
&i.CustomerID,
|
|
&i.TotalMoney,
|
|
&i.Description,
|
|
&i.ApplyAt,
|
|
&i.ApplyUserID,
|
|
&i.ManagerID,
|
|
&i.Members,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.CreatedUserID,
|
|
&i.UpdatedAt,
|
|
&i.UpdatedUserID,
|
|
)
|
|
return &i, err
|
|
}
|