feat: 统一sql命名、函数命名

This commit is contained in:
2026-08-02 12:02:04 +08:00
parent d39342ce5f
commit 0e674e9d56
68 changed files with 1985 additions and 1720 deletions

View File

@@ -22,8 +22,9 @@ func (q *Queries) CountFiles(ctx context.Context) (int64, error) {
}
const createFile = `-- name: CreateFile :one
INSERT INTO files(file_name, file_path, original_name, folder_name, mime_type, file_size)
VALUES ($1, $2, $3, $4, $5, $6) RETURNING id,file_path,file_name
INSERT INTO files(file_name, file_path, original_name, folder_name, mime_type, file_size, file_url)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id,file_url,file_name
`
type CreateFileParams struct {
@@ -33,11 +34,12 @@ type CreateFileParams struct {
FolderName string `json:"folder_name"`
MimeType string `json:"mime_type"`
FileSize int64 `json:"file_size"`
FileUrl string `json:"file_url"`
}
type CreateFileRow struct {
ID int32 `json:"id"`
FilePath string `json:"file_path"`
FileUrl string `json:"file_url"`
FileName string `json:"file_name"`
}
@@ -49,26 +51,27 @@ func (q *Queries) CreateFile(ctx context.Context, arg CreateFileParams) (CreateF
arg.FolderName,
arg.MimeType,
arg.FileSize,
arg.FileUrl,
)
var i CreateFileRow
err := row.Scan(&i.ID, &i.FilePath, &i.FileName)
err := row.Scan(&i.ID, &i.FileUrl, &i.FileName)
return i, err
}
const getFiles = `-- name: GetFiles :many
SELECT id, file_name, file_path, original_name, folder_name, mime_type, file_size, created_at, updated_at
const listFiles = `-- name: ListFiles :many
SELECT id, file_name, file_path, file_url, original_name, folder_name, mime_type, file_size, created_at, updated_at
FROM files
ORDER BY id LIMIT $1
OFFSET $2
ORDER BY id
LIMIT $1 OFFSET $2
`
type GetFilesParams struct {
type ListFilesParams struct {
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
func (q *Queries) GetFiles(ctx context.Context, arg GetFilesParams) ([]File, error) {
rows, err := q.db.Query(ctx, getFiles, arg.Limit, arg.Offset)
func (q *Queries) ListFiles(ctx context.Context, arg ListFilesParams) ([]File, error) {
rows, err := q.db.Query(ctx, listFiles, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
@@ -80,6 +83,7 @@ func (q *Queries) GetFiles(ctx context.Context, arg GetFilesParams) ([]File, err
&i.ID,
&i.FileName,
&i.FilePath,
&i.FileUrl,
&i.OriginalName,
&i.FolderName,
&i.MimeType,