-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconciler_errors.sql.go
83 lines (72 loc) · 2.14 KB
/
reconciler_errors.sql.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Code generated by sqlc. DO NOT EDIT.
// source: reconciler_errors.sql
package gensql
import (
"context"
"github.com/google/uuid"
"github.com/nais/api/internal/slug"
)
const clearReconcilerErrorsForTeam = `-- name: ClearReconcilerErrorsForTeam :exec
DELETE FROM reconciler_errors
WHERE team_slug = $1 AND reconciler = $2
`
type ClearReconcilerErrorsForTeamParams struct {
TeamSlug slug.Slug
Reconciler string
}
func (q *Queries) ClearReconcilerErrorsForTeam(ctx context.Context, arg ClearReconcilerErrorsForTeamParams) error {
_, err := q.db.Exec(ctx, clearReconcilerErrorsForTeam, arg.TeamSlug, arg.Reconciler)
return err
}
const getTeamReconcilerErrors = `-- name: GetTeamReconcilerErrors :many
SELECT id, correlation_id, reconciler, created_at, error_message, team_slug FROM reconciler_errors
WHERE team_slug = $1
ORDER BY created_at DESC
`
func (q *Queries) GetTeamReconcilerErrors(ctx context.Context, teamSlug slug.Slug) ([]*ReconcilerError, error) {
rows, err := q.db.Query(ctx, getTeamReconcilerErrors, teamSlug)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*ReconcilerError{}
for rows.Next() {
var i ReconcilerError
if err := rows.Scan(
&i.ID,
&i.CorrelationID,
&i.Reconciler,
&i.CreatedAt,
&i.ErrorMessage,
&i.TeamSlug,
); err != nil {
return nil, err
}
items = append(items, &i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const setReconcilerErrorForTeam = `-- name: SetReconcilerErrorForTeam :exec
INSERT INTO reconciler_errors (correlation_id, team_slug, reconciler, error_message)
VALUES ($1, $2, $3, $4)
ON CONFLICT(team_slug, reconciler) DO
UPDATE SET correlation_id = EXCLUDED.correlation_id, created_at = NOW(), error_message = EXCLUDED.error_message
`
type SetReconcilerErrorForTeamParams struct {
CorrelationID uuid.UUID
TeamSlug slug.Slug
Reconciler string
ErrorMessage string
}
func (q *Queries) SetReconcilerErrorForTeam(ctx context.Context, arg SetReconcilerErrorForTeamParams) error {
_, err := q.db.Exec(ctx, setReconcilerErrorForTeam,
arg.CorrelationID,
arg.TeamSlug,
arg.Reconciler,
arg.ErrorMessage,
)
return err
}