-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_labels.sql.go
238 lines (219 loc) · 5.09 KB
/
mail_labels.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// source: mail_labels.sql
package queries
import (
"context"
"strings"
)
const createMailLabel = `-- name: CreateMailLabel :one
INSERT INTO mail_labels (
color,
name,
unread_count,
my_character_id,
label_id
)
VALUES (
?, ?, ?, ?, ?
)
RETURNING id, my_character_id, color, label_id, name, unread_count
`
type CreateMailLabelParams struct {
Color string
Name string
UnreadCount int64
MyCharacterID int64
LabelID int64
}
func (q *Queries) CreateMailLabel(ctx context.Context, arg CreateMailLabelParams) (MailLabel, error) {
row := q.db.QueryRowContext(ctx, createMailLabel,
arg.Color,
arg.Name,
arg.UnreadCount,
arg.MyCharacterID,
arg.LabelID,
)
var i MailLabel
err := row.Scan(
&i.ID,
&i.MyCharacterID,
&i.Color,
&i.LabelID,
&i.Name,
&i.UnreadCount,
)
return i, err
}
const deleteObsoleteMailLabels = `-- name: DeleteObsoleteMailLabels :exec
DELETE FROM mail_labels
WHERE mail_labels.my_character_id = ?
AND id NOT IN (
SELECT mail_label_id
FROM mail_mail_labels
JOIN mails ON mails.id = mail_mail_labels.mail_id
WHERE mail_labels.my_character_id = ?
)
`
type DeleteObsoleteMailLabelsParams struct {
MyCharacterID int64
MyCharacterID_2 int64
}
func (q *Queries) DeleteObsoleteMailLabels(ctx context.Context, arg DeleteObsoleteMailLabelsParams) error {
_, err := q.db.ExecContext(ctx, deleteObsoleteMailLabels, arg.MyCharacterID, arg.MyCharacterID_2)
return err
}
const getMailLabel = `-- name: GetMailLabel :one
SELECT id, my_character_id, color, label_id, name, unread_count
FROM mail_labels
WHERE my_character_id = ? AND label_id = ?
`
type GetMailLabelParams struct {
MyCharacterID int64
LabelID int64
}
func (q *Queries) GetMailLabel(ctx context.Context, arg GetMailLabelParams) (MailLabel, error) {
row := q.db.QueryRowContext(ctx, getMailLabel, arg.MyCharacterID, arg.LabelID)
var i MailLabel
err := row.Scan(
&i.ID,
&i.MyCharacterID,
&i.Color,
&i.LabelID,
&i.Name,
&i.UnreadCount,
)
return i, err
}
const listMailLabelsByIDs = `-- name: ListMailLabelsByIDs :many
SELECT id, my_character_id, color, label_id, name, unread_count
FROM mail_labels
WHERE my_character_id = ? AND label_id IN (/*SLICE:ids*/?)
`
type ListMailLabelsByIDsParams struct {
MyCharacterID int64
Ids []int64
}
func (q *Queries) ListMailLabelsByIDs(ctx context.Context, arg ListMailLabelsByIDsParams) ([]MailLabel, error) {
query := listMailLabelsByIDs
var queryParams []interface{}
queryParams = append(queryParams, arg.MyCharacterID)
if len(arg.Ids) > 0 {
for _, v := range arg.Ids {
queryParams = append(queryParams, v)
}
query = strings.Replace(query, "/*SLICE:ids*/?", strings.Repeat(",?", len(arg.Ids))[1:], 1)
} else {
query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
}
rows, err := q.db.QueryContext(ctx, query, queryParams...)
if err != nil {
return nil, err
}
defer rows.Close()
var items []MailLabel
for rows.Next() {
var i MailLabel
if err := rows.Scan(
&i.ID,
&i.MyCharacterID,
&i.Color,
&i.LabelID,
&i.Name,
&i.UnreadCount,
); 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 listMailLabelsOrdered = `-- name: ListMailLabelsOrdered :many
SELECT id, my_character_id, color, label_id, name, unread_count
FROM mail_labels
WHERE my_character_id = ?
AND label_id > 8
ORDER BY name
`
func (q *Queries) ListMailLabelsOrdered(ctx context.Context, myCharacterID int64) ([]MailLabel, error) {
rows, err := q.db.QueryContext(ctx, listMailLabelsOrdered, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []MailLabel
for rows.Next() {
var i MailLabel
if err := rows.Scan(
&i.ID,
&i.MyCharacterID,
&i.Color,
&i.LabelID,
&i.Name,
&i.UnreadCount,
); 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 updateOrCreateMailLabel = `-- name: UpdateOrCreateMailLabel :one
INSERT INTO mail_labels (
my_character_id,
label_id,
color,
name,
unread_count
)
VALUES (
?1, ?2, ?3, ?4, ?5
)
ON CONFLICT(my_character_id, label_id) DO
UPDATE SET
color = ?3,
name = ?4,
unread_count = ?5
WHERE my_character_id = ?1
AND label_id = ?2
RETURNING id, my_character_id, color, label_id, name, unread_count
`
type UpdateOrCreateMailLabelParams struct {
MyCharacterID int64
LabelID int64
Color string
Name string
UnreadCount int64
}
func (q *Queries) UpdateOrCreateMailLabel(ctx context.Context, arg UpdateOrCreateMailLabelParams) (MailLabel, error) {
row := q.db.QueryRowContext(ctx, updateOrCreateMailLabel,
arg.MyCharacterID,
arg.LabelID,
arg.Color,
arg.Name,
arg.UnreadCount,
)
var i MailLabel
err := row.Scan(
&i.ID,
&i.MyCharacterID,
&i.Color,
&i.LabelID,
&i.Name,
&i.UnreadCount,
)
return i, err
}