/
relationships.sql.go
148 lines (133 loc) · 3.93 KB
/
relationships.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.18.0
// source: relationships.sql
package postgres
import (
"context"
"time"
"github.com/jackc/pgtype"
)
const createRelationship = `-- name: CreateRelationship :one
INSERT INTO relationships(trust_domain_a_id, trust_domain_b_id, trust_domain_a_consent, trust_domain_b_consent, created_at)
VALUES ($1, $2, $3, $4, $5)
RETURNING id, trust_domain_a_id, trust_domain_b_id, trust_domain_a_consent, trust_domain_b_consent, created_at, updated_at
`
type CreateRelationshipParams struct {
TrustDomainAID pgtype.UUID
TrustDomainBID pgtype.UUID
TrustDomainAConsent ConsentStatus
TrustDomainBConsent ConsentStatus
CreatedAt time.Time
}
func (q *Queries) CreateRelationship(ctx context.Context, arg CreateRelationshipParams) (Relationship, error) {
row := q.queryRow(ctx, q.createRelationshipStmt, createRelationship,
arg.TrustDomainAID,
arg.TrustDomainBID,
arg.TrustDomainAConsent,
arg.TrustDomainBConsent,
arg.CreatedAt,
)
var i Relationship
err := row.Scan(
&i.ID,
&i.TrustDomainAID,
&i.TrustDomainBID,
&i.TrustDomainAConsent,
&i.TrustDomainBConsent,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteRelationship = `-- name: DeleteRelationship :exec
DELETE
FROM relationships
WHERE id = $1
`
func (q *Queries) DeleteRelationship(ctx context.Context, id pgtype.UUID) error {
_, err := q.exec(ctx, q.deleteRelationshipStmt, deleteRelationship, id)
return err
}
const findRelationshipByID = `-- name: FindRelationshipByID :one
SELECT id, trust_domain_a_id, trust_domain_b_id, trust_domain_a_consent, trust_domain_b_consent, created_at, updated_at
FROM relationships
WHERE id = $1
`
func (q *Queries) FindRelationshipByID(ctx context.Context, id pgtype.UUID) (Relationship, error) {
row := q.queryRow(ctx, q.findRelationshipByIDStmt, findRelationshipByID, id)
var i Relationship
err := row.Scan(
&i.ID,
&i.TrustDomainAID,
&i.TrustDomainBID,
&i.TrustDomainAConsent,
&i.TrustDomainBConsent,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const findRelationshipsByTrustDomainID = `-- name: FindRelationshipsByTrustDomainID :many
SELECT id, trust_domain_a_id, trust_domain_b_id, trust_domain_a_consent, trust_domain_b_consent, created_at, updated_at
FROM relationships
WHERE trust_domain_a_id = $1
OR trust_domain_b_id = $1
`
func (q *Queries) FindRelationshipsByTrustDomainID(ctx context.Context, trustDomainAID pgtype.UUID) ([]Relationship, error) {
rows, err := q.query(ctx, q.findRelationshipsByTrustDomainIDStmt, findRelationshipsByTrustDomainID, trustDomainAID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Relationship
for rows.Next() {
var i Relationship
if err := rows.Scan(
&i.ID,
&i.TrustDomainAID,
&i.TrustDomainBID,
&i.TrustDomainAConsent,
&i.TrustDomainBConsent,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateRelationship = `-- name: UpdateRelationship :one
UPDATE relationships
SET trust_domain_a_consent = $2,
trust_domain_b_consent = $3,
updated_at = now()
WHERE id = $1
RETURNING id, trust_domain_a_id, trust_domain_b_id, trust_domain_a_consent, trust_domain_b_consent, created_at, updated_at
`
type UpdateRelationshipParams struct {
ID pgtype.UUID
TrustDomainAConsent ConsentStatus
TrustDomainBConsent ConsentStatus
}
func (q *Queries) UpdateRelationship(ctx context.Context, arg UpdateRelationshipParams) (Relationship, error) {
row := q.queryRow(ctx, q.updateRelationshipStmt, updateRelationship, arg.ID, arg.TrustDomainAConsent, arg.TrustDomainBConsent)
var i Relationship
err := row.Scan(
&i.ID,
&i.TrustDomainAID,
&i.TrustDomainBID,
&i.TrustDomainAConsent,
&i.TrustDomainBConsent,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}