// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: reaction.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const addReaction = `-- name: AddReaction :one WITH inserted AS ( INSERT INTO comment_reaction (comment_id, workspace_id, actor_type, actor_id, emoji) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (comment_id, actor_type, actor_id, emoji) DO NOTHING RETURNING id, comment_id, workspace_id, actor_type, actor_id, emoji, created_at ), bumped AS ( UPDATE comment SET revision = revision + 1 WHERE id IN (SELECT comment_id FROM inserted) RETURNING revision ) SELECT reaction.id, reaction.comment_id, reaction.workspace_id, reaction.actor_type, reaction.actor_id, reaction.emoji, reaction.created_at, COALESCE((SELECT revision FROM bumped), 0)::bigint AS comment_revision FROM inserted reaction UNION ALL SELECT reaction.id, reaction.comment_id, reaction.workspace_id, reaction.actor_type, reaction.actor_id, reaction.emoji, reaction.created_at, 0::bigint AS comment_revision FROM comment_reaction reaction WHERE reaction.comment_id = $1 AND reaction.actor_type = $3 AND reaction.actor_id = $4 AND reaction.emoji = $5 AND NOT EXISTS (SELECT 1 FROM inserted) LIMIT 1 ` type AddReactionParams struct { CommentID pgtype.UUID `json:"comment_id"` WorkspaceID pgtype.UUID `json:"workspace_id"` ActorType string `json:"actor_type"` ActorID pgtype.UUID `json:"actor_id"` Emoji string `json:"emoji"` } type AddReactionRow struct { ID pgtype.UUID `json:"id"` CommentID pgtype.UUID `json:"comment_id"` WorkspaceID pgtype.UUID `json:"workspace_id"` ActorType string `json:"actor_type"` ActorID pgtype.UUID `json:"actor_id"` Emoji string `json:"emoji"` CreatedAt pgtype.Timestamptz `json:"created_at"` CommentRevision int64 `json:"comment_revision"` } func (q *Queries) AddReaction(ctx context.Context, arg AddReactionParams) (AddReactionRow, error) { row := q.db.QueryRow(ctx, addReaction, arg.CommentID, arg.WorkspaceID, arg.ActorType, arg.ActorID, arg.Emoji, ) var i AddReactionRow err := row.Scan( &i.ID, &i.CommentID, &i.WorkspaceID, &i.ActorType, &i.ActorID, &i.Emoji, &i.CreatedAt, &i.CommentRevision, ) return i, err } const deleteCommentReactions = `-- name: DeleteCommentReactions :exec DELETE FROM comment_reaction WHERE comment_id = $1 AND workspace_id = $2 ` type DeleteCommentReactionsParams struct { CommentID pgtype.UUID `json:"comment_id"` WorkspaceID pgtype.UUID `json:"workspace_id"` } // Part of the comment delete transaction: reactions go with the comment. func (q *Queries) DeleteCommentReactions(ctx context.Context, arg DeleteCommentReactionsParams) error { _, err := q.db.Exec(ctx, deleteCommentReactions, arg.CommentID, arg.WorkspaceID) return err } const listReactionsByCommentIDs = `-- name: ListReactionsByCommentIDs :many SELECT id, comment_id, workspace_id, actor_type, actor_id, emoji, created_at FROM comment_reaction WHERE comment_id = ANY($1::uuid[]) ORDER BY created_at ASC ` func (q *Queries) ListReactionsByCommentIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]CommentReaction, error) { rows, err := q.db.Query(ctx, listReactionsByCommentIDs, dollar_1) if err != nil { return nil, err } defer rows.Close() items := []CommentReaction{} for rows.Next() { var i CommentReaction if err := rows.Scan( &i.ID, &i.CommentID, &i.WorkspaceID, &i.ActorType, &i.ActorID, &i.Emoji, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const removeReaction = `-- name: RemoveReaction :one WITH deleted AS ( DELETE FROM comment_reaction WHERE comment_id = $1 AND actor_type = $2 AND actor_id = $3 AND emoji = $4 RETURNING comment_id ), bumped AS ( UPDATE comment SET revision = revision + 1 WHERE id IN (SELECT comment_id FROM deleted) RETURNING revision ) SELECT EXISTS(SELECT 1 FROM deleted) AS changed, COALESCE((SELECT revision FROM bumped), 0)::bigint AS comment_revision ` type RemoveReactionParams struct { CommentID pgtype.UUID `json:"comment_id"` ActorType string `json:"actor_type"` ActorID pgtype.UUID `json:"actor_id"` Emoji string `json:"emoji"` } type RemoveReactionRow struct { Changed bool `json:"changed"` CommentRevision int64 `json:"comment_revision"` } func (q *Queries) RemoveReaction(ctx context.Context, arg RemoveReactionParams) (RemoveReactionRow, error) { row := q.db.QueryRow(ctx, removeReaction, arg.CommentID, arg.ActorType, arg.ActorID, arg.Emoji, ) var i RemoveReactionRow err := row.Scan(&i.Changed, &i.CommentRevision) return i, err }