330 lines
8.3 KiB
Go
330 lines
8.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: sys_menus.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const countSysMenus = `-- name: CountSysMenus :one
|
|
SELECT COUNT(*)
|
|
FROM sys_menus
|
|
`
|
|
|
|
func (q *Queries) CountSysMenus(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countSysMenus)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createSysMenu = `-- name: CreateSysMenu :one
|
|
INSERT INTO sys_menus (name, path, component, type, hidden, sort, status, parent_id, icon)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateSysMenuParams struct {
|
|
Name string `json:"name"`
|
|
Path *string `json:"path"`
|
|
Component *string `json:"component"`
|
|
Type int16 `json:"type"`
|
|
Hidden *bool `json:"hidden"`
|
|
Sort *int32 `json:"sort"`
|
|
Status int16 `json:"status"`
|
|
ParentID *int32 `json:"parent_id"`
|
|
Icon *int32 `json:"icon"`
|
|
}
|
|
|
|
func (q *Queries) CreateSysMenu(ctx context.Context, arg CreateSysMenuParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, createSysMenu,
|
|
arg.Name,
|
|
arg.Path,
|
|
arg.Component,
|
|
arg.Type,
|
|
arg.Hidden,
|
|
arg.Sort,
|
|
arg.Status,
|
|
arg.ParentID,
|
|
arg.Icon,
|
|
)
|
|
var id int32
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createSysMenuPermission = `-- name: CreateSysMenuPermission :exec
|
|
INSERT INTO sys_menu_permission (menu_id, permission_id)
|
|
VALUES ($1, $2)
|
|
`
|
|
|
|
type CreateSysMenuPermissionParams struct {
|
|
MenuID int32 `json:"menu_id"`
|
|
PermissionID int32 `json:"permission_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateSysMenuPermission(ctx context.Context, arg CreateSysMenuPermissionParams) error {
|
|
_, err := q.db.Exec(ctx, createSysMenuPermission, arg.MenuID, arg.PermissionID)
|
|
return err
|
|
}
|
|
|
|
const deleteSysMenu = `-- name: DeleteSysMenu :execrows
|
|
DELETE
|
|
FROM sys_menus
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSysMenu(ctx context.Context, id int32) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteSysMenu, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const deleteSysMenuPermission = `-- name: DeleteSysMenuPermission :exec
|
|
DELETE
|
|
FROM sys_menu_permission
|
|
WHERE menu_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSysMenuPermission(ctx context.Context, menuID int32) error {
|
|
_, err := q.db.Exec(ctx, deleteSysMenuPermission, menuID)
|
|
return err
|
|
}
|
|
|
|
const deleteSysPermissionByMenuID = `-- name: DeleteSysPermissionByMenuID :exec
|
|
DELETE
|
|
FROM sys_permissions
|
|
WHERE id IN (SELECT permission_id
|
|
FROM sys_menu_permission
|
|
WHERE menu_id = $1)
|
|
`
|
|
|
|
func (q *Queries) DeleteSysPermissionByMenuID(ctx context.Context, menuID int32) error {
|
|
_, err := q.db.Exec(ctx, deleteSysPermissionByMenuID, menuID)
|
|
return err
|
|
}
|
|
|
|
const getAllSysMenus = `-- name: GetAllSysMenus :many
|
|
SELECT m.id, m.name, m.path, m.component, m.type, m.hidden, m.sort, m.status, m.parent_id, m.icon, m.created_at, m.updated_at,
|
|
p.code AS permission_code
|
|
FROM sys_menus m
|
|
LEFT JOIN sys_menu_permission mp ON m.id = mp.menu_id
|
|
LEFT JOIN sys_permissions p ON p.id = mp.permission_id
|
|
ORDER BY m.sort ASC,
|
|
m.id ASC
|
|
`
|
|
|
|
type GetAllSysMenusRow struct {
|
|
ID int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Path *string `json:"path"`
|
|
Component *string `json:"component"`
|
|
Type int16 `json:"type"`
|
|
Hidden *bool `json:"hidden"`
|
|
Sort *int32 `json:"sort"`
|
|
Status int16 `json:"status"`
|
|
ParentID *int32 `json:"parent_id"`
|
|
Icon *int32 `json:"icon"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt *time.Time `json:"updated_at"`
|
|
PermissionCode *string `json:"permission_code"`
|
|
}
|
|
|
|
func (q *Queries) GetAllSysMenus(ctx context.Context) ([]GetAllSysMenusRow, error) {
|
|
rows, err := q.db.Query(ctx, getAllSysMenus)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []GetAllSysMenusRow{}
|
|
for rows.Next() {
|
|
var i GetAllSysMenusRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Path,
|
|
&i.Component,
|
|
&i.Type,
|
|
&i.Hidden,
|
|
&i.Sort,
|
|
&i.Status,
|
|
&i.ParentID,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PermissionCode,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getSysMenuByID = `-- name: GetSysMenuByID :one
|
|
SELECT id, name, path, component, type, hidden, sort, status, parent_id, icon, created_at, updated_at
|
|
FROM sys_menus
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSysMenuByID(ctx context.Context, id int32) (SysMenu, error) {
|
|
row := q.db.QueryRow(ctx, getSysMenuByID, id)
|
|
var i SysMenu
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Path,
|
|
&i.Component,
|
|
&i.Type,
|
|
&i.Hidden,
|
|
&i.Sort,
|
|
&i.Status,
|
|
&i.ParentID,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listSysMenus = `-- name: ListSysMenus :many
|
|
SELECT m.id, m.name, m.path, m.component, m.type, m.hidden, m.sort, m.status, m.parent_id, m.icon, m.created_at, m.updated_at, p.code AS permission_code
|
|
FROM sys_menus m
|
|
LEFT JOIN sys_menu_permission mp ON m.id = mp.menu_id
|
|
LEFT JOIN sys_permissions p ON mp.permission_id = p.id
|
|
ORDER BY m.id
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListSysMenusParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListSysMenusRow struct {
|
|
ID int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Path *string `json:"path"`
|
|
Component *string `json:"component"`
|
|
Type int16 `json:"type"`
|
|
Hidden *bool `json:"hidden"`
|
|
Sort *int32 `json:"sort"`
|
|
Status int16 `json:"status"`
|
|
ParentID *int32 `json:"parent_id"`
|
|
Icon *int32 `json:"icon"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt *time.Time `json:"updated_at"`
|
|
PermissionCode *string `json:"permission_code"`
|
|
}
|
|
|
|
func (q *Queries) ListSysMenus(ctx context.Context, arg ListSysMenusParams) ([]ListSysMenusRow, error) {
|
|
rows, err := q.db.Query(ctx, listSysMenus, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListSysMenusRow{}
|
|
for rows.Next() {
|
|
var i ListSysMenusRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Path,
|
|
&i.Component,
|
|
&i.Type,
|
|
&i.Hidden,
|
|
&i.Sort,
|
|
&i.Status,
|
|
&i.ParentID,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PermissionCode,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateSysMenu = `-- name: UpdateSysMenu :execrows
|
|
UPDATE sys_menus
|
|
SET name = coalesce($1, name),
|
|
path = coalesce($2, path),
|
|
component = coalesce($3, component),
|
|
type = coalesce($4, type),
|
|
hidden = coalesce($5, hidden),
|
|
sort = coalesce($6, sort),
|
|
status = coalesce($7, status),
|
|
icon = CASE WHEN $8::boolean THEN $9 ELSE icon END,
|
|
parent_id = CASE WHEN $10::boolean THEN $11 ELSE parent_id END
|
|
WHERE id = $12
|
|
`
|
|
|
|
type UpdateSysMenuParams struct {
|
|
Name *string `json:"name"`
|
|
Path *string `json:"path"`
|
|
Component *string `json:"component"`
|
|
Type *int16 `json:"type"`
|
|
Hidden *bool `json:"hidden"`
|
|
Sort *int32 `json:"sort"`
|
|
Status *int16 `json:"status"`
|
|
UpdateIcon bool `json:"update_icon"`
|
|
Icon *int32 `json:"icon"`
|
|
UpdateParentID bool `json:"update_parent_id"`
|
|
ParentID *int32 `json:"parent_id"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSysMenu(ctx context.Context, arg UpdateSysMenuParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, updateSysMenu,
|
|
arg.Name,
|
|
arg.Path,
|
|
arg.Component,
|
|
arg.Type,
|
|
arg.Hidden,
|
|
arg.Sort,
|
|
arg.Status,
|
|
arg.UpdateIcon,
|
|
arg.Icon,
|
|
arg.UpdateParentID,
|
|
arg.ParentID,
|
|
arg.ID,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateSysMenuPermissionCode = `-- name: UpdateSysMenuPermissionCode :exec
|
|
UPDATE sys_permissions p
|
|
SET code = coalesce($2, code)
|
|
FROM sys_menu_permission mp
|
|
WHERE p.id = mp.permission_id
|
|
AND mp.menu_id = $1
|
|
`
|
|
|
|
type UpdateSysMenuPermissionCodeParams struct {
|
|
MenuID int32 `json:"menu_id"`
|
|
Code *string `json:"code"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSysMenuPermissionCode(ctx context.Context, arg UpdateSysMenuPermissionCodeParams) error {
|
|
_, err := q.db.Exec(ctx, updateSysMenuPermissionCode, arg.MenuID, arg.Code)
|
|
return err
|
|
}
|