HN-like selfhosted forums

Code git clone ssh://git.poy.ooo:6969/~rii/district ZIP
store/posts.sql.go / 2KiB #af75cd76
Raw
// Code generated by sqlc. DO NOT EDIT.// versions://   sqlc v1.31.1// source: posts.sqlpackage storeimport (	"context"	"time"	"github.com/google/uuid")const getPost = `-- name: GetPost :oneSELECT p.id, p.author_id, p.title, p.embed_url, p.body, p.created_at, p.deleted_at, u.username as author_usernameFROM posts pJOIN users u ON u.id = p.author_idWHERE p.id = $1`type GetPostRow struct {	ID             int64	AuthorID       uuid.UUID	Title          string	EmbedUrl       string	Body           string	CreatedAt      time.Time	DeletedAt      *time.Time	AuthorUsername string}func (q *Queries) GetPost(ctx context.Context, id int64) (GetPostRow, error) {	row := q.db.QueryRow(ctx, getPost, id)	var i GetPostRow	err := row.Scan(		&i.ID,		&i.AuthorID,		&i.Title,		&i.EmbedUrl,		&i.Body,		&i.CreatedAt,		&i.DeletedAt,		&i.AuthorUsername,	)	return i, err}const getPostsByUsername = `-- name: GetPostsByUsername :manySELECT p.id, p.author_id, p.title, p.embed_url, p.body, p.created_at, p.deleted_at, u.username as author_usernameFROM posts pJOIN users u ON u.id = p.author_idWHERE lower(u.username) = lower($1::text)ORDER BY p.created_at DESC`type GetPostsByUsernameRow struct {	ID             int64	AuthorID       uuid.UUID	Title          string	EmbedUrl       string	Body           string	CreatedAt      time.Time	DeletedAt      *time.Time	AuthorUsername string}func (q *Queries) GetPostsByUsername(ctx context.Context, username string) ([]GetPostsByUsernameRow, error) {	rows, err := q.db.Query(ctx, getPostsByUsername, username)	if err != nil {		return nil, err	}	defer rows.Close()	var items []GetPostsByUsernameRow	for rows.Next() {		var i GetPostsByUsernameRow		if err := rows.Scan(			&i.ID,			&i.AuthorID,			&i.Title,			&i.EmbedUrl,			&i.Body,			&i.CreatedAt,			&i.DeletedAt,			&i.AuthorUsername,		); err != nil {			return nil, err		}		items = append(items, i)	}	if err := rows.Err(); err != nil {		return nil, err	}	return items, nil}const newPost = `-- name: NewPost :oneINSERT INTO posts(author_id, title, embed_url, body)VALUES ($1, $2, $3, $4)RETURNING id, author_id, title, embed_url, body, created_at, deleted_at`type NewPostParams struct {	AuthorID uuid.UUID	Title    string	EmbedUrl string	Body     string}func (q *Queries) NewPost(ctx context.Context, arg NewPostParams) (Post, error) {	row := q.db.QueryRow(ctx, newPost,		arg.AuthorID,		arg.Title,		arg.EmbedUrl,		arg.Body,	)	var i Post	err := row.Scan(		&i.ID,		&i.AuthorID,		&i.Title,		&i.EmbedUrl,		&i.Body,		&i.CreatedAt,		&i.DeletedAt,	)	return i, err}