663 lines
15 KiB
Go
663 lines
15 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: query.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"strings"
|
|
)
|
|
|
|
const addTaskCategory = `-- name: AddTaskCategory :one
|
|
INSERT INTO task_categories (task_id, category_id)
|
|
VALUES (?, ?)
|
|
RETURNING task_id, category_id
|
|
`
|
|
|
|
type AddTaskCategoryParams struct {
|
|
TaskID int64 `json:"task_id"`
|
|
CategoryID int64 `json:"category_id"`
|
|
}
|
|
|
|
func (q *Queries) AddTaskCategory(ctx context.Context, arg AddTaskCategoryParams) (TaskCategory, error) {
|
|
row := q.db.QueryRowContext(ctx, addTaskCategory, arg.TaskID, arg.CategoryID)
|
|
var i TaskCategory
|
|
err := row.Scan(&i.TaskID, &i.CategoryID)
|
|
return i, err
|
|
}
|
|
|
|
const allTasks = `-- name: AllTasks :many
|
|
SELECT id, name, description, completed, created_by, assigned_to, created_at, deadline FROM tasks
|
|
`
|
|
|
|
func (q *Queries) AllTasks(ctx context.Context) ([]Task, error) {
|
|
rows, err := q.db.QueryContext(ctx, allTasks)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Task
|
|
for rows.Next() {
|
|
var i Task
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
); 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 categoriesOf = `-- name: CategoriesOf :many
|
|
SELECT c.id, c.name, c.description, c.created_by, c.created_at FROM categories c
|
|
JOIN task_categories tc ON tc.category_id = c.id
|
|
WHERE tc.task_id IN (/*SLICE:ids*/?)
|
|
`
|
|
|
|
func (q *Queries) CategoriesOf(ctx context.Context, ids []int64) ([]Category, error) {
|
|
query := categoriesOf
|
|
var queryParams []interface{}
|
|
if len(ids) > 0 {
|
|
for _, v := range ids {
|
|
queryParams = append(queryParams, v)
|
|
}
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", strings.Repeat(",?", len(ids))[1:], 1)
|
|
} else {
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
|
|
}
|
|
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Category
|
|
for rows.Next() {
|
|
var i Category
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
); 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 completeTask = `-- name: CompleteTask :one
|
|
UPDATE tasks SET completed = TRUE WHERE id = ? RETURNING id, name, description, completed, created_by, assigned_to, created_at, deadline
|
|
`
|
|
|
|
func (q *Queries) CompleteTask(ctx context.Context, id int64) (Task, error) {
|
|
row := q.db.QueryRowContext(ctx, completeTask, id)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createCategory = `-- name: CreateCategory :one
|
|
INSERT INTO categories (
|
|
name, description, created_by, created_at
|
|
) VALUES (?, ?, ?, ?)
|
|
RETURNING id, name, description, created_by, created_at
|
|
`
|
|
|
|
type CreateCategoryParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
CreatedBy string `json:"created_by"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateCategory(ctx context.Context, arg CreateCategoryParams) (Category, error) {
|
|
row := q.db.QueryRowContext(ctx, createCategory,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.CreatedBy,
|
|
arg.CreatedAt,
|
|
)
|
|
var i Category
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createSession = `-- name: CreateSession :one
|
|
INSERT INTO sessions (
|
|
key,
|
|
user_id,
|
|
created_at
|
|
) VALUES (?, ?, ?)
|
|
RETURNING "key", user_id, created_at
|
|
`
|
|
|
|
type CreateSessionParams struct {
|
|
Key []byte `json:"key"`
|
|
UserID string `json:"user_id"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) {
|
|
row := q.db.QueryRowContext(ctx, createSession, arg.Key, arg.UserID, arg.CreatedAt)
|
|
var i Session
|
|
err := row.Scan(&i.Key, &i.UserID, &i.CreatedAt)
|
|
return i, err
|
|
}
|
|
|
|
const createTask = `-- name: CreateTask :one
|
|
INSERT INTO tasks (
|
|
name,
|
|
description,
|
|
created_by,
|
|
assigned_to,
|
|
created_at,
|
|
deadline,
|
|
completed
|
|
) VALUES (?, ?, ?, ?, ?, ?, FALSE)
|
|
RETURNING id, name, description, completed, created_by, assigned_to, created_at, deadline
|
|
`
|
|
|
|
type CreateTaskParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
CreatedBy string `json:"created_by"`
|
|
AssignedTo string `json:"assigned_to"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
Deadline sql.NullInt64 `json:"deadline"`
|
|
}
|
|
|
|
func (q *Queries) CreateTask(ctx context.Context, arg CreateTaskParams) (Task, error) {
|
|
row := q.db.QueryRowContext(ctx, createTask,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.CreatedBy,
|
|
arg.AssignedTo,
|
|
arg.CreatedAt,
|
|
arg.Deadline,
|
|
)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (
|
|
id,
|
|
username
|
|
) VALUES (
|
|
?, ?
|
|
) RETURNING id, username
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
type CreateUserRow struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, createUser, arg.ID, arg.Username)
|
|
var i CreateUserRow
|
|
err := row.Scan(&i.ID, &i.Username)
|
|
return i, err
|
|
}
|
|
|
|
const deleteCategory = `-- name: DeleteCategory :one
|
|
DELETE FROM categories WHERE id = ? LIMIT 1 RETURNING id, name, description, created_by, created_at
|
|
`
|
|
|
|
func (q *Queries) DeleteCategory(ctx context.Context, id int64) (Category, error) {
|
|
row := q.db.QueryRowContext(ctx, deleteCategory, id)
|
|
var i Category
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteSession = `-- name: DeleteSession :exec
|
|
DELETE FROM sessions WHERE key = ? LIMIT 1 RETURNING "key", user_id, created_at
|
|
`
|
|
|
|
func (q *Queries) DeleteSession(ctx context.Context, key []byte) error {
|
|
_, err := q.db.ExecContext(ctx, deleteSession, key)
|
|
return err
|
|
}
|
|
|
|
const deleteTask = `-- name: DeleteTask :exec
|
|
DELETE FROM tasks WHERE id = ? LIMIT 1 RETURNING id, name, description, completed, created_by, assigned_to, created_at, deadline
|
|
`
|
|
|
|
func (q *Queries) DeleteTask(ctx context.Context, id int64) error {
|
|
_, err := q.db.ExecContext(ctx, deleteTask, id)
|
|
return err
|
|
}
|
|
|
|
const getSession = `-- name: GetSession :one
|
|
SELECT "key", user_id, created_at FROM sessions WHERE key = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetSession(ctx context.Context, key []byte) (Session, error) {
|
|
row := q.db.QueryRowContext(ctx, getSession, key)
|
|
var i Session
|
|
err := row.Scan(&i.Key, &i.UserID, &i.CreatedAt)
|
|
return i, err
|
|
}
|
|
|
|
const getUser = `-- name: GetUser :one
|
|
SELECT id, username FROM users WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
type GetUserRow struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
func (q *Queries) GetUser(ctx context.Context, id string) (GetUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUser, id)
|
|
var i GetUserRow
|
|
err := row.Scan(&i.ID, &i.Username)
|
|
return i, err
|
|
}
|
|
|
|
const getUserPassword = `-- name: GetUserPassword :one
|
|
SELECT id, password FROM users WHERE username = ? LIMIT 1
|
|
`
|
|
|
|
type GetUserPasswordRow struct {
|
|
ID string `json:"id"`
|
|
Password []byte `json:"password"`
|
|
}
|
|
|
|
func (q *Queries) GetUserPassword(ctx context.Context, username string) (GetUserPasswordRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserPassword, username)
|
|
var i GetUserPasswordRow
|
|
err := row.Scan(&i.ID, &i.Password)
|
|
return i, err
|
|
}
|
|
|
|
const getUsers = `-- name: GetUsers :many
|
|
SELECT id, username, password FROM users ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) GetUsers(ctx context.Context) ([]User, error) {
|
|
rows, err := q.db.QueryContext(ctx, getUsers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []User
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(&i.ID, &i.Username, &i.Password); 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 listCategories = `-- name: ListCategories :many
|
|
SELECT id, name, description, created_by, created_at FROM categories
|
|
`
|
|
|
|
func (q *Queries) ListCategories(ctx context.Context) ([]Category, error) {
|
|
rows, err := q.db.QueryContext(ctx, listCategories)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Category
|
|
for rows.Next() {
|
|
var i Category
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
); 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 taskByID = `-- name: TaskByID :one
|
|
SELECT id, name, description, completed, created_by, assigned_to, created_at, deadline FROM tasks WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
|
row := q.db.QueryRowContext(ctx, taskByID, id)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const taskCategoriesOf = `-- name: TaskCategoriesOf :many
|
|
SELECT tc.task_id, tc.category_id FROM task_categories tc
|
|
JOIN tasks t ON tc.task_id = t.id
|
|
WHERE tc.task_id IN (/*SLICE:ids*/?)
|
|
`
|
|
|
|
func (q *Queries) TaskCategoriesOf(ctx context.Context, ids []int64) ([]TaskCategory, error) {
|
|
query := taskCategoriesOf
|
|
var queryParams []interface{}
|
|
if len(ids) > 0 {
|
|
for _, v := range ids {
|
|
queryParams = append(queryParams, v)
|
|
}
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", strings.Repeat(",?", len(ids))[1:], 1)
|
|
} else {
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
|
|
}
|
|
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TaskCategory
|
|
for rows.Next() {
|
|
var i TaskCategory
|
|
if err := rows.Scan(&i.TaskID, &i.CategoryID); 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 tasksForUser = `-- name: TasksForUser :many
|
|
SELECT id, name, description, completed, created_by, assigned_to, created_at, deadline FROM tasks WHERE assigned_to = ?
|
|
`
|
|
|
|
func (q *Queries) TasksForUser(ctx context.Context, assignedTo string) ([]Task, error) {
|
|
rows, err := q.db.QueryContext(ctx, tasksForUser, assignedTo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Task
|
|
for rows.Next() {
|
|
var i Task
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
); 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 updateCategory = `-- name: UpdateCategory :one
|
|
UPDATE categories SET
|
|
name = ?,
|
|
description = ?
|
|
WHERE id = ?
|
|
RETURNING id, name, description, created_by, created_at
|
|
`
|
|
|
|
type UpdateCategoryParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCategory(ctx context.Context, arg UpdateCategoryParams) (Category, error) {
|
|
row := q.db.QueryRowContext(ctx, updateCategory, arg.Name, arg.Description, arg.ID)
|
|
var i Category
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateTask = `-- name: UpdateTask :one
|
|
UPDATE tasks SET
|
|
name = ?,
|
|
description = ?
|
|
WHERE id = ?
|
|
RETURNING id, name, description, completed, created_by, assigned_to, created_at, deadline
|
|
`
|
|
|
|
type UpdateTaskParams struct {
|
|
Name string `json:"name"`
|
|
Description sql.NullString `json:"description"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) (Task, error) {
|
|
row := q.db.QueryRowContext(ctx, updateTask, arg.Name, arg.Description, arg.ID)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :one
|
|
UPDATE users
|
|
set username = ?
|
|
WHERE id = ?
|
|
RETURNING id, username
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
Username string `json:"username"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type UpdateUserRow struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
|
row := q.db.QueryRowContext(ctx, updateUser, arg.Username, arg.ID)
|
|
var i UpdateUserRow
|
|
err := row.Scan(&i.ID, &i.Username)
|
|
return i, err
|
|
}
|
|
|
|
const updateUserPassword = `-- name: UpdateUserPassword :one
|
|
UPDATE users
|
|
set password = ?
|
|
WHERE id = ?
|
|
RETURNING id, username
|
|
`
|
|
|
|
type UpdateUserPasswordParams struct {
|
|
Password []byte `json:"password"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type UpdateUserPasswordRow struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserPassword(ctx context.Context, arg UpdateUserPasswordParams) (UpdateUserPasswordRow, error) {
|
|
row := q.db.QueryRowContext(ctx, updateUserPassword, arg.Password, arg.ID)
|
|
var i UpdateUserPasswordRow
|
|
err := row.Scan(&i.ID, &i.Username)
|
|
return i, err
|
|
}
|
|
|
|
const userCategories = `-- name: UserCategories :many
|
|
SELECT id, name, description, created_by, created_at FROM categories WHERE created_by = ?
|
|
`
|
|
|
|
func (q *Queries) UserCategories(ctx context.Context, createdBy string) ([]Category, error) {
|
|
rows, err := q.db.QueryContext(ctx, userCategories, createdBy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Category
|
|
for rows.Next() {
|
|
var i Category
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.CreatedBy,
|
|
&i.CreatedAt,
|
|
); 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 userTasks = `-- name: UserTasks :many
|
|
SELECT id, name, description, completed, created_by, assigned_to, created_at, deadline FROM tasks WHERE created_by = ?
|
|
`
|
|
|
|
func (q *Queries) UserTasks(ctx context.Context, createdBy string) ([]Task, error) {
|
|
rows, err := q.db.QueryContext(ctx, userTasks, createdBy)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Task
|
|
for rows.Next() {
|
|
var i Task
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Completed,
|
|
&i.CreatedBy,
|
|
&i.AssignedTo,
|
|
&i.CreatedAt,
|
|
&i.Deadline,
|
|
); 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
|
|
}
|