// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: threads.sql package notifdb import ( "context" ) const deleteNotificationThread = `-- name: DeleteNotificationThread :exec DELETE FROM notification_threads WHERE recipient_user_id = $1 AND thread_kind = $2 AND thread_id = $3 ` type DeleteNotificationThreadParams struct { RecipientUserID int64 ThreadKind NotificationThreadKind ThreadID int64 } func (q *Queries) DeleteNotificationThread(ctx context.Context, db DBTX, arg DeleteNotificationThreadParams) error { _, err := db.Exec(ctx, deleteNotificationThread, arg.RecipientUserID, arg.ThreadKind, arg.ThreadID) return err } const getNotificationThread = `-- name: GetNotificationThread :one SELECT recipient_user_id, thread_kind, thread_id, subscribed, reason, updated_at FROM notification_threads WHERE recipient_user_id = $1 AND thread_kind = $2 AND thread_id = $3 ` type GetNotificationThreadParams struct { RecipientUserID int64 ThreadKind NotificationThreadKind ThreadID int64 } // ─── notification_threads ────────────────────────────────────────── func (q *Queries) GetNotificationThread(ctx context.Context, db DBTX, arg GetNotificationThreadParams) (NotificationThread, error) { row := db.QueryRow(ctx, getNotificationThread, arg.RecipientUserID, arg.ThreadKind, arg.ThreadID) var i NotificationThread err := row.Scan( &i.RecipientUserID, &i.ThreadKind, &i.ThreadID, &i.Subscribed, &i.Reason, &i.UpdatedAt, ) return i, err } const insertNotificationThreadIfAbsent = `-- name: InsertNotificationThreadIfAbsent :exec INSERT INTO notification_threads (recipient_user_id, thread_kind, thread_id, subscribed, reason) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (recipient_user_id, thread_kind, thread_id) DO NOTHING ` type InsertNotificationThreadIfAbsentParams struct { RecipientUserID int64 ThreadKind NotificationThreadKind ThreadID int64 Subscribed bool Reason string } // Auto-subscription path: only insert if the user has no explicit // preference yet. Preserves user choices (e.g. an explicit // `subscribed=false` from clicking "Unsubscribe"). func (q *Queries) InsertNotificationThreadIfAbsent(ctx context.Context, db DBTX, arg InsertNotificationThreadIfAbsentParams) error { _, err := db.Exec(ctx, insertNotificationThreadIfAbsent, arg.RecipientUserID, arg.ThreadKind, arg.ThreadID, arg.Subscribed, arg.Reason, ) return err } const listSubscribersForThread = `-- name: ListSubscribersForThread :many SELECT recipient_user_id, reason FROM notification_threads WHERE thread_kind = $1 AND thread_id = $2 AND subscribed = true ` type ListSubscribersForThreadParams struct { ThreadKind NotificationThreadKind ThreadID int64 } type ListSubscribersForThreadRow struct { RecipientUserID int64 Reason string } // Fan-out helper: returns recipients who explicitly subscribed to a // thread. The fan-out worker unions this with the per-repo `watches` // result + author/assignee/reviewer rules. func (q *Queries) ListSubscribersForThread(ctx context.Context, db DBTX, arg ListSubscribersForThreadParams) ([]ListSubscribersForThreadRow, error) { rows, err := db.Query(ctx, listSubscribersForThread, arg.ThreadKind, arg.ThreadID) if err != nil { return nil, err } defer rows.Close() items := []ListSubscribersForThreadRow{} for rows.Next() { var i ListSubscribersForThreadRow if err := rows.Scan(&i.RecipientUserID, &i.Reason); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const upsertNotificationThread = `-- name: UpsertNotificationThread :exec INSERT INTO notification_threads (recipient_user_id, thread_kind, thread_id, subscribed, reason) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (recipient_user_id, thread_kind, thread_id) DO UPDATE SET subscribed = EXCLUDED.subscribed, reason = EXCLUDED.reason, updated_at = now() ` type UpsertNotificationThreadParams struct { RecipientUserID int64 ThreadKind NotificationThreadKind ThreadID int64 Subscribed bool Reason string } // Always-write upsert. Used by Subscribe / Unsubscribe / Ignore // handlers and by the auto-subscription rules in the fan-out // worker. func (q *Queries) UpsertNotificationThread(ctx context.Context, db DBTX, arg UpsertNotificationThreadParams) error { _, err := db.Exec(ctx, upsertNotificationThread, arg.RecipientUserID, arg.ThreadKind, arg.ThreadID, arg.Subscribed, arg.Reason, ) return err }