mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-08 09:26:50 +08:00
* feat(issues): add revision-aware concurrency guards * fix(concurrency): decouple text edits from aggregate revisions
152 lines
4.2 KiB
Go
152 lines
4.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: issue_reaction.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const addIssueReaction = `-- name: AddIssueReaction :one
|
|
WITH inserted AS (
|
|
INSERT INTO issue_reaction (issue_id, workspace_id, actor_type, actor_id, emoji)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
ON CONFLICT (issue_id, actor_type, actor_id, emoji) DO NOTHING
|
|
RETURNING id, issue_id, workspace_id, actor_type, actor_id, emoji, created_at
|
|
), bumped AS (
|
|
UPDATE issue
|
|
SET revision = revision + 1
|
|
WHERE id IN (SELECT issue_id FROM inserted)
|
|
RETURNING revision
|
|
)
|
|
SELECT reaction.id, reaction.issue_id, reaction.workspace_id, reaction.actor_type, reaction.actor_id, reaction.emoji, reaction.created_at, COALESCE((SELECT revision FROM bumped), 0)::bigint AS issue_revision
|
|
FROM inserted reaction
|
|
UNION ALL
|
|
SELECT reaction.id, reaction.issue_id, reaction.workspace_id, reaction.actor_type, reaction.actor_id, reaction.emoji, reaction.created_at, 0::bigint AS issue_revision
|
|
FROM issue_reaction reaction
|
|
WHERE reaction.issue_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 AddIssueReactionParams struct {
|
|
IssueID pgtype.UUID `json:"issue_id"`
|
|
WorkspaceID pgtype.UUID `json:"workspace_id"`
|
|
ActorType string `json:"actor_type"`
|
|
ActorID pgtype.UUID `json:"actor_id"`
|
|
Emoji string `json:"emoji"`
|
|
}
|
|
|
|
type AddIssueReactionRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
IssueID pgtype.UUID `json:"issue_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"`
|
|
IssueRevision int64 `json:"issue_revision"`
|
|
}
|
|
|
|
func (q *Queries) AddIssueReaction(ctx context.Context, arg AddIssueReactionParams) (AddIssueReactionRow, error) {
|
|
row := q.db.QueryRow(ctx, addIssueReaction,
|
|
arg.IssueID,
|
|
arg.WorkspaceID,
|
|
arg.ActorType,
|
|
arg.ActorID,
|
|
arg.Emoji,
|
|
)
|
|
var i AddIssueReactionRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.IssueID,
|
|
&i.WorkspaceID,
|
|
&i.ActorType,
|
|
&i.ActorID,
|
|
&i.Emoji,
|
|
&i.CreatedAt,
|
|
&i.IssueRevision,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listIssueReactions = `-- name: ListIssueReactions :many
|
|
SELECT id, issue_id, workspace_id, actor_type, actor_id, emoji, created_at FROM issue_reaction
|
|
WHERE issue_id = $1
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListIssueReactions(ctx context.Context, issueID pgtype.UUID) ([]IssueReaction, error) {
|
|
rows, err := q.db.Query(ctx, listIssueReactions, issueID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []IssueReaction{}
|
|
for rows.Next() {
|
|
var i IssueReaction
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.IssueID,
|
|
&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 removeIssueReaction = `-- name: RemoveIssueReaction :one
|
|
WITH deleted AS (
|
|
DELETE FROM issue_reaction
|
|
WHERE issue_id = $1 AND actor_type = $2 AND actor_id = $3 AND emoji = $4
|
|
RETURNING issue_id
|
|
), bumped AS (
|
|
UPDATE issue
|
|
SET revision = revision + 1
|
|
WHERE id IN (SELECT issue_id FROM deleted)
|
|
RETURNING revision
|
|
)
|
|
SELECT EXISTS(SELECT 1 FROM deleted) AS changed,
|
|
COALESCE((SELECT revision FROM bumped), 0)::bigint AS issue_revision
|
|
`
|
|
|
|
type RemoveIssueReactionParams struct {
|
|
IssueID pgtype.UUID `json:"issue_id"`
|
|
ActorType string `json:"actor_type"`
|
|
ActorID pgtype.UUID `json:"actor_id"`
|
|
Emoji string `json:"emoji"`
|
|
}
|
|
|
|
type RemoveIssueReactionRow struct {
|
|
Changed bool `json:"changed"`
|
|
IssueRevision int64 `json:"issue_revision"`
|
|
}
|
|
|
|
func (q *Queries) RemoveIssueReaction(ctx context.Context, arg RemoveIssueReactionParams) (RemoveIssueReactionRow, error) {
|
|
row := q.db.QueryRow(ctx, removeIssueReaction,
|
|
arg.IssueID,
|
|
arg.ActorType,
|
|
arg.ActorID,
|
|
arg.Emoji,
|
|
)
|
|
var i RemoveIssueReactionRow
|
|
err := row.Scan(&i.Changed, &i.IssueRevision)
|
|
return i, err
|
|
}
|