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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
|
// 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(*) < (SELECT COUNT(*) FROM testcases WHERE problem_id =
(SELECT problem_id FROM games WHERE game_id =
(SELECT game_id FROM submissions AS s WHERE s.submission_id = $1)))
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 testcase_results AS r
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 createGame = `-- name: CreateGame :one
INSERT INTO games (game_type, is_public, display_name, duration_seconds, problem_id)
VALUES ($1, $2, $3, $4, $5)
RETURNING game_id
`
type CreateGameParams struct {
GameType string
IsPublic bool
DisplayName string
DurationSeconds int32
ProblemID int32
}
func (q *Queries) CreateGame(ctx context.Context, arg CreateGameParams) (int32, error) {
row := q.db.QueryRow(ctx, createGame,
arg.GameType,
arg.IsPublic,
arg.DisplayName,
arg.DurationSeconds,
arg.ProblemID,
)
var game_id int32
err := row.Scan(&game_id)
return game_id, err
}
const createProblem = `-- name: CreateProblem :one
INSERT INTO problems (title, description, language, sample_code)
VALUES ($1, $2, $3, $4)
RETURNING problem_id
`
type CreateProblemParams struct {
Title string
Description string
Language string
SampleCode string
}
func (q *Queries) CreateProblem(ctx context.Context, arg CreateProblemParams) (int32, error) {
row := q.db.QueryRow(ctx, createProblem,
arg.Title,
arg.Description,
arg.Language,
arg.SampleCode,
)
var problem_id int32
err := row.Scan(&problem_id)
return problem_id, 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 createTestcase = `-- name: CreateTestcase :one
INSERT INTO testcases (problem_id, stdin, stdout)
VALUES ($1, $2, $3)
RETURNING testcase_id
`
type CreateTestcaseParams struct {
ProblemID int32
Stdin string
Stdout string
}
func (q *Queries) CreateTestcase(ctx context.Context, arg CreateTestcaseParams) (int32, error) {
row := q.db.QueryRow(ctx, createTestcase, arg.ProblemID, arg.Stdin, arg.Stdout)
var testcase_id int32
err := row.Scan(&testcase_id)
return testcase_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 deleteTestcase = `-- name: DeleteTestcase :exec
DELETE FROM testcases
WHERE testcase_id = $1
`
func (q *Queries) DeleteTestcase(ctx context.Context, testcaseID int32) error {
_, err := q.db.Exec(ctx, deleteTestcase, testcaseID)
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, language, 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
Language 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.Language,
&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 getProblemByID = `-- name: GetProblemByID :one
SELECT problem_id, title, description, language, sample_code FROM problems
WHERE problem_id = $1
LIMIT 1
`
func (q *Queries) GetProblemByID(ctx context.Context, problemID int32) (Problem, error) {
row := q.db.QueryRow(ctx, getProblemByID, problemID)
var i Problem
err := row.Scan(
&i.ProblemID,
&i.Title,
&i.Description,
&i.Language,
&i.SampleCode,
)
return i, err
}
const getQualifyingRanking = `-- name: GetQualifyingRanking :many
SELECT
u.username AS username,
u.label AS user_label,
s1.code_size AS code_size_1,
s2.code_size AS code_size_2,
s3.code_size AS code_size_3,
(COALESCE(s1.code_size, 0) + COALESCE(s2.code_size, 0) + COALESCE(s3.code_size, 0)) AS total_code_size,
s1.created_at AS submitted_at_1,
s2.created_at AS submitted_at_2,
s3.created_at AS submitted_at_3
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 game_states gs3 ON gs1.user_id = gs3.user_id
JOIN submissions s3 ON gs3.best_score_submission_id = s3.submission_id
JOIN users u ON gs1.user_id = u.user_id
WHERE gs1.game_id = $1 AND gs2.game_id = $2 AND gs3.game_id = $3
ORDER BY total_code_size ASC
`
type GetQualifyingRankingParams struct {
GameID int32
GameID_2 int32
GameID_3 int32
}
type GetQualifyingRankingRow struct {
Username string
UserLabel *string
CodeSize1 int32
CodeSize2 int32
CodeSize3 int32
TotalCodeSize int32
SubmittedAt1 pgtype.Timestamp
SubmittedAt2 pgtype.Timestamp
SubmittedAt3 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, arg.GameID_3)
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.UserLabel,
&i.CodeSize1,
&i.CodeSize2,
&i.CodeSize3,
&i.TotalCodeSize,
&i.SubmittedAt1,
&i.SubmittedAt2,
&i.SubmittedAt3,
); 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
LIMIT 30
`
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 getTestcaseByID = `-- name: GetTestcaseByID :one
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
WHERE testcase_id = $1
LIMIT 1
`
func (q *Queries) GetTestcaseByID(ctx context.Context, testcaseID int32) (Testcase, error) {
row := q.db.QueryRow(ctx, getTestcaseByID, testcaseID)
var i Testcase
err := row.Scan(
&i.TestcaseID,
&i.ProblemID,
&i.Stdin,
&i.Stdout,
)
return i, err
}
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 listGameStateIDs = `-- name: ListGameStateIDs :many
SELECT game_id, user_id FROM game_states
`
type ListGameStateIDsRow struct {
GameID int32
UserID int32
}
func (q *Queries) ListGameStateIDs(ctx context.Context) ([]ListGameStateIDsRow, error) {
rows, err := q.db.Query(ctx, listGameStateIDs)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListGameStateIDsRow
for rows.Next() {
var i ListGameStateIDsRow
if err := rows.Scan(&i.GameID, &i.UserID); 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 listProblems = `-- name: ListProblems :many
SELECT problem_id, title, description, language, sample_code FROM problems
ORDER BY problem_id
`
func (q *Queries) ListProblems(ctx context.Context) ([]Problem, error) {
rows, err := q.db.Query(ctx, listProblems)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Problem
for rows.Next() {
var i Problem
if err := rows.Scan(
&i.ProblemID,
&i.Title,
&i.Description,
&i.Language,
&i.SampleCode,
); 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, language, 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
Language 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.Language,
&i.SampleCode,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSubmissionIDs = `-- name: ListSubmissionIDs :many
SELECT submission_id FROM submissions
`
func (q *Queries) ListSubmissionIDs(ctx context.Context) ([]int32, error) {
rows, err := q.db.Query(ctx, listSubmissionIDs)
if err != nil {
return nil, err
}
defer rows.Close()
var items []int32
for rows.Next() {
var submission_id int32
if err := rows.Scan(&submission_id); err != nil {
return nil, err
}
items = append(items, submission_id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listTestcases = `-- name: ListTestcases :many
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
ORDER BY testcase_id
`
func (q *Queries) ListTestcases(ctx context.Context) ([]Testcase, error) {
rows, err := q.db.Query(ctx, listTestcases)
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 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 listTestcasesByProblemID = `-- name: ListTestcasesByProblemID :many
SELECT testcase_id, problem_id, stdin, stdout FROM testcases
WHERE problem_id = $1
ORDER BY testcase_id
`
func (q *Queries) ListTestcasesByProblemID(ctx context.Context, problemID int32) ([]Testcase, error) {
rows, err := q.db.Query(ctx, listTestcasesByProblemID, problemID)
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 updateCodeAndStatus = `-- name: UpdateCodeAndStatus :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, status = EXCLUDED.status
`
type UpdateCodeAndStatusParams struct {
GameID int32
UserID int32
Code string
Status string
}
func (q *Queries) UpdateCodeAndStatus(ctx context.Context, arg UpdateCodeAndStatusParams) error {
_, err := q.db.Exec(ctx, updateCodeAndStatus,
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 updateProblem = `-- name: UpdateProblem :exec
UPDATE problems
SET
title = $2,
description = $3,
language = $4,
sample_code = $5
WHERE problem_id = $1
`
type UpdateProblemParams struct {
ProblemID int32
Title string
Description string
Language string
SampleCode string
}
func (q *Queries) UpdateProblem(ctx context.Context, arg UpdateProblemParams) error {
_, err := q.db.Exec(ctx, updateProblem,
arg.ProblemID,
arg.Title,
arg.Description,
arg.Language,
arg.SampleCode,
)
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 updateTestcase = `-- name: UpdateTestcase :exec
UPDATE testcases
SET
problem_id = $2,
stdin = $3,
stdout = $4
WHERE testcase_id = $1
`
type UpdateTestcaseParams struct {
TestcaseID int32
ProblemID int32
Stdin string
Stdout string
}
func (q *Queries) UpdateTestcase(ctx context.Context, arg UpdateTestcaseParams) error {
_, err := q.db.Exec(ctx, updateTestcase,
arg.TestcaseID,
arg.ProblemID,
arg.Stdin,
arg.Stdout,
)
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
}
|