Files
blog-server/internal/db/sqlc/sys_apis.sql.go

268 lines
5.6 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: sys_apis.sql
package sqlc
import (
"context"
)
const countApis = `-- name: CountApis :one
SELECT COUNT(*)
FROM sys_apis
WHERE ($1::text = '' OR name ILIKE '%' || $1 || '%')
AND ($2::text = '' OR group_name ILIKE '%' || $2 || '%')
AND ($3::text = '' OR method = $3)
`
type CountApisParams struct {
Name string `json:"name"`
GroupName string `json:"group_name"`
Method string `json:"method"`
}
func (q *Queries) CountApis(ctx context.Context, arg CountApisParams) (int64, error) {
row := q.db.QueryRow(ctx, countApis, arg.Name, arg.GroupName, arg.Method)
var count int64
err := row.Scan(&count)
return count, err
}
const createApi = `-- name: CreateApi :one
INSERT INTO sys_apis (name, group_name, method, path, sort)
VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
type CreateApiParams 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) CreateApi(ctx context.Context, arg CreateApiParams) (int32, error) {
row := q.db.QueryRow(ctx, createApi,
arg.Name,
arg.GroupName,
arg.Method,
arg.Path,
arg.Sort,
)
var id int32
err := row.Scan(&id)
return id, err
}
const createApiPermission = `-- name: CreateApiPermission :exec
INSERT INTO sys_api_permission (api_id, permission_id)
VALUES ($1, $2)
`
type CreateApiPermissionParams struct {
ApiID int32 `json:"api_id"`
PermissionID int32 `json:"permission_id"`
}
func (q *Queries) CreateApiPermission(ctx context.Context, arg CreateApiPermissionParams) error {
_, err := q.db.Exec(ctx, createApiPermission, arg.ApiID, arg.PermissionID)
return err
}
const deleteApi = `-- name: DeleteApi :execrows
DELETE
FROM sys_apis
WHERE id = $1
`
func (q *Queries) DeleteApi(ctx context.Context, id int32) (int64, error) {
result, err := q.db.Exec(ctx, deleteApi, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const deleteApiPermission = `-- name: DeleteApiPermission :exec
DELETE
FROM sys_api_permission
WHERE api_id = $1
`
func (q *Queries) DeleteApiPermission(ctx context.Context, apiID int32) error {
_, err := q.db.Exec(ctx, deleteApiPermission, apiID)
return err
}
const getApiByID = `-- name: GetApiByID :one
SELECT id, group_name, name, method, path, sort, created_at, updated_at
FROM sys_apis
WHERE id = $1
`
func (q *Queries) GetApiByID(ctx context.Context, id int32) (SysApi, error) {
row := q.db.QueryRow(ctx, getApiByID, 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 listAllApis = `-- name: ListAllApis :many
SELECT id, group_name, name, method, path, sort, created_at, updated_at
FROM sys_apis
ORDER BY sort ASC
`
func (q *Queries) ListAllApis(ctx context.Context) ([]SysApi, error) {
rows, err := q.db.Query(ctx, listAllApis)
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 listApiGroups = `-- name: ListApiGroups :many
SELECT DISTINCT group_name
FROM sys_apis
`
func (q *Queries) ListApiGroups(ctx context.Context) ([]string, error) {
rows, err := q.db.Query(ctx, listApiGroups)
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 listApis = `-- name: ListApis :many
SELECT id, group_name, name, method, path, sort, created_at, updated_at
FROM sys_apis
WHERE ($3::text = '' OR name ILIKE '%' || $3 || '%')
AND ($4::text = '' OR group_name ILIKE '%' || $4 || '%')
AND ($5::text = '' OR method = $5)
ORDER BY id
LIMIT $1 OFFSET $2
`
type ListApisParams struct {
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
Name string `json:"name"`
GroupName string `json:"group_name"`
Method string `json:"method"`
}
func (q *Queries) ListApis(ctx context.Context, arg ListApisParams) ([]SysApi, error) {
rows, err := q.db.Query(ctx, listApis,
arg.Limit,
arg.Offset,
arg.Name,
arg.GroupName,
arg.Method,
)
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 updateApi = `-- name: UpdateApi :execrows
UPDATE sys_apis
SET name = $2,
method = $3,
path = $4,
sort = $5,
group_name = $6
WHERE id = $1
`
type UpdateApiParams 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) UpdateApi(ctx context.Context, arg UpdateApiParams) (int64, error) {
result, err := q.db.Exec(ctx, updateApi,
arg.ID,
arg.Name,
arg.Method,
arg.Path,
arg.Sort,
arg.GroupName,
)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}