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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: query.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const addMainPlayer = `-- name: AddMainPlayer :exec
INSERT INTO game_main_players (game_id, user_id)
VALUES ($1, $2)
`
type AddMainPlayerParams struct {
GameID int32
UserID int32
}
func (q *Queries) AddMainPlayer(ctx context.Context, arg AddMainPlayerParams) error {
_, err := q.db.Exec(ctx, addMainPlayer, arg.GameID, arg.UserID)
return err
}
const aggregateTestcaseResults = `-- name: AggregateTestcaseResults :one
SELECT
CASE
WHEN COUNT(CASE WHEN r.status IS NULL THEN 1 END) > 0 THEN 'running'
WHEN COUNT(CASE WHEN r.status = 'internal_error' THEN 1 END) > 0 THEN 'internal_error'
WHEN COUNT(CASE WHEN r.status = 'timeout' THEN 1 END) > 0 THEN 'timeout'
WHEN COUNT(CASE WHEN r.status = 'runtime_error' THEN 1 END) > 0 THEN 'runtime_error'
WHEN COUNT(CASE WHEN r.status = 'wrong_answer' THEN 1 END) > 0 THEN 'wrong_answer'
ELSE 'success'
END AS status
FROM testcases
LEFT JOIN testcase_results AS r ON testcases.testcase_id = r.testcase_id
WHERE r.submission_id = $1
`
func (q *Queries) AggregateTestcaseResults(ctx context.Context, submissionID int32) (string, error) {
row := q.db.QueryRow(ctx, aggregateTestcaseResults, submissionID)
var status string
err := row.Scan(&status)
return status, err
}
const createSubmission = `-- name: CreateSubmission :one
INSERT INTO submissions (game_id, user_id, code, code_size, status)
VALUES ($1, $2, $3, $4, 'running')
RETURNING submission_id
`
type CreateSubmissionParams struct {
GameID int32
UserID int32
Code string
CodeSize int32
}
func (q *Queries) CreateSubmission(ctx context.Context, arg CreateSubmissionParams) (int32, error) {
row := q.db.QueryRow(ctx, createSubmission,
arg.GameID,
arg.UserID,
arg.Code,
arg.CodeSize,
)
var submission_id int32
err := row.Scan(&submission_id)
return submission_id, err
}
const createTestcaseResult = `-- name: CreateTestcaseResult :exec
INSERT INTO testcase_results (submission_id, testcase_id, status, stdout, stderr)
VALUES ($1, $2, $3, $4, $5)
`
type CreateTestcaseResultParams struct {
SubmissionID int32
TestcaseID int32
Status string
Stdout string
Stderr string
}
func (q *Queries) CreateTestcaseResult(ctx context.Context, arg CreateTestcaseResultParams) error {
_, err := q.db.Exec(ctx, createTestcaseResult,
arg.SubmissionID,
arg.TestcaseID,
arg.Status,
arg.Stdout,
arg.Stderr,
)
return err
}
const createUser = `-- name: CreateUser :one
INSERT INTO users (username, display_name, is_admin)
VALUES ($1, $1, false)
RETURNING user_id
`
func (q *Queries) CreateUser(ctx context.Context, username string) (int32, error) {
row := q.db.QueryRow(ctx, createUser, username)
var user_id int32
err := row.Scan(&user_id)
return user_id, err
}
const createUserAuth = `-- name: CreateUserAuth :exec
INSERT INTO user_auths (user_id, auth_type)
VALUES ($1, $2)
`
type CreateUserAuthParams struct {
UserID int32
AuthType string
}
func (q *Queries) CreateUserAuth(ctx context.Context, arg CreateUserAuthParams) error {
_, err := q.db.Exec(ctx, createUserAuth, arg.UserID, arg.AuthType)
return err
}
const getGameByID = `-- name: GetGameByID :one
SELECT game_id, game_type, is_public, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description, sample_code FROM games
JOIN problems ON games.problem_id = problems.problem_id
WHERE games.game_id = $1
LIMIT 1
`
type GetGameByIDRow struct {
GameID int32
GameType string
IsPublic bool
DisplayName string
DurationSeconds int32
CreatedAt pgtype.Timestamp
StartedAt pgtype.Timestamp
ProblemID int32
ProblemID_2 int32
Title string
Description string
SampleCode string
}
func (q *Queries) GetGameByID(ctx context.Context, gameID int32) (GetGameByIDRow, error) {
row := q.db.QueryRow(ctx, getGameByID, gameID)
var i GetGameByIDRow
err := row.Scan(
&i.GameID,
&i.GameType,
&i.IsPublic,
&i.DisplayName,
&i.DurationSeconds,
&i.CreatedAt,
&i.StartedAt,
&i.ProblemID,
&i.ProblemID_2,
&i.Title,
&i.Description,
&i.SampleCode,
)
return i, err
}
const getLatestState = `-- name: GetLatestState :one
SELECT game_states.game_id, game_states.user_id, game_states.code, game_states.status, best_score_submission_id, submission_id, submissions.game_id, submissions.user_id, submissions.code, code_size, submissions.status, created_at FROM game_states
LEFT JOIN submissions ON game_states.best_score_submission_id = submissions.submission_id
WHERE game_states.game_id = $1 AND game_states.user_id = $2
LIMIT 1
`
type GetLatestStateParams struct {
GameID int32
UserID int32
}
type GetLatestStateRow struct {
GameID int32
UserID int32
Code string
Status string
BestScoreSubmissionID *int32
SubmissionID *int32
GameID_2 *int32
UserID_2 *int32
Code_2 *string
CodeSize *int32
Status_2 *string
CreatedAt pgtype.Timestamp
}
func (q *Queries) GetLatestState(ctx context.Context, arg GetLatestStateParams) (GetLatestStateRow, error) {
row := q.db.QueryRow(ctx, getLatestState, arg.GameID, arg.UserID)
var i GetLatestStateRow
err := row.Scan(
&i.GameID,
&i.UserID,
&i.Code,
&i.Status,
&i.BestScoreSubmissionID,
&i.SubmissionID,
&i.GameID_2,
&i.UserID_2,
&i.Code_2,
&i.CodeSize,
&i.Status_2,
&i.CreatedAt,
)
return i, err
}
const getLatestStatesOfMainPlayers = `-- name: GetLatestStatesOfMainPlayers :many
SELECT game_main_players.game_id, game_main_players.user_id, game_states.game_id, game_states.user_id, game_states.code, game_states.status, best_score_submission_id, submission_id, submissions.game_id, submissions.user_id, submissions.code, code_size, submissions.status, created_at FROM game_main_players
LEFT JOIN game_states ON game_main_players.game_id = game_states.game_id AND game_main_players.user_id = game_states.user_id
LEFT JOIN submissions ON game_states.best_score_submission_id = submissions.submission_id
WHERE game_main_players.game_id = $1
`
type GetLatestStatesOfMainPlayersRow struct {
GameID int32
UserID int32
GameID_2 *int32
UserID_2 *int32
Code *string
Status *string
BestScoreSubmissionID *int32
SubmissionID *int32
GameID_3 *int32
UserID_3 *int32
Code_2 *string
CodeSize *int32
Status_2 *string
CreatedAt pgtype.Timestamp
}
func (q *Queries) GetLatestStatesOfMainPlayers(ctx context.Context, gameID int32) ([]GetLatestStatesOfMainPlayersRow, error) {
rows, err := q.db.Query(ctx, getLatestStatesOfMainPlayers, gameID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetLatestStatesOfMainPlayersRow
for rows.Next() {
var i GetLatestStatesOfMainPlayersRow
if err := rows.Scan(
&i.GameID,
&i.UserID,
&i.GameID_2,
&i.UserID_2,
&i.Code,
&i.Status,
&i.BestScoreSubmissionID,
&i.SubmissionID,
&i.GameID_3,
&i.UserID_3,
&i.Code_2,
&i.CodeSize,
&i.Status_2,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getQualifyingRanking = `-- name: GetQualifyingRanking :many
SELECT
u.username AS username,
s1.code_size AS code_size_1,
s2.code_size AS code_size_2,
(s1.code_size + s2.code_size) AS total_code_size,
s1.created_at AS submitted_at_1,
s2.created_at AS submitted_at_2
FROM game_states gs1
JOIN submissions s1 ON gs1.best_score_submission_id = s1.submission_id
JOIN game_states gs2 ON gs1.user_id = gs2.user_id
JOIN submissions s2 ON gs2.best_score_submission_id = s2.submission_id
JOIN users u ON gs1.user_id = u.user_id
WHERE gs1.game_id = $1 AND gs2.game_id = $2
ORDER BY total_code_size ASC
`
type GetQualifyingRankingParams struct {
GameID int32
GameID_2 int32
}
type GetQualifyingRankingRow struct {
Username string
CodeSize1 int32
CodeSize2 int32
TotalCodeSize int32
SubmittedAt1 pgtype.Timestamp
SubmittedAt2 pgtype.Timestamp
}
func (q *Queries) GetQualifyingRanking(ctx context.Context, arg GetQualifyingRankingParams) ([]GetQualifyingRankingRow, error) {
rows, err := q.db.Query(ctx, getQualifyingRanking, arg.GameID, arg.GameID_2)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetQualifyingRankingRow
for rows.Next() {
var i GetQualifyingRankingRow
if err := rows.Scan(
&i.Username,
&i.CodeSize1,
&i.CodeSize2,
&i.TotalCodeSize,
&i.SubmittedAt1,
&i.SubmittedAt2,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getRanking = `-- name: GetRanking :many
SELECT
submissions.submission_id, submissions.game_id, submissions.user_id, submissions.code, submissions.code_size, submissions.status, submissions.created_at,
users.user_id, users.username, users.display_name, users.icon_path, users.is_admin, users.label, users.created_at
FROM game_states
JOIN users ON game_states.user_id = users.user_id
JOIN submissions ON game_states.best_score_submission_id = submissions.submission_id
WHERE game_states.game_id = $1
ORDER BY submissions.code_size ASC, submissions.created_at ASC
`
type GetRankingRow struct {
Submission Submission
User User
}
func (q *Queries) GetRanking(ctx context.Context, gameID int32) ([]GetRankingRow, error) {
rows, err := q.db.Query(ctx, getRanking, gameID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetRankingRow
for rows.Next() {
var i GetRankingRow
if err := rows.Scan(
&i.Submission.SubmissionID,
&i.Submission.GameID,
&i.Submission.UserID,
&i.Submission.Code,
&i.Submission.CodeSize,
&i.Submission.Status,
&i.Submission.CreatedAt,
&i.User.UserID,
&i.User.Username,
&i.User.DisplayName,
&i.User.IconPath,
&i.User.IsAdmin,
&i.User.Label,
&i.User.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserAuthByUsername = `-- name: GetUserAuthByUsername :one
SELECT users.user_id, username, display_name, icon_path, is_admin, label, created_at, user_auth_id, user_auths.user_id, auth_type, password_hash FROM users
JOIN user_auths ON users.user_id = user_auths.user_id
WHERE users.username = $1
LIMIT 1
`
type GetUserAuthByUsernameRow struct {
UserID int32
Username string
DisplayName string
IconPath *string
IsAdmin bool
Label *string
CreatedAt pgtype.Timestamp
UserAuthID int32
UserID_2 int32
AuthType string
PasswordHash *string
}
func (q *Queries) GetUserAuthByUsername(ctx context.Context, username string) (GetUserAuthByUsernameRow, error) {
row := q.db.QueryRow(ctx, getUserAuthByUsername, username)
var i GetUserAuthByUsernameRow
err := row.Scan(
&i.UserID,
&i.Username,
&i.DisplayName,
&i.IconPath,
&i.IsAdmin,
&i.Label,
&i.CreatedAt,
&i.UserAuthID,
&i.UserID_2,
&i.AuthType,
&i.PasswordHash,
)
return i, err
}
const getUserByID = `-- name: GetUserByID :one
SELECT user_id, username, display_name, icon_path, is_admin, label, created_at FROM users
WHERE users.user_id = $1
LIMIT 1
`
func (q *Queries) GetUserByID(ctx context.Context, userID int32) (User, error) {
row := q.db.QueryRow(ctx, getUserByID, userID)
var i User
err := row.Scan(
&i.UserID,
&i.Username,
&i.DisplayName,
&i.IconPath,
&i.IsAdmin,
&i.Label,
&i.CreatedAt,
)
return i, err
}
const getUserIDByUsername = `-- name: GetUserIDByUsername :one
SELECT user_id FROM users
WHERE users.username = $1
LIMIT 1
`
func (q *Queries) GetUserIDByUsername(ctx context.Context, username string) (int32, error) {
row := q.db.QueryRow(ctx, getUserIDByUsername, username)
var user_id int32
err := row.Scan(&user_id)
return user_id, err
}
const listAllGames = `-- name: ListAllGames :many
SELECT game_id, game_type, is_public, display_name, duration_seconds, created_at, started_at, problem_id FROM games
ORDER BY games.game_id
`
func (q *Queries) ListAllGames(ctx context.Context) ([]Game, error) {
rows, err := q.db.Query(ctx, listAllGames)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Game
for rows.Next() {
var i Game
if err := rows.Scan(
&i.GameID,
&i.GameType,
&i.IsPublic,
&i.DisplayName,
&i.DurationSeconds,
&i.CreatedAt,
&i.StartedAt,
&i.ProblemID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMainPlayers = `-- name: ListMainPlayers :many
SELECT game_id, game_main_players.user_id, users.user_id, username, display_name, icon_path, is_admin, label, created_at FROM game_main_players
JOIN users ON game_main_players.user_id = users.user_id
WHERE game_main_players.game_id = ANY($1::INT[])
ORDER BY game_main_players.user_id
`
type ListMainPlayersRow struct {
GameID int32
UserID int32
UserID_2 int32
Username string
DisplayName string
IconPath *string
IsAdmin bool
Label *string
CreatedAt pgtype.Timestamp
}
func (q *Queries) ListMainPlayers(ctx context.Context, dollar_1 []int32) ([]ListMainPlayersRow, error) {
rows, err := q.db.Query(ctx, listMainPlayers, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListMainPlayersRow
for rows.Next() {
var i ListMainPlayersRow
if err := rows.Scan(
&i.GameID,
&i.UserID,
&i.UserID_2,
&i.Username,
&i.DisplayName,
&i.IconPath,
&i.IsAdmin,
&i.Label,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listPublicGames = `-- name: ListPublicGames :many
SELECT game_id, game_type, is_public, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description, sample_code FROM games
JOIN problems ON games.problem_id = problems.problem_id
WHERE is_public = true
ORDER BY games.game_id
`
type ListPublicGamesRow struct {
GameID int32
GameType string
IsPublic bool
DisplayName string
DurationSeconds int32
CreatedAt pgtype.Timestamp
StartedAt pgtype.Timestamp
ProblemID int32
ProblemID_2 int32
Title string
Description string
SampleCode string
}
func (q *Queries) ListPublicGames(ctx context.Context) ([]ListPublicGamesRow, error) {
rows, err := q.db.Query(ctx, listPublicGames)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListPublicGamesRow
for rows.Next() {
var i ListPublicGamesRow
if err := rows.Scan(
&i.GameID,
&i.GameType,
&i.IsPublic,
&i.DisplayName,
&i.DurationSeconds,
&i.CreatedAt,
&i.StartedAt,
&i.ProblemID,
&i.ProblemID_2,
&i.Title,
&i.Description,
&i.SampleCode,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listTestcasesByGameID = `-- name: ListTestcasesByGameID :many
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1)
ORDER BY testcases.testcase_id
`
func (q *Queries) ListTestcasesByGameID(ctx context.Context, gameID int32) ([]Testcase, error) {
rows, err := q.db.Query(ctx, listTestcasesByGameID, gameID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Testcase
for rows.Next() {
var i Testcase
if err := rows.Scan(
&i.TestcaseID,
&i.ProblemID,
&i.Stdin,
&i.Stdout,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUsers = `-- name: ListUsers :many
SELECT user_id, username, display_name, icon_path, is_admin, label, created_at FROM users
ORDER BY users.user_id
`
func (q *Queries) ListUsers(ctx context.Context) ([]User, error) {
rows, err := q.db.Query(ctx, listUsers)
if err != nil {
return nil, err
}
defer rows.Close()
var items []User
for rows.Next() {
var i User
if err := rows.Scan(
&i.UserID,
&i.Username,
&i.DisplayName,
&i.IconPath,
&i.IsAdmin,
&i.Label,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const removeAllMainPlayers = `-- name: RemoveAllMainPlayers :exec
DELETE FROM game_main_players
WHERE game_id = $1
`
func (q *Queries) RemoveAllMainPlayers(ctx context.Context, gameID int32) error {
_, err := q.db.Exec(ctx, removeAllMainPlayers, gameID)
return err
}
const syncGameStateBestScoreSubmission = `-- name: SyncGameStateBestScoreSubmission :exec
UPDATE game_states
SET best_score_submission_id = (
SELECT submission_id FROM submissions AS s
WHERE s.game_id = $1 AND s.user_id = $2 AND s.status = 'success'
ORDER BY s.code_size ASC, s.created_at ASC
LIMIT 1
)
WHERE game_id = $1 AND user_id = $2
`
type SyncGameStateBestScoreSubmissionParams struct {
GameID int32
UserID int32
}
func (q *Queries) SyncGameStateBestScoreSubmission(ctx context.Context, arg SyncGameStateBestScoreSubmissionParams) error {
_, err := q.db.Exec(ctx, syncGameStateBestScoreSubmission, arg.GameID, arg.UserID)
return err
}
const updateCode = `-- name: UpdateCode :exec
INSERT INTO game_states (game_id, user_id, code, status)
VALUES ($1, $2, $3, $4)
ON CONFLICT (game_id, user_id)
DO UPDATE SET code = EXCLUDED.code
`
type UpdateCodeParams struct {
GameID int32
UserID int32
Code string
Status string
}
func (q *Queries) UpdateCode(ctx context.Context, arg UpdateCodeParams) error {
_, err := q.db.Exec(ctx, updateCode,
arg.GameID,
arg.UserID,
arg.Code,
arg.Status,
)
return err
}
const updateGame = `-- name: UpdateGame :exec
UPDATE games
SET
game_type = $2,
is_public = $3,
display_name = $4,
duration_seconds = $5,
started_at = $6,
problem_id = $7
WHERE game_id = $1
`
type UpdateGameParams struct {
GameID int32
GameType string
IsPublic bool
DisplayName string
DurationSeconds int32
StartedAt pgtype.Timestamp
ProblemID int32
}
func (q *Queries) UpdateGame(ctx context.Context, arg UpdateGameParams) error {
_, err := q.db.Exec(ctx, updateGame,
arg.GameID,
arg.GameType,
arg.IsPublic,
arg.DisplayName,
arg.DurationSeconds,
arg.StartedAt,
arg.ProblemID,
)
return err
}
const updateGameStartedAt = `-- name: UpdateGameStartedAt :exec
UPDATE games
SET started_at = $2
WHERE game_id = $1
`
type UpdateGameStartedAtParams struct {
GameID int32
StartedAt pgtype.Timestamp
}
func (q *Queries) UpdateGameStartedAt(ctx context.Context, arg UpdateGameStartedAtParams) error {
_, err := q.db.Exec(ctx, updateGameStartedAt, arg.GameID, arg.StartedAt)
return err
}
const updateGameStateStatus = `-- name: UpdateGameStateStatus :exec
UPDATE game_states
SET status = $3
WHERE game_id = $1 AND user_id = $2
`
type UpdateGameStateStatusParams struct {
GameID int32
UserID int32
Status string
}
func (q *Queries) UpdateGameStateStatus(ctx context.Context, arg UpdateGameStateStatusParams) error {
_, err := q.db.Exec(ctx, updateGameStateStatus, arg.GameID, arg.UserID, arg.Status)
return err
}
const updateSubmissionStatus = `-- name: UpdateSubmissionStatus :exec
UPDATE submissions
SET status = $2
WHERE submission_id = $1
`
type UpdateSubmissionStatusParams struct {
SubmissionID int32
Status string
}
func (q *Queries) UpdateSubmissionStatus(ctx context.Context, arg UpdateSubmissionStatusParams) error {
_, err := q.db.Exec(ctx, updateSubmissionStatus, arg.SubmissionID, arg.Status)
return err
}
const updateUser = `-- name: UpdateUser :exec
UPDATE users
SET
display_name = $2,
icon_path = $3,
is_admin = $4,
label = $5
WHERE user_id = $1
`
type UpdateUserParams struct {
UserID int32
DisplayName string
IconPath *string
IsAdmin bool
Label *string
}
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
_, err := q.db.Exec(ctx, updateUser,
arg.UserID,
arg.DisplayName,
arg.IconPath,
arg.IsAdmin,
arg.Label,
)
return err
}
const updateUserIconPath = `-- name: UpdateUserIconPath :exec
UPDATE users
SET icon_path = $2
WHERE user_id = $1
`
type UpdateUserIconPathParams struct {
UserID int32
IconPath *string
}
func (q *Queries) UpdateUserIconPath(ctx context.Context, arg UpdateUserIconPathParams) error {
_, err := q.db.Exec(ctx, updateUserIconPath, arg.UserID, arg.IconPath)
return err
}
|