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

84 lines
1.5 KiB
Go

// 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"
)
const insertPost = `-- name: InsertPost :one
INSERT INTO post (
site_id,
title,
body,
state,
props,
post_date,
created_at
) VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id
`
type InsertPostParams struct {
SiteID int64
Title pgtype.Text
Body string
State PostState
Props []byte
PostDate pgtype.Timestamptz
CreatedAt pgtype.Timestamp
}
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,
arg.PostDate,
arg.CreatedAt,
)
var id int64
err := row.Scan(&id)
return id, err
}
const listPosts = `-- name: ListPosts :many
SELECT id, site_id, title, body, state, props, post_date, created_at FROM post WHERE site_id = $1 ORDER BY post_date DESC LIMIT 25
`
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.Body,
&i.State,
&i.Props,
&i.PostDate,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}