385 lines
8.3 KiB
Go
385 lines
8.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: sys_role.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const allSysRole = `-- name: AllSysRole :many
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
WHERE status = 0
|
|
ORDER BY sort DESC
|
|
`
|
|
|
|
func (q *Queries) AllSysRole(ctx context.Context) ([]*SysRole, error) {
|
|
rows, err := q.db.Query(ctx, allSysRole)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*SysRole{}
|
|
for rows.Next() {
|
|
var i SysRole
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&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 countSysRole = `-- name: CountSysRole :one
|
|
SELECT count(*) FROM sys_role
|
|
WHERE status = 0
|
|
`
|
|
|
|
func (q *Queries) CountSysRole(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countSysRole)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const countSysRoleCondition = `-- name: CountSysRoleCondition :one
|
|
SELECT COUNT(*) FROM sys_role
|
|
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 display_name ILIKE '%' || $7 || '%')
|
|
`
|
|
|
|
type CountSysRoleConditionParams struct {
|
|
IsStatus bool `json:"is_status"`
|
|
Status int32 `json:"status"`
|
|
IsID bool `json:"is_id"`
|
|
ID int32 `json:"id"`
|
|
IsParentID bool `json:"is_parent_id"`
|
|
ParentID int32 `json:"parent_id"`
|
|
DisplayName string `json:"display_name"`
|
|
}
|
|
|
|
func (q *Queries) CountSysRoleCondition(ctx context.Context, arg *CountSysRoleConditionParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countSysRoleCondition,
|
|
arg.IsStatus,
|
|
arg.Status,
|
|
arg.IsID,
|
|
arg.ID,
|
|
arg.IsParentID,
|
|
arg.ParentID,
|
|
arg.DisplayName,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createSysRole = `-- name: CreateSysRole :one
|
|
INSERT INTO sys_role (
|
|
name,
|
|
display_name,
|
|
vip,
|
|
parent_id,
|
|
parent_path,
|
|
status,
|
|
sort,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9
|
|
) RETURNING id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at
|
|
`
|
|
|
|
type CreateSysRoleParams struct {
|
|
Name string `json:"name"`
|
|
DisplayName string `json:"display_name"`
|
|
Vip bool `json:"vip"`
|
|
ParentID int32 `json:"parent_id"`
|
|
ParentPath string `json:"parent_path"`
|
|
Status int32 `json:"status"`
|
|
Sort int32 `json:"sort"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateSysRole(ctx context.Context, arg *CreateSysRoleParams) (*SysRole, error) {
|
|
row := q.db.QueryRow(ctx, createSysRole,
|
|
arg.Name,
|
|
arg.DisplayName,
|
|
arg.Vip,
|
|
arg.ParentID,
|
|
arg.ParentPath,
|
|
arg.Status,
|
|
arg.Sort,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
var i SysRole
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const existsVipRole = `-- name: ExistsVipRole :one
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM sys_role
|
|
WHERE vip = true
|
|
)
|
|
`
|
|
|
|
func (q *Queries) ExistsVipRole(ctx context.Context) (bool, error) {
|
|
row := q.db.QueryRow(ctx, existsVipRole)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const getFirstVipRole = `-- name: GetFirstVipRole :one
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
WHERE vip = true
|
|
ORDER BY id ASC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetFirstVipRole(ctx context.Context) (*SysRole, error) {
|
|
row := q.db.QueryRow(ctx, getFirstVipRole)
|
|
var i SysRole
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getSysRole = `-- name: GetSysRole :one
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetSysRole(ctx context.Context, id int32) (*SysRole, error) {
|
|
row := q.db.QueryRow(ctx, getSysRole, id)
|
|
var i SysRole
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getSysRoleByUserID = `-- name: GetSysRoleByUserID :one
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
WHERE id = (SELECT role_id
|
|
FROM sys_user
|
|
WHERE sys_user.id = $1)
|
|
`
|
|
|
|
func (q *Queries) GetSysRoleByUserID(ctx context.Context, id int32) (*SysRole, error) {
|
|
row := q.db.QueryRow(ctx, getSysRoleByUserID, id)
|
|
var i SysRole
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listSysRole = `-- name: ListSysRole :many
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
WHERE status = 0
|
|
`
|
|
|
|
func (q *Queries) ListSysRole(ctx context.Context) ([]*SysRole, error) {
|
|
rows, err := q.db.Query(ctx, listSysRole)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*SysRole{}
|
|
for rows.Next() {
|
|
var i SysRole
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&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 listSysRoleCondition = `-- name: ListSysRoleCondition :many
|
|
SELECT id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at FROM sys_role
|
|
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 display_name ILIKE '%' || $7 || '%')
|
|
ORDER BY created_at DESC
|
|
OFFSET $8
|
|
LIMIT $9
|
|
`
|
|
|
|
type ListSysRoleConditionParams struct {
|
|
IsStatus bool `json:"is_status"`
|
|
Status int32 `json:"status"`
|
|
IsID bool `json:"is_id"`
|
|
ID int32 `json:"id"`
|
|
IsParentID bool `json:"is_parent_id"`
|
|
ParentID int32 `json:"parent_id"`
|
|
DisplayName string `json:"display_name"`
|
|
Skip int32 `json:"skip"`
|
|
Size int32 `json:"size"`
|
|
}
|
|
|
|
func (q *Queries) ListSysRoleCondition(ctx context.Context, arg *ListSysRoleConditionParams) ([]*SysRole, error) {
|
|
rows, err := q.db.Query(ctx, listSysRoleCondition,
|
|
arg.IsStatus,
|
|
arg.Status,
|
|
arg.IsID,
|
|
arg.ID,
|
|
arg.IsParentID,
|
|
arg.ParentID,
|
|
arg.DisplayName,
|
|
arg.Skip,
|
|
arg.Size,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*SysRole{}
|
|
for rows.Next() {
|
|
var i SysRole
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&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 updateSysRole = `-- name: UpdateSysRole :one
|
|
UPDATE sys_role
|
|
SET display_name = $2,
|
|
status = $3,
|
|
parent_id = $4,
|
|
parent_path = $5,
|
|
sort = $6,
|
|
updated_at = $7
|
|
WHERE id = $1
|
|
RETURNING id, name, display_name, parent_id, parent_path, vip, status, sort, created_at, updated_at
|
|
`
|
|
|
|
type UpdateSysRoleParams struct {
|
|
ID int32 `json:"id"`
|
|
DisplayName string `json:"display_name"`
|
|
Status int32 `json:"status"`
|
|
ParentID int32 `json:"parent_id"`
|
|
ParentPath string `json:"parent_path"`
|
|
Sort int32 `json:"sort"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSysRole(ctx context.Context, arg *UpdateSysRoleParams) (*SysRole, error) {
|
|
row := q.db.QueryRow(ctx, updateSysRole,
|
|
arg.ID,
|
|
arg.DisplayName,
|
|
arg.Status,
|
|
arg.ParentID,
|
|
arg.ParentPath,
|
|
arg.Sort,
|
|
arg.UpdatedAt,
|
|
)
|
|
var i SysRole
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.DisplayName,
|
|
&i.ParentID,
|
|
&i.ParentPath,
|
|
&i.Vip,
|
|
&i.Status,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|