tijl.dev-core/internal/queries/app_flags.sql.go

109 lines
2.8 KiB
Go
Raw Normal View History

2024-08-25 17:43:55 +02:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: app_flags.sql
package queries
import (
"context"
"database/sql"
"github.com/google/uuid"
"github.com/lib/pq"
)
2024-08-26 00:18:45 +02:00
const createFlagsGame = `-- name: CreateFlagsGame :one
2024-08-25 22:14:13 +02:00
INSERT INTO app_flags_games (uid, tags, question_amount)
VALUES ($1, $2, $3)
2024-08-26 00:18:45 +02:00
RETURNING game_id, game_seed
2024-08-25 17:43:55 +02:00
`
type CreateFlagsGameParams struct {
Uid sql.NullString
Tags []string
QuestionAmount int32
}
2024-08-26 00:18:45 +02:00
type CreateFlagsGameRow struct {
GameID uuid.UUID
GameSeed uuid.NullUUID
}
func (q *Queries) CreateFlagsGame(ctx context.Context, arg CreateFlagsGameParams) (CreateFlagsGameRow, error) {
row := q.db.QueryRowContext(ctx, createFlagsGame, arg.Uid, pq.Array(arg.Tags), arg.QuestionAmount)
var i CreateFlagsGameRow
err := row.Scan(&i.GameID, &i.GameSeed)
return i, err
2024-08-25 17:43:55 +02:00
}
const getFlagsGame = `-- name: GetFlagsGame :one
2024-08-26 16:46:28 +02:00
SELECT game_id, game_seed, uid, tags, question_amount, question_current, questions_errors, created_at, last_activity FROM app_flags_games WHERE game_id = $1 LIMIT 1
2024-08-25 17:43:55 +02:00
`
func (q *Queries) GetFlagsGame(ctx context.Context, gameID uuid.UUID) (AppFlagsGame, error) {
row := q.db.QueryRowContext(ctx, getFlagsGame, gameID)
var i AppFlagsGame
err := row.Scan(
&i.GameID,
&i.GameSeed,
&i.Uid,
pq.Array(&i.Tags),
&i.QuestionAmount,
&i.QuestionCurrent,
2024-08-26 16:46:28 +02:00
&i.QuestionsErrors,
2024-08-25 17:43:55 +02:00
&i.CreatedAt,
&i.LastActivity,
)
return i, err
}
const updateFlagsGame = `-- name: UpdateFlagsGame :exec
2024-08-25 22:14:13 +02:00
UPDATE app_flags_games
SET question_current = $1, last_activity = CURRENT_TIMESTAMP
WHERE game_id = $2
2024-08-25 17:43:55 +02:00
`
2024-08-25 22:14:13 +02:00
type UpdateFlagsGameParams struct {
QuestionCurrent int32
GameID uuid.UUID
}
func (q *Queries) UpdateFlagsGame(ctx context.Context, arg UpdateFlagsGameParams) error {
_, err := q.db.ExecContext(ctx, updateFlagsGame, arg.QuestionCurrent, arg.GameID)
return err
}
const updateQuestionCorrect = `-- name: UpdateQuestionCorrect :exec
UPDATE app_flags_games
2024-08-26 16:46:28 +02:00
SET questions_errors = (
SELECT COALESCE(SUM(errors), 0)
2024-08-25 22:14:13 +02:00
FROM app_flags_games_answers
2024-08-26 16:46:28 +02:00
WHERE app_flags_games_answers.game_id = app_flags_games.game_id
2024-08-25 22:14:13 +02:00
)
2024-08-26 16:46:28 +02:00
WHERE app_flags_games.game_id = $1
2024-08-25 22:14:13 +02:00
`
2024-08-26 16:46:28 +02:00
func (q *Queries) UpdateQuestionCorrect(ctx context.Context, gameID uuid.UUID) error {
_, err := q.db.ExecContext(ctx, updateQuestionCorrect, gameID)
return err
}
const upsertGameAnswer = `-- name: UpsertGameAnswer :exec
INSERT INTO app_flags_games_answers (game_id, question, errors)
VALUES ($1, $2, $3)
ON CONFLICT (game_id, question)
DO UPDATE SET errors = app_flags_games_answers.errors + EXCLUDED.errors
`
type UpsertGameAnswerParams struct {
GameID uuid.UUID
Question int32
Errors int32
}
func (q *Queries) UpsertGameAnswer(ctx context.Context, arg UpsertGameAnswerParams) error {
_, err := q.db.ExecContext(ctx, upsertGameAnswer, arg.GameID, arg.Question, arg.Errors)
2024-08-25 17:43:55 +02:00
return err
}