feat: 统一sql命名、函数命名
This commit is contained in:
@@ -83,9 +83,9 @@ func (q *Queries) DeletePost(ctx context.Context, id int32) (int64, error) {
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const getPostById = `-- name: GetPostById :one
|
||||
const getPostByID = `-- name: GetPostByID :one
|
||||
SELECT p.id, p.title, p.cover_id, p.slug, p.content, p.summary, p.status, p.sort, p.published_at, p.created_at, p.updated_at,
|
||||
f.file_path AS cover,
|
||||
f.file_url AS cover,
|
||||
c.name AS category_name,
|
||||
c.id AS category_id,
|
||||
COALESCE(
|
||||
@@ -99,13 +99,13 @@ FROM posts p
|
||||
LEFT JOIN post_tag pt ON pt.post_id = p.id
|
||||
WHERE p.id = $1
|
||||
GROUP BY p.id,
|
||||
f.file_path,
|
||||
f.file_url,
|
||||
c.name,
|
||||
c.id
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetPostByIdRow struct {
|
||||
type GetPostByIDRow struct {
|
||||
ID int32 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
CoverID *int32 `json:"cover_id"`
|
||||
@@ -123,9 +123,9 @@ type GetPostByIdRow struct {
|
||||
Tags interface{} `json:"tags"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPostById(ctx context.Context, id int32) (GetPostByIdRow, error) {
|
||||
row := q.db.QueryRow(ctx, getPostById, id)
|
||||
var i GetPostByIdRow
|
||||
func (q *Queries) GetPostByID(ctx context.Context, id int32) (GetPostByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getPostByID, id)
|
||||
var i GetPostByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
@@ -149,7 +149,7 @@ func (q *Queries) GetPostById(ctx context.Context, id int32) (GetPostByIdRow, er
|
||||
const getPublicPostBySlug = `-- name: GetPublicPostBySlug :one
|
||||
|
||||
SELECT p.id, p.title, p.cover_id, p.slug, p.content, p.summary, p.status, p.sort, p.published_at, p.created_at, p.updated_at,
|
||||
f.file_path AS cover,
|
||||
f.file_url AS cover,
|
||||
COALESCE(ps.view, 0) AS view
|
||||
FROM posts p
|
||||
LEFT JOIN files f ON f.id = p.cover_id
|
||||
@@ -312,7 +312,7 @@ WITH paginated_posts AS (
|
||||
LIMIT $1 OFFSET $2
|
||||
)
|
||||
SELECT p.id, p.title, p.cover_id, p.slug, p.summary, p.status, p.sort, p.published_at, p.created_at, p.updated_at,
|
||||
f.file_path AS cover,
|
||||
f.file_url AS cover,
|
||||
c.name AS category_name,
|
||||
c.id AS category_id,
|
||||
COALESCE(ps.view, 0) AS view,
|
||||
@@ -344,7 +344,7 @@ GROUP BY p.id,
|
||||
p.published_at,
|
||||
p.created_at,
|
||||
p.updated_at,
|
||||
f.file_path,
|
||||
f.file_url,
|
||||
c.name,
|
||||
c.id,
|
||||
ps.view
|
||||
@@ -427,7 +427,7 @@ WITH paginated_posts AS (
|
||||
ORDER BY sort DESC, published_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2)
|
||||
SELECT p.id, p.title, p.cover_id, p.slug, p.summary, p.sort, p.published_at,
|
||||
f.file_path AS cover,
|
||||
f.file_url AS cover,
|
||||
c.name AS category_name,
|
||||
c.id AS category_id,
|
||||
COALESCE(ps.view, 0) AS view,
|
||||
@@ -456,7 +456,7 @@ GROUP BY p.id,
|
||||
p.summary,
|
||||
p.sort,
|
||||
p.published_at,
|
||||
f.file_path,
|
||||
f.file_url,
|
||||
c.name,
|
||||
c.id,
|
||||
ps.view
|
||||
|
||||
Reference in New Issue
Block a user