-
Notifications
You must be signed in to change notification settings - Fork 0
/
mails.sql.go
500 lines (453 loc) · 11.6 KB
/
mails.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// source: mails.sql
package queries
import (
"context"
"time"
)
const createMail = `-- name: CreateMail :one
INSERT INTO mails (
body,
my_character_id,
from_id,
is_read,
mail_id,
subject,
timestamp
)
VALUES (
?, ?, ?, ?, ?, ?, ?
)
RETURNING id, body, my_character_id, from_id, is_read, mail_id, subject, timestamp
`
type CreateMailParams struct {
Body string
MyCharacterID int64
FromID int64
IsRead bool
MailID int64
Subject string
Timestamp time.Time
}
func (q *Queries) CreateMail(ctx context.Context, arg CreateMailParams) (Mail, error) {
row := q.db.QueryRowContext(ctx, createMail,
arg.Body,
arg.MyCharacterID,
arg.FromID,
arg.IsRead,
arg.MailID,
arg.Subject,
arg.Timestamp,
)
var i Mail
err := row.Scan(
&i.ID,
&i.Body,
&i.MyCharacterID,
&i.FromID,
&i.IsRead,
&i.MailID,
&i.Subject,
&i.Timestamp,
)
return i, err
}
const createMailMailLabel = `-- name: CreateMailMailLabel :exec
INSERT INTO mail_mail_labels (
mail_label_id,
mail_id
)
VALUES (?, ?)
`
type CreateMailMailLabelParams struct {
MailLabelID int64
MailID int64
}
func (q *Queries) CreateMailMailLabel(ctx context.Context, arg CreateMailMailLabelParams) error {
_, err := q.db.ExecContext(ctx, createMailMailLabel, arg.MailLabelID, arg.MailID)
return err
}
const createMailRecipient = `-- name: CreateMailRecipient :exec
INSERT INTO mail_recipients (
mail_id,
eve_entity_id
)
VALUES (?, ?)
`
type CreateMailRecipientParams struct {
MailID int64
EveEntityID int64
}
func (q *Queries) CreateMailRecipient(ctx context.Context, arg CreateMailRecipientParams) error {
_, err := q.db.ExecContext(ctx, createMailRecipient, arg.MailID, arg.EveEntityID)
return err
}
const deleteMail = `-- name: DeleteMail :exec
DELETE FROM mails
WHERE mails.my_character_id = ?
AND mails.mail_id = ?
`
type DeleteMailParams struct {
MyCharacterID int64
MailID int64
}
func (q *Queries) DeleteMail(ctx context.Context, arg DeleteMailParams) error {
_, err := q.db.ExecContext(ctx, deleteMail, arg.MyCharacterID, arg.MailID)
return err
}
const deleteMailMailLabels = `-- name: DeleteMailMailLabels :exec
DELETE FROM mail_mail_labels
WHERE mail_mail_labels.mail_id = ?
`
func (q *Queries) DeleteMailMailLabels(ctx context.Context, mailID int64) error {
_, err := q.db.ExecContext(ctx, deleteMailMailLabels, mailID)
return err
}
const getMail = `-- name: GetMail :one
SELECT mails.id, mails.body, mails.my_character_id, mails.from_id, mails.is_read, mails.mail_id, mails.subject, mails.timestamp, eve_entities.id, eve_entities.category, eve_entities.name
FROM mails
JOIN eve_entities ON eve_entities.id = mails.from_id
WHERE my_character_id = ?
AND mail_id = ?
`
type GetMailParams struct {
MyCharacterID int64
MailID int64
}
type GetMailRow struct {
Mail Mail
EveEntity EveEntity
}
func (q *Queries) GetMail(ctx context.Context, arg GetMailParams) (GetMailRow, error) {
row := q.db.QueryRowContext(ctx, getMail, arg.MyCharacterID, arg.MailID)
var i GetMailRow
err := row.Scan(
&i.Mail.ID,
&i.Mail.Body,
&i.Mail.MyCharacterID,
&i.Mail.FromID,
&i.Mail.IsRead,
&i.Mail.MailID,
&i.Mail.Subject,
&i.Mail.Timestamp,
&i.EveEntity.ID,
&i.EveEntity.Category,
&i.EveEntity.Name,
)
return i, err
}
const getMailLabelUnreadCounts = `-- name: GetMailLabelUnreadCounts :many
SELECT label_id, COUNT(mails.id) AS unread_count_2
FROM mail_labels
JOIN mail_mail_labels ON mail_mail_labels.mail_label_id = mail_labels.id
JOIN mails ON mails.id = mail_mail_labels.mail_id
WHERE mail_labels.my_character_id = ?
AND is_read IS FALSE
GROUP BY label_id
`
type GetMailLabelUnreadCountsRow struct {
LabelID int64
UnreadCount2 int64
}
func (q *Queries) GetMailLabelUnreadCounts(ctx context.Context, myCharacterID int64) ([]GetMailLabelUnreadCountsRow, error) {
rows, err := q.db.QueryContext(ctx, getMailLabelUnreadCounts, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetMailLabelUnreadCountsRow
for rows.Next() {
var i GetMailLabelUnreadCountsRow
if err := rows.Scan(&i.LabelID, &i.UnreadCount2); 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 getMailLabels = `-- name: GetMailLabels :many
SELECT mail_labels.id, mail_labels.my_character_id, mail_labels.color, mail_labels.label_id, mail_labels.name, mail_labels.unread_count
FROM mail_labels
JOIN mail_mail_labels ON mail_mail_labels.mail_label_id = mail_labels.id
WHERE mail_id = ?
`
func (q *Queries) GetMailLabels(ctx context.Context, mailID int64) ([]MailLabel, error) {
rows, err := q.db.QueryContext(ctx, getMailLabels, mailID)
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 getMailListUnreadCounts = `-- name: GetMailListUnreadCounts :many
SELECT eve_entities.id AS list_id, COUNT(mails.id) as unread_count_2
FROM mails
JOIN mail_recipients ON mail_recipients.mail_id = mails.id
JOIN eve_entities ON eve_entities.id = mail_recipients.eve_entity_id
WHERE my_character_id = ?
AND eve_entities.category = "mail_list"
AND mails.is_read IS FALSE
GROUP BY eve_entities.id
`
type GetMailListUnreadCountsRow struct {
ListID int64
UnreadCount2 int64
}
func (q *Queries) GetMailListUnreadCounts(ctx context.Context, myCharacterID int64) ([]GetMailListUnreadCountsRow, error) {
rows, err := q.db.QueryContext(ctx, getMailListUnreadCounts, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetMailListUnreadCountsRow
for rows.Next() {
var i GetMailListUnreadCountsRow
if err := rows.Scan(&i.ListID, &i.UnreadCount2); 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 getMailRecipients = `-- name: GetMailRecipients :many
SELECT eve_entities.id, eve_entities.category, eve_entities.name
FROM eve_entities
JOIN mail_recipients ON mail_recipients.eve_entity_id = eve_entities.id
WHERE mail_id = ?
`
func (q *Queries) GetMailRecipients(ctx context.Context, mailID int64) ([]EveEntity, error) {
rows, err := q.db.QueryContext(ctx, getMailRecipients, mailID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []EveEntity
for rows.Next() {
var i EveEntity
if err := rows.Scan(&i.ID, &i.Category, &i.Name); 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 getMailUnreadCount = `-- name: GetMailUnreadCount :one
SELECT COUNT(mails.id)
FROM mails
WHERE mails.my_character_id = ?
AND is_read IS FALSE
`
func (q *Queries) GetMailUnreadCount(ctx context.Context, myCharacterID int64) (int64, error) {
row := q.db.QueryRowContext(ctx, getMailUnreadCount, myCharacterID)
var count int64
err := row.Scan(&count)
return count, err
}
const listMailIDs = `-- name: ListMailIDs :many
SELECT mail_id
FROM mails
WHERE my_character_id = ?
`
func (q *Queries) ListMailIDs(ctx context.Context, myCharacterID int64) ([]int64, error) {
rows, err := q.db.QueryContext(ctx, listMailIDs, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var mail_id int64
if err := rows.Scan(&mail_id); err != nil {
return nil, err
}
items = append(items, mail_id)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMailIDsForLabelOrdered = `-- name: ListMailIDsForLabelOrdered :many
SELECT mails.mail_id
FROM mails
JOIN mail_mail_labels ON mail_mail_labels.mail_id = mails.id
JOIN mail_labels ON mail_labels.id = mail_mail_labels.mail_label_id
WHERE mails.my_character_id = ?
AND label_id = ?
ORDER BY timestamp DESC
`
type ListMailIDsForLabelOrderedParams struct {
MyCharacterID int64
LabelID int64
}
func (q *Queries) ListMailIDsForLabelOrdered(ctx context.Context, arg ListMailIDsForLabelOrderedParams) ([]int64, error) {
rows, err := q.db.QueryContext(ctx, listMailIDsForLabelOrdered, arg.MyCharacterID, arg.LabelID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var mail_id int64
if err := rows.Scan(&mail_id); err != nil {
return nil, err
}
items = append(items, mail_id)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMailIDsForListOrdered = `-- name: ListMailIDsForListOrdered :many
SELECT mails.mail_id
FROM mails
JOIN mail_recipients ON mail_recipients.mail_id = mails.id
WHERE my_character_id = ?
AND mail_recipients.eve_entity_id = ?
ORDER BY timestamp DESC
`
type ListMailIDsForListOrderedParams struct {
MyCharacterID int64
EveEntityID int64
}
func (q *Queries) ListMailIDsForListOrdered(ctx context.Context, arg ListMailIDsForListOrderedParams) ([]int64, error) {
rows, err := q.db.QueryContext(ctx, listMailIDsForListOrdered, arg.MyCharacterID, arg.EveEntityID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var mail_id int64
if err := rows.Scan(&mail_id); err != nil {
return nil, err
}
items = append(items, mail_id)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMailIDsNoLabelOrdered = `-- name: ListMailIDsNoLabelOrdered :many
SELECT mails.mail_id
FROM mails
LEFT JOIN mail_mail_labels ON mail_mail_labels.mail_id = mails.id
WHERE my_character_id = ?
AND mail_mail_labels.mail_id IS NULL
ORDER BY timestamp DESC
`
func (q *Queries) ListMailIDsNoLabelOrdered(ctx context.Context, myCharacterID int64) ([]int64, error) {
rows, err := q.db.QueryContext(ctx, listMailIDsNoLabelOrdered, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var mail_id int64
if err := rows.Scan(&mail_id); err != nil {
return nil, err
}
items = append(items, mail_id)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMailIDsOrdered = `-- name: ListMailIDsOrdered :many
SELECT mail_id
FROM mails
WHERE my_character_id = ?
ORDER BY timestamp DESC
`
func (q *Queries) ListMailIDsOrdered(ctx context.Context, myCharacterID int64) ([]int64, error) {
rows, err := q.db.QueryContext(ctx, listMailIDsOrdered, myCharacterID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int64
for rows.Next() {
var mail_id int64
if err := rows.Scan(&mail_id); err != nil {
return nil, err
}
items = append(items, mail_id)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateMail = `-- name: UpdateMail :exec
UPDATE mails
SET is_read = ?2
WHERE id = ?1
`
type UpdateMailParams struct {
ID int64
IsRead bool
}
func (q *Queries) UpdateMail(ctx context.Context, arg UpdateMailParams) error {
_, err := q.db.ExecContext(ctx, updateMail, arg.ID, arg.IsRead)
return err
}