// 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 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, body, state, props, post_date, created_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.Body, &i.State, &i.Props, &i.PostDate, &i.CreatedAt, ) return i, err } const insertPost = `-- name: InsertPost :one INSERT INTO posts ( 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 posts 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 } const listPublishablePosts = `-- name: ListPublishablePosts :many SELECT id, site_id, title, body, state, props, post_date, created_at FROM posts WHERE id > $1 AND site_id = $2 AND state = 'published' AND post_date <= $3 ORDER BY id LIMIT 100 ` type ListPublishablePostsParams struct { ID int64 SiteID int64 PostDate pgtype.Timestamptz } func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishablePostsParams) ([]Post, error) { rows, err := q.db.Query(ctx, listPublishablePosts, arg.ID, arg.SiteID, arg.PostDate) 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 } const updatePost = `-- name: UpdatePost :exec UPDATE posts SET site_id = $2, title = $3, body = $4, state = $5, props = $6, post_date = $7 -- updated_at = $7 WHERE id = $1 ` type UpdatePostParams struct { ID int64 SiteID int64 Title pgtype.Text Body string State PostState Props []byte PostDate pgtype.Timestamptz } 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, arg.PostDate, ) return err }