// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.26.0 // source: query.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) 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, code_hash) VALUES ($1, $2, $3, $4, $5) RETURNING submission_id ` type CreateSubmissionParams struct { GameID int32 UserID int32 Code string CodeSize int32 CodeHash string } 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, arg.CodeHash, ) var submission_id int32 err := row.Scan(&submission_id) return submission_id, err } const createSubmissionResult = `-- name: CreateSubmissionResult :exec INSERT INTO submission_results (submission_id, status, stdout, stderr) VALUES ($1, $2, $3, $4) ` type CreateSubmissionResultParams struct { SubmissionID int32 Status string Stdout string Stderr string } func (q *Queries) CreateSubmissionResult(ctx context.Context, arg CreateSubmissionResultParams) error { _, err := q.db.Exec(ctx, createSubmissionResult, arg.SubmissionID, arg.Status, arg.Stdout, arg.Stderr, ) return 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, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description 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 State string DisplayName string DurationSeconds int32 CreatedAt pgtype.Timestamp StartedAt pgtype.Timestamp ProblemID int32 ProblemID_2 int32 Title string Description 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.State, &i.DisplayName, &i.DurationSeconds, &i.CreatedAt, &i.StartedAt, &i.ProblemID, &i.ProblemID_2, &i.Title, &i.Description, ) return i, err } const getUserAuthByUsername = `-- name: GetUserAuthByUsername :one SELECT users.user_id, username, display_name, icon_path, is_admin, 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 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.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, 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.CreatedAt, ) return i, err } const isRegistrationTokenValid = `-- name: IsRegistrationTokenValid :one SELECT EXISTS ( SELECT 1 FROM registration_tokens WHERE token = $1 ) ` func (q *Queries) IsRegistrationTokenValid(ctx context.Context, token string) (bool, error) { row := q.db.QueryRow(ctx, isRegistrationTokenValid, token) var exists bool err := row.Scan(&exists) return exists, err } const listGamePlayers = `-- name: ListGamePlayers :many SELECT game_id, game_players.user_id, users.user_id, username, display_name, icon_path, is_admin, created_at FROM game_players JOIN users ON game_players.user_id = users.user_id WHERE game_players.game_id = $1 ORDER BY game_players.user_id ` type ListGamePlayersRow struct { GameID int32 UserID int32 UserID_2 int32 Username string DisplayName string IconPath *string IsAdmin bool CreatedAt pgtype.Timestamp } func (q *Queries) ListGamePlayers(ctx context.Context, gameID int32) ([]ListGamePlayersRow, error) { rows, err := q.db.Query(ctx, listGamePlayers, gameID) if err != nil { return nil, err } defer rows.Close() var items []ListGamePlayersRow for rows.Next() { var i ListGamePlayersRow if err := rows.Scan( &i.GameID, &i.UserID, &i.UserID_2, &i.Username, &i.DisplayName, &i.IconPath, &i.IsAdmin, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listGames = `-- name: ListGames :many SELECT game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games JOIN problems ON games.problem_id = problems.problem_id ORDER BY games.game_id ` type ListGamesRow struct { GameID int32 GameType string State string DisplayName string DurationSeconds int32 CreatedAt pgtype.Timestamp StartedAt pgtype.Timestamp ProblemID int32 ProblemID_2 int32 Title string Description string } func (q *Queries) ListGames(ctx context.Context) ([]ListGamesRow, error) { rows, err := q.db.Query(ctx, listGames) if err != nil { return nil, err } defer rows.Close() var items []ListGamesRow for rows.Next() { var i ListGamesRow if err := rows.Scan( &i.GameID, &i.GameType, &i.State, &i.DisplayName, &i.DurationSeconds, &i.CreatedAt, &i.StartedAt, &i.ProblemID, &i.ProblemID_2, &i.Title, &i.Description, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listGamesForPlayer = `-- name: ListGamesForPlayer :many SELECT games.game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description, game_players.game_id, user_id FROM games JOIN problems ON games.problem_id = problems.problem_id JOIN game_players ON games.game_id = game_players.game_id WHERE game_players.user_id = $1 ORDER BY games.game_id ` type ListGamesForPlayerRow struct { GameID int32 GameType string State string DisplayName string DurationSeconds int32 CreatedAt pgtype.Timestamp StartedAt pgtype.Timestamp ProblemID int32 ProblemID_2 int32 Title string Description string GameID_2 int32 UserID int32 } func (q *Queries) ListGamesForPlayer(ctx context.Context, userID int32) ([]ListGamesForPlayerRow, error) { rows, err := q.db.Query(ctx, listGamesForPlayer, userID) if err != nil { return nil, err } defer rows.Close() var items []ListGamesForPlayerRow for rows.Next() { var i ListGamesForPlayerRow if err := rows.Scan( &i.GameID, &i.GameType, &i.State, &i.DisplayName, &i.DurationSeconds, &i.CreatedAt, &i.StartedAt, &i.ProblemID, &i.ProblemID_2, &i.Title, &i.Description, &i.GameID_2, &i.UserID, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listTestcaseIDsByGameID = `-- name: ListTestcaseIDsByGameID :many SELECT testcases.testcase_id FROM testcases WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1) ORDER BY testcases.testcase_id ` func (q *Queries) ListTestcaseIDsByGameID(ctx context.Context, gameID int32) ([]int32, error) { rows, err := q.db.Query(ctx, listTestcaseIDsByGameID, gameID) if err != nil { return nil, err } defer rows.Close() var items []int32 for rows.Next() { var testcase_id int32 if err := rows.Scan(&testcase_id); err != nil { return nil, err } items = append(items, testcase_id) } 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, 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.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateGame = `-- name: UpdateGame :exec UPDATE games SET game_type = $2, state = $3, display_name = $4, duration_seconds = $5, started_at = $6, problem_id = $7 WHERE game_id = $1 ` type UpdateGameParams struct { GameID int32 GameType string State string 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.State, 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 updateGameState = `-- name: UpdateGameState :exec UPDATE games SET state = $2 WHERE game_id = $1 ` type UpdateGameStateParams struct { GameID int32 State string } func (q *Queries) UpdateGameState(ctx context.Context, arg UpdateGameStateParams) error { _, err := q.db.Exec(ctx, updateGameState, arg.GameID, arg.State) return err }