260 lines
5.5 KiB
Go
260 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: sys_api.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const countSysApis = `-- name: CountSysApis :one
|
|
SELECT COUNT(*)
|
|
FROM sys_apis
|
|
`
|
|
|
|
func (q *Queries) CountSysApis(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countSysApis)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createSysApi = `-- name: CreateSysApi :one
|
|
INSERT INTO sys_apis (name, group_name, method, path, sort)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateSysApiParams struct {
|
|
Name string `json:"name"`
|
|
GroupName string `json:"group_name"`
|
|
Method string `json:"method"`
|
|
Path string `json:"path"`
|
|
Sort *int32 `json:"sort"`
|
|
}
|
|
|
|
func (q *Queries) CreateSysApi(ctx context.Context, arg CreateSysApiParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, createSysApi,
|
|
arg.Name,
|
|
arg.GroupName,
|
|
arg.Method,
|
|
arg.Path,
|
|
arg.Sort,
|
|
)
|
|
var id int32
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const createSysApiPermission = `-- name: CreateSysApiPermission :exec
|
|
INSERT INTO sys_api_permission (api_id, permission_id)
|
|
VALUES ($1, $2)
|
|
`
|
|
|
|
type CreateSysApiPermissionParams struct {
|
|
ApiID int32 `json:"api_id"`
|
|
PermissionID int32 `json:"permission_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateSysApiPermission(ctx context.Context, arg CreateSysApiPermissionParams) error {
|
|
_, err := q.db.Exec(ctx, createSysApiPermission, arg.ApiID, arg.PermissionID)
|
|
return err
|
|
}
|
|
|
|
const deleteSysApi = `-- name: DeleteSysApi :execrows
|
|
DELETE
|
|
FROM sys_apis
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSysApi(ctx context.Context, id int32) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteSysApi, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const deleteSysApiPermission = `-- name: DeleteSysApiPermission :exec
|
|
DELETE
|
|
FROM sys_api_permission
|
|
WHERE api_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSysApiPermission(ctx context.Context, apiID int32) error {
|
|
_, err := q.db.Exec(ctx, deleteSysApiPermission, apiID)
|
|
return err
|
|
}
|
|
|
|
const deleteSysPermissionBySysApiID = `-- name: DeleteSysPermissionBySysApiID :exec
|
|
DELETE
|
|
FROM sys_permissions
|
|
WHERE id IN (SELECT permission_id
|
|
FROM sys_api_permission
|
|
WHERE api_id = $1)
|
|
`
|
|
|
|
func (q *Queries) DeleteSysPermissionBySysApiID(ctx context.Context, apiID int32) error {
|
|
_, err := q.db.Exec(ctx, deleteSysPermissionBySysApiID, apiID)
|
|
return err
|
|
}
|
|
|
|
const getAllSysApis = `-- name: GetAllSysApis :many
|
|
SELECT id, group_name, name, method, path, sort, created_at, updated_at
|
|
FROM sys_apis
|
|
ORDER BY sort ASC
|
|
`
|
|
|
|
func (q *Queries) GetAllSysApis(ctx context.Context) ([]SysApi, error) {
|
|
rows, err := q.db.Query(ctx, getAllSysApis)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []SysApi{}
|
|
for rows.Next() {
|
|
var i SysApi
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.GroupName,
|
|
&i.Name,
|
|
&i.Method,
|
|
&i.Path,
|
|
&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 getSysApiByID = `-- name: GetSysApiByID :one
|
|
SELECT id, group_name, name, method, path, sort, created_at, updated_at
|
|
FROM sys_apis
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetSysApiByID(ctx context.Context, id int32) (SysApi, error) {
|
|
row := q.db.QueryRow(ctx, getSysApiByID, id)
|
|
var i SysApi
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.GroupName,
|
|
&i.Name,
|
|
&i.Method,
|
|
&i.Path,
|
|
&i.Sort,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getSysApiGroupNames = `-- name: GetSysApiGroupNames :many
|
|
SELECT DISTINCT group_name
|
|
FROM sys_apis
|
|
`
|
|
|
|
func (q *Queries) GetSysApiGroupNames(ctx context.Context) ([]string, error) {
|
|
rows, err := q.db.Query(ctx, getSysApiGroupNames)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var group_name string
|
|
if err := rows.Scan(&group_name); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, group_name)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getSysApis = `-- name: GetSysApis :many
|
|
SELECT id, group_name, name, method, path, sort, created_at, updated_at
|
|
FROM sys_apis
|
|
ORDER BY id
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type GetSysApisParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) GetSysApis(ctx context.Context, arg GetSysApisParams) ([]SysApi, error) {
|
|
rows, err := q.db.Query(ctx, getSysApis, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []SysApi{}
|
|
for rows.Next() {
|
|
var i SysApi
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.GroupName,
|
|
&i.Name,
|
|
&i.Method,
|
|
&i.Path,
|
|
&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 updateSysApi = `-- name: UpdateSysApi :execrows
|
|
UPDATE sys_apis
|
|
SET name = $2,
|
|
method = $3,
|
|
path = $4,
|
|
sort = $5,
|
|
group_name = $6
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateSysApiParams struct {
|
|
ID int32 `json:"id"`
|
|
Name string `json:"name"`
|
|
Method string `json:"method"`
|
|
Path string `json:"path"`
|
|
Sort *int32 `json:"sort"`
|
|
GroupName string `json:"group_name"`
|
|
}
|
|
|
|
func (q *Queries) UpdateSysApi(ctx context.Context, arg UpdateSysApiParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, updateSysApi,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.Method,
|
|
arg.Path,
|
|
arg.Sort,
|
|
arg.GroupName,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|