436 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			436 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Code generated by sqlc. DO NOT EDIT.
 | |
| // versions:
 | |
| //   sqlc v1.27.0
 | |
| // source: categroy.sql
 | |
| 
 | |
| package db
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/jackc/pgx/v5/pgtype"
 | |
| )
 | |
| 
 | |
| const allCategories = `-- name: AllCategories :many
 | |
| SELECT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at FROM categories 
 | |
| WHERE status = 0
 | |
| ORDER BY sort DESC, id ASC
 | |
| `
 | |
| 
 | |
| func (q *Queries) AllCategories(ctx context.Context) ([]*Category, error) {
 | |
| 	rows, err := q.db.Query(ctx, allCategories)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*Category{}
 | |
| 	for rows.Next() {
 | |
| 		var i Category
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.Icon,
 | |
| 			&i.Description,
 | |
| 			&i.Letter,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const countCategoriesCondition = `-- name: CountCategoriesCondition :one
 | |
| SELECT COUNT(*) FROM categories
 | |
| WHERE (NOT $1::Boolean OR status = $2)
 | |
|     AND (NOT $3::Boolean OR id = $4)
 | |
|     AND (NOT $5::Boolean OR parent_id = $6)
 | |
|     AND ($7::text = '' OR name ILIKE '%' || $7 || '%')
 | |
| `
 | |
| 
 | |
| type CountCategoriesConditionParams struct {
 | |
| 	IsStatus   bool   `json:"is_status"`
 | |
| 	Status     int16  `json:"status"`
 | |
| 	IsID       bool   `json:"is_id"`
 | |
| 	ID         int32  `json:"id"`
 | |
| 	IsParentID bool   `json:"is_parent_id"`
 | |
| 	ParentID   int32  `json:"parent_id"`
 | |
| 	Name       string `json:"name"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) CountCategoriesCondition(ctx context.Context, arg *CountCategoriesConditionParams) (int64, error) {
 | |
| 	row := q.db.QueryRow(ctx, countCategoriesCondition,
 | |
| 		arg.IsStatus,
 | |
| 		arg.Status,
 | |
| 		arg.IsID,
 | |
| 		arg.ID,
 | |
| 		arg.IsParentID,
 | |
| 		arg.ParentID,
 | |
| 		arg.Name,
 | |
| 	)
 | |
| 	var count int64
 | |
| 	err := row.Scan(&count)
 | |
| 	return count, err
 | |
| }
 | |
| 
 | |
| const createCategory = `-- name: CreateCategory :one
 | |
| INSERT INTO categories (
 | |
|     name,
 | |
|     icon,
 | |
|     description,
 | |
|     letter,
 | |
|     parent_id,
 | |
|     parent_path,
 | |
|     status,
 | |
|     sort
 | |
| )
 | |
| VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
 | |
| RETURNING id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| `
 | |
| 
 | |
| type CreateCategoryParams struct {
 | |
| 	Name        string `json:"name"`
 | |
| 	Icon        string `json:"icon"`
 | |
| 	Description string `json:"description"`
 | |
| 	Letter      string `json:"letter"`
 | |
| 	ParentID    int32  `json:"parent_id"`
 | |
| 	ParentPath  string `json:"parent_path"`
 | |
| 	Status      int16  `json:"status"`
 | |
| 	Sort        int32  `json:"sort"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) CreateCategory(ctx context.Context, arg *CreateCategoryParams) (*Category, error) {
 | |
| 	row := q.db.QueryRow(ctx, createCategory,
 | |
| 		arg.Name,
 | |
| 		arg.Icon,
 | |
| 		arg.Description,
 | |
| 		arg.Letter,
 | |
| 		arg.ParentID,
 | |
| 		arg.ParentPath,
 | |
| 		arg.Status,
 | |
| 		arg.Sort,
 | |
| 	)
 | |
| 	var i Category
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.Icon,
 | |
| 		&i.Description,
 | |
| 		&i.Letter,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 | |
| 
 | |
| const existsCategories = `-- name: ExistsCategories :one
 | |
| SELECT EXISTS (
 | |
|     SELECT 1 FROM categories
 | |
| )
 | |
| `
 | |
| 
 | |
| func (q *Queries) ExistsCategories(ctx context.Context) (bool, error) {
 | |
| 	row := q.db.QueryRow(ctx, existsCategories)
 | |
| 	var exists bool
 | |
| 	err := row.Scan(&exists)
 | |
| 	return exists, err
 | |
| }
 | |
| 
 | |
| const getCategory = `-- name: GetCategory :one
 | |
| SELECT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at 
 | |
| FROM categories 
 | |
| WHERE id = $1
 | |
| LIMIT 1
 | |
| `
 | |
| 
 | |
| func (q *Queries) GetCategory(ctx context.Context, id int32) (*Category, error) {
 | |
| 	row := q.db.QueryRow(ctx, getCategory, id)
 | |
| 	var i Category
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.Icon,
 | |
| 		&i.Description,
 | |
| 		&i.Letter,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 | |
| 
 | |
| const listCategories = `-- name: ListCategories :many
 | |
| SELECT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at FROM categories 
 | |
| WHERE status = 0
 | |
| `
 | |
| 
 | |
| func (q *Queries) ListCategories(ctx context.Context) ([]*Category, error) {
 | |
| 	rows, err := q.db.Query(ctx, listCategories)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*Category{}
 | |
| 	for rows.Next() {
 | |
| 		var i Category
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.Icon,
 | |
| 			&i.Description,
 | |
| 			&i.Letter,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const listCategoriesByPath = `-- name: ListCategoriesByPath :many
 | |
| SELECT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at FROM categories 
 | |
| WHERE parent_path LIKE $1
 | |
| AND status = 0
 | |
| ORDER BY sort DESC, id ASC
 | |
| `
 | |
| 
 | |
| func (q *Queries) ListCategoriesByPath(ctx context.Context, parentPath string) ([]*Category, error) {
 | |
| 	rows, err := q.db.Query(ctx, listCategoriesByPath, parentPath)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*Category{}
 | |
| 	for rows.Next() {
 | |
| 		var i Category
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.Icon,
 | |
| 			&i.Description,
 | |
| 			&i.Letter,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const listCategoriesCondition = `-- name: ListCategoriesCondition :many
 | |
| SELECT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at FROM categories
 | |
| WHERE (NOT $1::Boolean OR status = $2)
 | |
|     AND (NOT $3::Boolean OR id = $4)
 | |
|     AND (NOT $5::Boolean OR parent_id = $6)
 | |
|     AND ($7::text = '' OR name ILIKE '%' || $7 || '%')
 | |
| ORDER BY sort DESC, id ASC
 | |
| OFFSET $8
 | |
| LIMIT $9
 | |
| `
 | |
| 
 | |
| type ListCategoriesConditionParams struct {
 | |
| 	IsStatus   bool   `json:"is_status"`
 | |
| 	Status     int16  `json:"status"`
 | |
| 	IsID       bool   `json:"is_id"`
 | |
| 	ID         int32  `json:"id"`
 | |
| 	IsParentID bool   `json:"is_parent_id"`
 | |
| 	ParentID   int32  `json:"parent_id"`
 | |
| 	Name       string `json:"name"`
 | |
| 	Skip       int32  `json:"skip"`
 | |
| 	Size       int32  `json:"size"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) ListCategoriesCondition(ctx context.Context, arg *ListCategoriesConditionParams) ([]*Category, error) {
 | |
| 	rows, err := q.db.Query(ctx, listCategoriesCondition,
 | |
| 		arg.IsStatus,
 | |
| 		arg.Status,
 | |
| 		arg.IsID,
 | |
| 		arg.ID,
 | |
| 		arg.IsParentID,
 | |
| 		arg.ParentID,
 | |
| 		arg.Name,
 | |
| 		arg.Skip,
 | |
| 		arg.Size,
 | |
| 	)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*Category{}
 | |
| 	for rows.Next() {
 | |
| 		var i Category
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.Icon,
 | |
| 			&i.Description,
 | |
| 			&i.Letter,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const listCategoriesRecursive = `-- name: ListCategoriesRecursive :many
 | |
| WITH RECURSIVE dist AS (SELECT categories.id, categories.name, categories.icon, categories.description, categories.letter, categories.parent_id, categories.parent_path, categories.status, categories.sort, categories.created_at, categories.updated_at
 | |
|                         FROM categories
 | |
|                         WHERE status = 0
 | |
|                         UNION ALL
 | |
|                         SELECT categories.id, categories.name, categories.icon, categories.description, categories.letter, categories.parent_id, categories.parent_path, categories.status, categories.sort, categories.created_at, categories.updated_at
 | |
|                         FROM categories,
 | |
|                              dist
 | |
|                         WHERE categories.id = dist.parent_id)
 | |
| SELECT DISTINCT id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| FROM dist
 | |
| ORDER BY sort DESC, id ASC
 | |
| `
 | |
| 
 | |
| type ListCategoriesRecursiveRow struct {
 | |
| 	ID          int32     `json:"id"`
 | |
| 	Name        string    `json:"name"`
 | |
| 	Icon        string    `json:"icon"`
 | |
| 	Description string    `json:"description"`
 | |
| 	Letter      string    `json:"letter"`
 | |
| 	ParentID    int32     `json:"parent_id"`
 | |
| 	ParentPath  string    `json:"parent_path"`
 | |
| 	Status      int16     `json:"status"`
 | |
| 	Sort        int32     `json:"sort"`
 | |
| 	CreatedAt   time.Time `json:"created_at"`
 | |
| 	UpdatedAt   time.Time `json:"updated_at"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) ListCategoriesRecursive(ctx context.Context) ([]*ListCategoriesRecursiveRow, error) {
 | |
| 	rows, err := q.db.Query(ctx, listCategoriesRecursive)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer rows.Close()
 | |
| 	items := []*ListCategoriesRecursiveRow{}
 | |
| 	for rows.Next() {
 | |
| 		var i ListCategoriesRecursiveRow
 | |
| 		if err := rows.Scan(
 | |
| 			&i.ID,
 | |
| 			&i.Name,
 | |
| 			&i.Icon,
 | |
| 			&i.Description,
 | |
| 			&i.Letter,
 | |
| 			&i.ParentID,
 | |
| 			&i.ParentPath,
 | |
| 			&i.Status,
 | |
| 			&i.Sort,
 | |
| 			&i.CreatedAt,
 | |
| 			&i.UpdatedAt,
 | |
| 		); err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		items = append(items, &i)
 | |
| 	}
 | |
| 	if err := rows.Err(); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return items, nil
 | |
| }
 | |
| 
 | |
| const updateCategory = `-- name: UpdateCategory :one
 | |
| UPDATE categories
 | |
| SET
 | |
|     name = COALESCE($2, name),
 | |
|     icon = COALESCE($3, icon),
 | |
|     description = COALESCE($4, description),
 | |
|     letter = COALESCE($5, letter),
 | |
|     parent_id = COALESCE($6, parent_id),
 | |
|     parent_path = COALESCE($7, parent_path),
 | |
|     sort = COALESCE($8, sort),
 | |
|     status = COALESCE($9, status),
 | |
|     updated_at = NOW()
 | |
| WHERE id = $1
 | |
| RETURNING id, name, icon, description, letter, parent_id, parent_path, status, sort, created_at, updated_at
 | |
| `
 | |
| 
 | |
| type UpdateCategoryParams struct {
 | |
| 	ID          int32       `json:"id"`
 | |
| 	Name        pgtype.Text `json:"name"`
 | |
| 	Icon        pgtype.Text `json:"icon"`
 | |
| 	Description pgtype.Text `json:"description"`
 | |
| 	Letter      pgtype.Text `json:"letter"`
 | |
| 	ParentID    pgtype.Int4 `json:"parent_id"`
 | |
| 	ParentPath  pgtype.Text `json:"parent_path"`
 | |
| 	Sort        pgtype.Int4 `json:"sort"`
 | |
| 	Status      pgtype.Int2 `json:"status"`
 | |
| }
 | |
| 
 | |
| func (q *Queries) UpdateCategory(ctx context.Context, arg *UpdateCategoryParams) (*Category, error) {
 | |
| 	row := q.db.QueryRow(ctx, updateCategory,
 | |
| 		arg.ID,
 | |
| 		arg.Name,
 | |
| 		arg.Icon,
 | |
| 		arg.Description,
 | |
| 		arg.Letter,
 | |
| 		arg.ParentID,
 | |
| 		arg.ParentPath,
 | |
| 		arg.Sort,
 | |
| 		arg.Status,
 | |
| 	)
 | |
| 	var i Category
 | |
| 	err := row.Scan(
 | |
| 		&i.ID,
 | |
| 		&i.Name,
 | |
| 		&i.Icon,
 | |
| 		&i.Description,
 | |
| 		&i.Letter,
 | |
| 		&i.ParentID,
 | |
| 		&i.ParentPath,
 | |
| 		&i.Status,
 | |
| 		&i.Sort,
 | |
| 		&i.CreatedAt,
 | |
| 		&i.UpdatedAt,
 | |
| 	)
 | |
| 	return &i, err
 | |
| }
 |