hugo-cms/gen/sqlc/dbq/posts.sql.go

201 lines
4 KiB
Go
Raw Normal View History

2025-01-27 03:23:54 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: posts.sql
package dbq
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
2025-01-31 22:42:32 +00:00
const deletePost = `-- name: DeletePost :exec
DELETE FROM posts WHERE id = $1
`
func (q *Queries) DeletePost(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, deletePost, id)
return err
}
const getPostWithID = `-- name: GetPostWithID :one
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at FROM posts WHERE id = $1 LIMIT 1
`
func (q *Queries) GetPostWithID(ctx context.Context, id int64) (Post, error) {
row := q.db.QueryRow(ctx, getPostWithID, id)
var i Post
err := row.Scan(
&i.ID,
&i.SiteID,
&i.Title,
&i.PostTypeID,
&i.Body,
&i.State,
&i.Props,
2025-02-16 00:43:22 +00:00
&i.PublishDate,
&i.CreatedAt,
2025-02-16 00:43:22 +00:00
&i.UpdatedAt,
)
return i, err
}
2025-01-27 03:23:54 +00:00
const insertPost = `-- name: InsertPost :one
2025-01-31 22:42:32 +00:00
INSERT INTO posts (
2025-01-27 03:23:54 +00:00
site_id,
title,
body,
state,
props,
2025-02-16 00:43:22 +00:00
publish_date,
created_at,
updated_at
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2025-01-27 03:23:54 +00:00
RETURNING id
`
type InsertPostParams struct {
2025-02-16 00:43:22 +00:00
SiteID int64
Title pgtype.Text
Body string
State PostState
Props []byte
PublishDate pgtype.Timestamptz
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
2025-01-27 03:23:54 +00:00
}
func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64, error) {
row := q.db.QueryRow(ctx, insertPost,
arg.SiteID,
arg.Title,
arg.Body,
arg.State,
arg.Props,
2025-02-16 00:43:22 +00:00
arg.PublishDate,
2025-01-27 03:23:54 +00:00
arg.CreatedAt,
2025-02-16 00:43:22 +00:00
arg.UpdatedAt,
2025-01-27 03:23:54 +00:00
)
var id int64
err := row.Scan(&id)
return id, err
}
const listPosts = `-- name: ListPosts :many
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at FROM posts WHERE site_id = $1 ORDER BY publish_date DESC LIMIT 25
2025-01-27 03:23:54 +00:00
`
func (q *Queries) ListPosts(ctx context.Context, siteID int64) ([]Post, error) {
rows, err := q.db.Query(ctx, listPosts, siteID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.Title,
&i.PostTypeID,
2025-01-27 03:23:54 +00:00
&i.Body,
&i.State,
&i.Props,
2025-02-16 00:43:22 +00:00
&i.PublishDate,
2025-01-27 03:23:54 +00:00
&i.CreatedAt,
2025-02-16 00:43:22 +00:00
&i.UpdatedAt,
2025-01-27 03:23:54 +00:00
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
2025-01-27 04:45:53 +00:00
const listPublishablePosts = `-- name: ListPublishablePosts :many
SELECT id, site_id, title, post_type_id, body, state, props, publish_date, created_at, updated_at
2025-01-31 22:42:32 +00:00
FROM posts
2025-02-16 00:43:22 +00:00
WHERE id > $1 AND site_id = $2 AND state = 'published' AND publish_date <= $3
2025-01-27 04:45:53 +00:00
ORDER BY id LIMIT 100
`
type ListPublishablePostsParams struct {
2025-02-16 00:43:22 +00:00
ID int64
SiteID int64
PublishDate pgtype.Timestamptz
2025-01-27 04:45:53 +00:00
}
func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishablePostsParams) ([]Post, error) {
2025-02-16 00:43:22 +00:00
rows, err := q.db.Query(ctx, listPublishablePosts, arg.ID, arg.SiteID, arg.PublishDate)
2025-01-27 04:45:53 +00:00
if err != nil {
return nil, err
}
defer rows.Close()
var items []Post
for rows.Next() {
var i Post
if err := rows.Scan(
&i.ID,
&i.SiteID,
&i.Title,
&i.PostTypeID,
2025-01-27 04:45:53 +00:00
&i.Body,
&i.State,
&i.Props,
2025-02-16 00:43:22 +00:00
&i.PublishDate,
2025-01-27 04:45:53 +00:00
&i.CreatedAt,
2025-02-16 00:43:22 +00:00
&i.UpdatedAt,
2025-01-27 04:45:53 +00:00
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updatePost = `-- name: UpdatePost :exec
2025-01-31 22:42:32 +00:00
UPDATE posts SET
site_id = $2,
title = $3,
body = $4,
state = $5,
props = $6,
2025-02-16 00:43:22 +00:00
publish_date = $7,
updated_at = $8
WHERE id = $1
`
type UpdatePostParams struct {
2025-02-16 00:43:22 +00:00
ID int64
SiteID int64
Title pgtype.Text
Body string
State PostState
Props []byte
PublishDate pgtype.Timestamptz
UpdatedAt pgtype.Timestamp
}
func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) error {
_, err := q.db.Exec(ctx, updatePost,
arg.ID,
arg.SiteID,
arg.Title,
arg.Body,
arg.State,
arg.Props,
2025-02-16 00:43:22 +00:00
arg.PublishDate,
arg.UpdatedAt,
)
return err
}