notifications.sql.go116 lines, 2.5 KB
| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: notifications.sql |
| 5 | |
| 6 | package notificationdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/google/uuid" |
| 12 | ) |
| 13 | |
| 14 | const insertDeadLetter = `-- name: InsertDeadLetter :exec |
| 15 | INSERT INTO dead_letters (stream, seq, subject, payload, error, deliveries) |
| 16 | VALUES ($1, $2, $3, $4, $5, $6) |
| 17 | ON CONFLICT (stream, seq) DO NOTHING |
| 18 | ` |
| 19 | |
| 20 | type InsertDeadLetterParams struct { |
| 21 | Stream string |
| 22 | Seq int64 |
| 23 | Subject string |
| 24 | Payload []byte |
| 25 | Error string |
| 26 | Deliveries int32 |
| 27 | } |
| 28 | |
| 29 | func (q *Queries) InsertDeadLetter(ctx context.Context, arg InsertDeadLetterParams) error { |
| 30 | _, err := q.db.Exec(ctx, insertDeadLetter, |
| 31 | arg.Stream, |
| 32 | arg.Seq, |
| 33 | arg.Subject, |
| 34 | arg.Payload, |
| 35 | arg.Error, |
| 36 | arg.Deliveries, |
| 37 | ) |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | const insertNotification = `-- name: InsertNotification :execrows |
| 42 | INSERT INTO notifications (event_id, user_id, recipient, subject) |
| 43 | VALUES ($1, $2, $3, $4) |
| 44 | ON CONFLICT (event_id) DO NOTHING |
| 45 | ` |
| 46 | |
| 47 | type InsertNotificationParams struct { |
| 48 | EventID uuid.UUID |
| 49 | UserID uuid.UUID |
| 50 | Recipient string |
| 51 | Subject string |
| 52 | } |
| 53 | |
| 54 | // Inserts nothing, and returns 0, when the event was handled before. |
| 55 | func (q *Queries) InsertNotification(ctx context.Context, arg InsertNotificationParams) (int64, error) { |
| 56 | result, err := q.db.Exec(ctx, insertNotification, |
| 57 | arg.EventID, |
| 58 | arg.UserID, |
| 59 | arg.Recipient, |
| 60 | arg.Subject, |
| 61 | ) |
| 62 | if err != nil { |
| 63 | return 0, err |
| 64 | } |
| 65 | return result.RowsAffected(), nil |
| 66 | } |
| 67 | |
| 68 | const listDeadLetters = `-- name: ListDeadLetters :many |
| 69 | SELECT stream, seq, subject, payload, error, deliveries, failed_at, replayed_at FROM dead_letters |
| 70 | WHERE replayed_at IS NULL |
| 71 | ORDER BY failed_at |
| 72 | ` |
| 73 | |
| 74 | func (q *Queries) ListDeadLetters(ctx context.Context) ([]DeadLetter, error) { |
| 75 | rows, err := q.db.Query(ctx, listDeadLetters) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | defer rows.Close() |
| 80 | var items []DeadLetter |
| 81 | for rows.Next() { |
| 82 | var i DeadLetter |
| 83 | if err := rows.Scan( |
| 84 | &i.Stream, |
| 85 | &i.Seq, |
| 86 | &i.Subject, |
| 87 | &i.Payload, |
| 88 | &i.Error, |
| 89 | &i.Deliveries, |
| 90 | &i.FailedAt, |
| 91 | &i.ReplayedAt, |
| 92 | ); err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | items = append(items, i) |
| 96 | } |
| 97 | if err := rows.Err(); err != nil { |
| 98 | return nil, err |
| 99 | } |
| 100 | return items, nil |
| 101 | } |
| 102 | |
| 103 | const markReplayed = `-- name: MarkReplayed :exec |
| 104 | UPDATE dead_letters SET replayed_at = now() |
| 105 | WHERE stream = $1 AND seq = $2 |
| 106 | ` |
| 107 | |
| 108 | type MarkReplayedParams struct { |
| 109 | Stream string |
| 110 | Seq int64 |
| 111 | } |
| 112 | |
| 113 | func (q *Queries) MarkReplayed(ctx context.Context, arg MarkReplayedParams) error { |
| 114 | _, err := q.db.Exec(ctx, markReplayed, arg.Stream, arg.Seq) |
| 115 | return err |
| 116 | } |