-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.sql.go
609 lines (551 loc) · 12.8 KB
/
queries.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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: queries.sql
package main
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createOrReturnID = `-- name: CreateOrReturnID :one
SELECT id::bigint, is_admin::boolean FROM createOrReturnID($1)
`
type CreateOrReturnIDRow struct {
ID int64
IsAdmin bool
}
func (q *Queries) CreateOrReturnID(ctx context.Context, pEmail string) (CreateOrReturnIDRow, error) {
row := q.db.QueryRow(ctx, createOrReturnID, pEmail)
var i CreateOrReturnIDRow
err := row.Scan(&i.ID, &i.IsAdmin)
return i, err
}
const createThread = `-- name: CreateThread :exec
INSERT INTO thread (subject,member_id,last_member_id) VALUES ($1,$2,$3)
`
type CreateThreadParams struct {
Subject string
MemberID int64
LastMemberID int64
}
func (q *Queries) CreateThread(ctx context.Context, arg CreateThreadParams) error {
_, err := q.db.Exec(ctx, createThread, arg.Subject, arg.MemberID, arg.LastMemberID)
return err
}
const createThreadPost = `-- name: CreateThreadPost :exec
INSERT INTO
thread_post
(thread_id,body,member_id)
VALUES
($1,$2,$3)
`
type CreateThreadPostParams struct {
ThreadID int64
Body pgtype.Text
MemberID int64
}
func (q *Queries) CreateThreadPost(ctx context.Context, arg CreateThreadPostParams) error {
_, err := q.db.Exec(ctx, createThreadPost, arg.ThreadID, arg.Body, arg.MemberID)
return err
}
const getBoardData = `-- name: GetBoardData :one
SELECT
id,
title,
total_members,
total_threads,
total_thread_posts,
edit_window
FROM board_data
`
type GetBoardDataRow struct {
ID int32
Title string
TotalMembers pgtype.Int4
TotalThreads pgtype.Int4
TotalThreadPosts pgtype.Int4
EditWindow pgtype.Int4
}
func (q *Queries) GetBoardData(ctx context.Context) (GetBoardDataRow, error) {
row := q.db.QueryRow(ctx, getBoardData)
var i GetBoardDataRow
err := row.Scan(
&i.ID,
&i.Title,
&i.TotalMembers,
&i.TotalThreads,
&i.TotalThreadPosts,
&i.EditWindow,
)
return i, err
}
const getMember = `-- name: GetMember :one
SELECT
m.email,
mp.location,
m.id,
mp.bio,
mp.timezone,
mp.preferred_name,
mp.proper_name,
mp.pronouns,
m.date_joined,
mp.photo_url
FROM
member m
LEFT JOIN
member_profile mp
ON
m.id = mp.member_id
WHERE
m.id = $1
`
type GetMemberRow struct {
Email string
Location pgtype.Text
ID int64
Bio pgtype.Text
Timezone pgtype.Text
PreferredName pgtype.Text
ProperName pgtype.Text
Pronouns pgtype.Text
DateJoined pgtype.Timestamptz
PhotoUrl pgtype.Text
}
func (q *Queries) GetMember(ctx context.Context, id int64) (GetMemberRow, error) {
row := q.db.QueryRow(ctx, getMember, id)
var i GetMemberRow
err := row.Scan(
&i.Email,
&i.Location,
&i.ID,
&i.Bio,
&i.Timezone,
&i.PreferredName,
&i.ProperName,
&i.Pronouns,
&i.DateJoined,
&i.PhotoUrl,
)
return i, err
}
const getMemberId = `-- name: GetMemberId :one
SELECT id FROM member WHERE email = $1
`
func (q *Queries) GetMemberId(ctx context.Context, email string) (int64, error) {
row := q.db.QueryRow(ctx, getMemberId, email)
var id int64
err := row.Scan(&id)
return id, err
}
const getThreadForEdit = `-- name: GetThreadForEdit :one
SELECT m.email AS email,
t.id AS thread_id,
t.subject AS subject,
tp.id AS thread_post_id,
tp.body AS body
FROM thread t
LEFT JOIN thread_post tp
ON tp.thread_id=t.id
LEFT JOIN member m
ON t.member_id=m.id
WHERE t.id=$1 AND m.id=$2
`
type GetThreadForEditParams struct {
ID int64
ID_2 int64
}
type GetThreadForEditRow struct {
Email pgtype.Text
ThreadID int64
Subject string
ThreadPostID pgtype.Int8
Body pgtype.Text
}
func (q *Queries) GetThreadForEdit(ctx context.Context, arg GetThreadForEditParams) (GetThreadForEditRow, error) {
row := q.db.QueryRow(ctx, getThreadForEdit, arg.ID, arg.ID_2)
var i GetThreadForEditRow
err := row.Scan(
&i.Email,
&i.ThreadID,
&i.Subject,
&i.ThreadPostID,
&i.Body,
)
return i, err
}
const getThreadPostForEdit = `-- name: GetThreadPostForEdit :one
SELECT tp.id, tp.body
FROM thread_post tp LEFT JOIN member m
ON tp.member_id=m.id
WHERE tp.id=$1 AND m.id=$2
`
type GetThreadPostForEditParams struct {
ID int64
ID_2 int64
}
type GetThreadPostForEditRow struct {
ID int64
Body pgtype.Text
}
func (q *Queries) GetThreadPostForEdit(ctx context.Context, arg GetThreadPostForEditParams) (GetThreadPostForEditRow, error) {
row := q.db.QueryRow(ctx, getThreadPostForEdit, arg.ID, arg.ID_2)
var i GetThreadPostForEditRow
err := row.Scan(&i.ID, &i.Body)
return i, err
}
const getThreadPostSequenceId = `-- name: GetThreadPostSequenceId :one
SELECT currval('thread_id_post_seq')
`
func (q *Queries) GetThreadPostSequenceId(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, getThreadPostSequenceId)
var currval int64
err := row.Scan(&currval)
return currval, err
}
const getThreadSequenceId = `-- name: GetThreadSequenceId :one
SELECT currval('thread_id_seq')
`
func (q *Queries) GetThreadSequenceId(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, getThreadSequenceId)
var currval int64
err := row.Scan(&currval)
return currval, err
}
const getThreadSubjectById = `-- name: GetThreadSubjectById :one
SELECT subject FROM thread WHERE id=$1
`
func (q *Queries) GetThreadSubjectById(ctx context.Context, id int64) (string, error) {
row := q.db.QueryRow(ctx, getThreadSubjectById, id)
var subject string
err := row.Scan(&subject)
return subject, err
}
const listMemberThreads = `-- name: ListMemberThreads :many
SELECT
t.id as thread_id,
t.date_last_posted,
m.id,
m.email,
l.id as lastid,
l.email as lastname,
t.subject,
t.posts,
t.views,
(CASE WHEN tm.last_view_posts IS null THEN 0 ELSE tm.last_view_posts END) as last_view_posts,
(CASE WHEN tm.date_posted IS NOT null AND tm.undot IS false AND tm.member_id IS NOT null THEN 't' ELSE 'f' END)::boolean as dot,
t.sticky,
t.locked
FROM
thread t
LEFT JOIN
member m
ON
m.id=t.member_id
LEFT JOIN
member l
ON
l.id=t.last_member_id
LEFT JOIN
thread_post tp
ON
tp.id=t.first_post_id
LEFT OUTER JOIN
thread_member tm
ON
(tm.member_id=$1 AND tm.thread_id=t.id)
WHERE t.sticky IS false
AND m.id=$1
ORDER BY t.date_last_posted DESC
LIMIT 10
`
type ListMemberThreadsRow struct {
ThreadID int64
DateLastPosted pgtype.Timestamptz
ID pgtype.Int8
Email pgtype.Text
Lastid pgtype.Int8
Lastname pgtype.Text
Subject string
Posts pgtype.Int4
Views pgtype.Int4
LastViewPosts interface{}
Dot bool
Sticky pgtype.Bool
Locked pgtype.Bool
}
func (q *Queries) ListMemberThreads(ctx context.Context, memberID int64) ([]ListMemberThreadsRow, error) {
rows, err := q.db.Query(ctx, listMemberThreads, memberID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListMemberThreadsRow
for rows.Next() {
var i ListMemberThreadsRow
if err := rows.Scan(
&i.ThreadID,
&i.DateLastPosted,
&i.ID,
&i.Email,
&i.Lastid,
&i.Lastname,
&i.Subject,
&i.Posts,
&i.Views,
&i.LastViewPosts,
&i.Dot,
&i.Sticky,
&i.Locked,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listThreadPosts = `-- name: ListThreadPosts :many
SELECT
tp.id,
tp.date_posted,
m.id as member_id,
m.email,
tp.body,
t.subject,
t.id as thread_id,
m.is_admin,
(CASE WHEN (m.email = $2 AND t.date_posted >= NOW() - INTERVAL '900 seconds') THEN 't' ELSE 'f' END)::boolean as can_edit
FROM
thread_post tp
LEFT JOIN
member m
ON
m.id=tp.member_id
LEFT JOIN
thread t
ON
t.id = tp.thread_id
WHERE tp.thread_id=$1
ORDER BY tp.date_posted ASC
`
type ListThreadPostsParams struct {
ThreadID int64
Email string
}
type ListThreadPostsRow struct {
ID int64
DatePosted pgtype.Timestamptz
MemberID pgtype.Int8
Email pgtype.Text
Body pgtype.Text
Subject pgtype.Text
ThreadID pgtype.Int8
IsAdmin pgtype.Bool
CanEdit bool
}
func (q *Queries) ListThreadPosts(ctx context.Context, arg ListThreadPostsParams) ([]ListThreadPostsRow, error) {
rows, err := q.db.Query(ctx, listThreadPosts, arg.ThreadID, arg.Email)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListThreadPostsRow
for rows.Next() {
var i ListThreadPostsRow
if err := rows.Scan(
&i.ID,
&i.DatePosted,
&i.MemberID,
&i.Email,
&i.Body,
&i.Subject,
&i.ThreadID,
&i.IsAdmin,
&i.CanEdit,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listThreads = `-- name: ListThreads :many
SELECT
t.id as thread_id,
t.date_last_posted,
m.id,
m.email,
l.id as lastid,
l.email as lastname,
t.subject,
t.posts,
t.views,
tp.body,
(CASE WHEN (m.email = $1 AND t.date_posted >= NOW() - INTERVAL '900 seconds') THEN 't' ELSE 'f' END)::boolean as can_edit,
(CASE WHEN tm.last_view_posts IS null THEN 0 ELSE tm.last_view_posts END) as last_view_posts,
(CASE WHEN tm.date_posted IS NOT null AND tm.undot IS false AND tm.member_id IS NOT null THEN 't' ELSE 'f' END)::boolean as dot,
t.sticky,
t.locked
FROM
thread t
LEFT JOIN
member m
ON
m.id=t.member_id
LEFT JOIN
member l
ON
l.id=t.last_member_id
LEFT JOIN
thread_post tp
ON
tp.id=t.first_post_id
LEFT OUTER JOIN
thread_member tm
ON
(tm.member_id=$2 AND tm.thread_id=t.id)
WHERE t.sticky IS false
ORDER BY t.date_last_posted DESC
LIMIT 100
`
type ListThreadsParams struct {
Email string
MemberID int64
}
type ListThreadsRow struct {
ThreadID int64
DateLastPosted pgtype.Timestamptz
ID pgtype.Int8
Email pgtype.Text
Lastid pgtype.Int8
Lastname pgtype.Text
Subject string
Posts pgtype.Int4
Views pgtype.Int4
Body pgtype.Text
CanEdit bool
LastViewPosts interface{}
Dot bool
Sticky pgtype.Bool
Locked pgtype.Bool
}
func (q *Queries) ListThreads(ctx context.Context, arg ListThreadsParams) ([]ListThreadsRow, error) {
rows, err := q.db.Query(ctx, listThreads, arg.Email, arg.MemberID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListThreadsRow
for rows.Next() {
var i ListThreadsRow
if err := rows.Scan(
&i.ThreadID,
&i.DateLastPosted,
&i.ID,
&i.Email,
&i.Lastid,
&i.Lastname,
&i.Subject,
&i.Posts,
&i.Views,
&i.Body,
&i.CanEdit,
&i.LastViewPosts,
&i.Dot,
&i.Sticky,
&i.Locked,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateBoardEditWindow = `-- name: UpdateBoardEditWindow :exec
UPDATE board_data
SET edit_window=$1
`
func (q *Queries) UpdateBoardEditWindow(ctx context.Context, editWindow pgtype.Int4) error {
_, err := q.db.Exec(ctx, updateBoardEditWindow, editWindow)
return err
}
const updateBoardTitle = `-- name: UpdateBoardTitle :exec
UPDATE board_data
SET title=$1
`
func (q *Queries) UpdateBoardTitle(ctx context.Context, title string) error {
_, err := q.db.Exec(ctx, updateBoardTitle, title)
return err
}
const updateMemberProfileByID = `-- name: UpdateMemberProfileByID :exec
UPDATE member_profile SET
photo_url = $2,
location = $3,
bio = $4,
timezone = $5,
preferred_name = $6,
pronouns = $7
WHERE member_id = $1
`
type UpdateMemberProfileByIDParams struct {
MemberID int64
PhotoUrl pgtype.Text
Location pgtype.Text
Bio pgtype.Text
Timezone pgtype.Text
PreferredName pgtype.Text
Pronouns pgtype.Text
}
func (q *Queries) UpdateMemberProfileByID(ctx context.Context, arg UpdateMemberProfileByIDParams) error {
_, err := q.db.Exec(ctx, updateMemberProfileByID,
arg.MemberID,
arg.PhotoUrl,
arg.Location,
arg.Bio,
arg.Timezone,
arg.PreferredName,
arg.Pronouns,
)
return err
}
const updateThread = `-- name: UpdateThread :exec
UPDATE thread SET
subject = $1
WHERE id = $2
AND member_id = $3
AND date_posted >= NOW() - INTERVAL '900 seconds'
`
type UpdateThreadParams struct {
Subject string
ID int64
MemberID int64
}
func (q *Queries) UpdateThread(ctx context.Context, arg UpdateThreadParams) error {
_, err := q.db.Exec(ctx, updateThread, arg.Subject, arg.ID, arg.MemberID)
return err
}
const updateThreadPost = `-- name: UpdateThreadPost :exec
UPDATE thread_post SET
body = $1
WHERE id = $2
AND member_id = $3
AND date_posted >= NOW() - INTERVAL '900 seconds'
`
type UpdateThreadPostParams struct {
Body pgtype.Text
ID int64
MemberID int64
}
func (q *Queries) UpdateThreadPost(ctx context.Context, arg UpdateThreadPostParams) error {
_, err := q.db.Exec(ctx, updateThreadPost, arg.Body, arg.ID, arg.MemberID)
return err
}