// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: assessment_practice.sql package sqlc import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const findAssessmentPracticeSubmissionByScope = `-- name: FindAssessmentPracticeSubmissionByScope :one SELECT submission.id, submission.practice_id, submission.mode FROM assessment_practice_submissions AS submission WHERE submission.user_id = $1 AND submission.idempotency_scope = $2 ORDER BY submission.created_at DESC, submission.id DESC LIMIT 1 ` type FindAssessmentPracticeSubmissionByScopeParams struct { UserID pgtype.UUID IdempotencyScope []byte } type FindAssessmentPracticeSubmissionByScopeRow struct { ID pgtype.UUID PracticeID pgtype.UUID Mode string } // Finds the latest submission of the owner under an idempotency scope, which // a replay returns. func (q *Queries) FindAssessmentPracticeSubmissionByScope(ctx context.Context, arg FindAssessmentPracticeSubmissionByScopeParams) (FindAssessmentPracticeSubmissionByScopeRow, error) { row := q.db.QueryRow(ctx, findAssessmentPracticeSubmissionByScope, arg.UserID, arg.IdempotencyScope) var i FindAssessmentPracticeSubmissionByScopeRow err := row.Scan(&i.ID, &i.PracticeID, &i.Mode) return i, err } const getAssessmentPracticeRun = `-- name: GetAssessmentPracticeRun :one SELECT submission.id, submission.practice_id, submission.created_at, submission.result, job.state, job.finished_at FROM assessment_practice_submissions AS submission INNER JOIN assessment_practices AS practice ON submission.practice_id = practice.id INNER JOIN assessment_practice_jobs AS job ON submission.id = job.submission_id WHERE submission.id = $1 AND submission.user_id = $2 AND submission.mode = 'public' AND practice.attempt_id = $3 ` type GetAssessmentPracticeRunParams struct { ID pgtype.UUID UserID pgtype.UUID AttemptID pgtype.UUID } type GetAssessmentPracticeRunRow struct { ID pgtype.UUID PracticeID pgtype.UUID CreatedAt pgtype.Timestamptz Result []byte State string FinishedAt pgtype.Timestamptz } // Reads a debug run of the owner's attempt with the state of its job. func (q *Queries) GetAssessmentPracticeRun(ctx context.Context, arg GetAssessmentPracticeRunParams) (GetAssessmentPracticeRunRow, error) { row := q.db.QueryRow(ctx, getAssessmentPracticeRun, arg.ID, arg.UserID, arg.AttemptID) var i GetAssessmentPracticeRunRow err := row.Scan( &i.ID, &i.PracticeID, &i.CreatedAt, &i.Result, &i.State, &i.FinishedAt, ) return i, err } const getLatestFinalPracticeSubmission = `-- name: GetLatestFinalPracticeSubmission :one SELECT submission.id, submission.language, submission.source_sha256 FROM assessment_practice_submissions AS submission WHERE submission.practice_id = $1 AND submission.mode = 'final' ORDER BY submission.created_at DESC, submission.id DESC LIMIT 1 ` type GetLatestFinalPracticeSubmissionRow struct { ID pgtype.UUID Language string SourceSha256 []byte } // The latest final submission of a practice: the solution the practice // state describes. func (q *Queries) GetLatestFinalPracticeSubmission(ctx context.Context, practiceID pgtype.UUID) (GetLatestFinalPracticeSubmissionRow, error) { row := q.db.QueryRow(ctx, getLatestFinalPracticeSubmission, practiceID) var i GetLatestFinalPracticeSubmissionRow err := row.Scan(&i.ID, &i.Language, &i.SourceSha256) return i, err } const insertAssessmentPractice = `-- name: InsertAssessmentPractice :exec INSERT INTO assessment_practices ( id, attempt_id, user_id, kind, task, status, failure_reason, submitted_at, created_at, updated_at ) VALUES ( $1, $2, $3, $4, $5, 'not_started', NULL, NULL, $6, $6 ) ` type InsertAssessmentPracticeParams struct { ID pgtype.UUID AttemptID pgtype.UUID UserID pgtype.UUID Kind string Task []byte CreatedAt pgtype.Timestamptz } func (q *Queries) InsertAssessmentPractice(ctx context.Context, arg InsertAssessmentPracticeParams) error { _, err := q.db.Exec(ctx, insertAssessmentPractice, arg.ID, arg.AttemptID, arg.UserID, arg.Kind, arg.Task, arg.CreatedAt, ) return err } const insertAssessmentPracticeJob = `-- name: InsertAssessmentPracticeJob :exec INSERT INTO assessment_practice_jobs ( submission_id, mode, state, available_at, created_at, updated_at ) VALUES ( $1, $2, 'queued', $3, $3, $3 ) ` type InsertAssessmentPracticeJobParams struct { SubmissionID pgtype.UUID Mode string CreatedAt pgtype.Timestamptz } // Queues the execution job of a submission in the transaction that stores // the submission. The job is available at once. func (q *Queries) InsertAssessmentPracticeJob(ctx context.Context, arg InsertAssessmentPracticeJobParams) error { _, err := q.db.Exec(ctx, insertAssessmentPracticeJob, arg.SubmissionID, arg.Mode, arg.CreatedAt) return err } const insertAssessmentPracticeSubmission = `-- name: InsertAssessmentPracticeSubmission :exec INSERT INTO assessment_practice_submissions ( id, practice_id, user_id, mode, language, source, source_sha256, custom_tests, idempotency_scope, created_at ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 ) ` type InsertAssessmentPracticeSubmissionParams struct { ID pgtype.UUID PracticeID pgtype.UUID UserID pgtype.UUID Mode string Language string Source string SourceSha256 []byte CustomTests []byte IdempotencyScope []byte CreatedAt pgtype.Timestamptz } func (q *Queries) InsertAssessmentPracticeSubmission(ctx context.Context, arg InsertAssessmentPracticeSubmissionParams) error { _, err := q.db.Exec(ctx, insertAssessmentPracticeSubmission, arg.ID, arg.PracticeID, arg.UserID, arg.Mode, arg.Language, arg.Source, arg.SourceSha256, arg.CustomTests, arg.IdempotencyScope, arg.CreatedAt, ) return err } const lockAssessmentAttemptForPractice = `-- name: LockAssessmentAttemptForPractice :one SELECT attempt.state, attempt.expires_at, clock_timestamp()::timestamptz AS database_time FROM assessment_attempts AS attempt WHERE attempt.id = $1 AND attempt.user_id = $2 FOR SHARE ` type LockAssessmentAttemptForPracticeParams struct { AttemptID pgtype.UUID UserID pgtype.UUID } type LockAssessmentAttemptForPracticeRow struct { State string ExpiresAt pgtype.Timestamptz DatabaseTime pgtype.Timestamptz } // Lock order of a practice command: the idempotency record, the attempt in // share mode, then the practice row. The attempt flows lock the attempt // first as well, so a practice command never waits for them in the opposite // order. // Locks the owner's attempt in share mode, so its state cannot change while // a practice command decides on it, and reads the database time after the // lock. func (q *Queries) LockAssessmentAttemptForPractice(ctx context.Context, arg LockAssessmentAttemptForPracticeParams) (LockAssessmentAttemptForPracticeRow, error) { row := q.db.QueryRow(ctx, lockAssessmentAttemptForPractice, arg.AttemptID, arg.UserID) var i LockAssessmentAttemptForPracticeRow err := row.Scan(&i.State, &i.ExpiresAt, &i.DatabaseTime) return i, err } const lockAssessmentPractice = `-- name: LockAssessmentPractice :one SELECT practice.id, practice.attempt_id, practice.user_id, practice.kind, practice.task, practice.status, practice.failure_reason, practice.submitted_at, practice.created_at FROM assessment_practices AS practice WHERE practice.id = $1 AND practice.attempt_id = $2 AND practice.user_id = $3 FOR UPDATE ` type LockAssessmentPracticeParams struct { ID pgtype.UUID AttemptID pgtype.UUID UserID pgtype.UUID } type LockAssessmentPracticeRow struct { ID pgtype.UUID AttemptID pgtype.UUID UserID pgtype.UUID Kind string Task []byte Status string FailureReason pgtype.Text SubmittedAt pgtype.Timestamptz CreatedAt pgtype.Timestamptz } // Locks one practice of the owner's attempt for a state change. func (q *Queries) LockAssessmentPractice(ctx context.Context, arg LockAssessmentPracticeParams) (LockAssessmentPracticeRow, error) { row := q.db.QueryRow(ctx, lockAssessmentPractice, arg.ID, arg.AttemptID, arg.UserID) var i LockAssessmentPracticeRow err := row.Scan( &i.ID, &i.AttemptID, &i.UserID, &i.Kind, &i.Task, &i.Status, &i.FailureReason, &i.SubmittedAt, &i.CreatedAt, ) return i, err } const updateAssessmentPracticeState = `-- name: UpdateAssessmentPracticeState :execrows UPDATE assessment_practices SET status = $1, failure_reason = $2, submitted_at = $3, updated_at = greatest(updated_at, $4::timestamptz) WHERE id = $5 ` type UpdateAssessmentPracticeStateParams struct { Status string FailureReason pgtype.Text SubmittedAt pgtype.Timestamptz UpdatedAt pgtype.Timestamptz ID pgtype.UUID } func (q *Queries) UpdateAssessmentPracticeState(ctx context.Context, arg UpdateAssessmentPracticeStateParams) (int64, error) { result, err := q.db.Exec(ctx, updateAssessmentPracticeState, arg.Status, arg.FailureReason, arg.SubmittedAt, arg.UpdatedAt, arg.ID, ) if err != nil { return 0, err } return result.RowsAffected(), nil }