// 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, 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, &i.PublishDate, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const insertPost = `-- name: InsertPost :one INSERT INTO posts ( site_id, title, body, state, props, publish_date, created_at, updated_at ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id ` type InsertPostParams struct { SiteID int64 Title pgtype.Text Body string State PostState Props []byte PublishDate pgtype.Timestamptz CreatedAt pgtype.Timestamp UpdatedAt 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.PublishDate, arg.CreatedAt, arg.UpdatedAt, ) 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 ` 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, &i.Body, &i.State, &i.Props, &i.PublishDate, &i.CreatedAt, &i.UpdatedAt, ); 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, post_type_id, body, state, props, publish_date, created_at, updated_at FROM posts WHERE id > $1 AND site_id = $2 AND state = 'published' AND publish_date <= $3 ORDER BY id LIMIT 100 ` type ListPublishablePostsParams struct { ID int64 SiteID int64 PublishDate 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.PublishDate) 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, &i.Body, &i.State, &i.Props, &i.PublishDate, &i.CreatedAt, &i.UpdatedAt, ); 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, publish_date = $7, updated_at = $8 WHERE id = $1 ` type UpdatePostParams struct { 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, arg.PublishDate, arg.UpdatedAt, ) return err }