feat: 统一sql命名、函数命名
This commit is contained in:
@@ -9,32 +9,34 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const countSysApis = `-- name: CountSysApis :one
|
||||
const countApis = `-- name: CountApis :one
|
||||
SELECT COUNT(*)
|
||||
FROM sys_apis
|
||||
WHERE ($1::text = '' OR group_name ILIKE '%' || $1 || '%')
|
||||
AND ($2::text = '' OR method = $2)
|
||||
WHERE ($1::text = '' OR name ILIKE '%' || $1 || '%')
|
||||
AND ($2::text = '' OR group_name ILIKE '%' || $2 || '%')
|
||||
AND ($3::text = '' OR method = $3)
|
||||
`
|
||||
|
||||
type CountSysApisParams struct {
|
||||
type CountApisParams struct {
|
||||
Name string `json:"name"`
|
||||
GroupName string `json:"group_name"`
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountSysApis(ctx context.Context, arg CountSysApisParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countSysApis, arg.GroupName, arg.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 createSysApi = `-- name: CreateSysApi :one
|
||||
const createApi = `-- name: CreateApi :one
|
||||
INSERT INTO sys_apis (name, group_name, method, path, sort)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type CreateSysApiParams struct {
|
||||
type CreateApiParams struct {
|
||||
Name string `json:"name"`
|
||||
GroupName string `json:"group_name"`
|
||||
Method string `json:"method"`
|
||||
@@ -42,8 +44,8 @@ type CreateSysApiParams struct {
|
||||
Sort *int32 `json:"sort"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateSysApi(ctx context.Context, arg CreateSysApiParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, createSysApi,
|
||||
func (q *Queries) CreateApi(ctx context.Context, arg CreateApiParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, createApi,
|
||||
arg.Name,
|
||||
arg.GroupName,
|
||||
arg.Method,
|
||||
@@ -55,54 +57,76 @@ func (q *Queries) CreateSysApi(ctx context.Context, arg CreateSysApiParams) (int
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createSysApiPermission = `-- name: CreateSysApiPermission :exec
|
||||
const createApiPermission = `-- name: CreateApiPermission :exec
|
||||
INSERT INTO sys_api_permission (api_id, permission_id)
|
||||
VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type CreateSysApiPermissionParams struct {
|
||||
type CreateApiPermissionParams 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)
|
||||
func (q *Queries) CreateApiPermission(ctx context.Context, arg CreateApiPermissionParams) error {
|
||||
_, err := q.db.Exec(ctx, createApiPermission, arg.ApiID, arg.PermissionID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteSysApi = `-- name: DeleteSysApi :execrows
|
||||
const deleteApi = `-- name: DeleteApi :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)
|
||||
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 deleteSysApiPermission = `-- name: DeleteSysApiPermission :exec
|
||||
const deleteApiPermission = `-- name: DeleteApiPermission :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)
|
||||
func (q *Queries) DeleteApiPermission(ctx context.Context, apiID int32) error {
|
||||
_, err := q.db.Exec(ctx, deleteApiPermission, apiID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllSysApis = `-- name: GetAllSysApis :many
|
||||
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) GetAllSysApis(ctx context.Context) ([]SysApi, error) {
|
||||
rows, err := q.db.Query(ctx, getAllSysApis)
|
||||
func (q *Queries) ListAllApis(ctx context.Context) ([]SysApi, error) {
|
||||
rows, err := q.db.Query(ctx, listAllApis)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,35 +154,13 @@ func (q *Queries) GetAllSysApis(ctx context.Context) ([]SysApi, error) {
|
||||
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
|
||||
const listApiGroups = `-- name: ListApiGroups :many
|
||||
SELECT DISTINCT group_name
|
||||
FROM sys_apis
|
||||
`
|
||||
|
||||
func (q *Queries) GetSysApiGroupNames(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, getSysApiGroupNames)
|
||||
func (q *Queries) ListApiGroups(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, listApiGroups)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -177,26 +179,29 @@ func (q *Queries) GetSysApiGroupNames(ctx context.Context) ([]string, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getSysApis = `-- name: GetSysApis :many
|
||||
const listApis = `-- name: ListApis :many
|
||||
SELECT id, group_name, name, method, path, sort, created_at, updated_at
|
||||
FROM sys_apis
|
||||
WHERE ($3::text = '' OR group_name ILIKE '%' || $3 || '%')
|
||||
AND ($4::text = '' OR method = $4)
|
||||
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 GetSysApisParams struct {
|
||||
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) GetSysApis(ctx context.Context, arg GetSysApisParams) ([]SysApi, error) {
|
||||
rows, err := q.db.Query(ctx, getSysApis,
|
||||
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,
|
||||
)
|
||||
@@ -227,7 +232,7 @@ func (q *Queries) GetSysApis(ctx context.Context, arg GetSysApisParams) ([]SysAp
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateSysApi = `-- name: UpdateSysApi :execrows
|
||||
const updateApi = `-- name: UpdateApi :execrows
|
||||
UPDATE sys_apis
|
||||
SET name = $2,
|
||||
method = $3,
|
||||
@@ -237,7 +242,7 @@ SET name = $2,
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdateSysApiParams struct {
|
||||
type UpdateApiParams struct {
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Method string `json:"method"`
|
||||
@@ -246,8 +251,8 @@ type UpdateSysApiParams struct {
|
||||
GroupName string `json:"group_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSysApi(ctx context.Context, arg UpdateSysApiParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateSysApi,
|
||||
func (q *Queries) UpdateApi(ctx context.Context, arg UpdateApiParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateApi,
|
||||
arg.ID,
|
||||
arg.Name,
|
||||
arg.Method,
|
||||
|
||||
Reference in New Issue
Block a user