207 lines
4.5 KiB
Go
207 lines
4.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: questions.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const attachTagToQuestion = `-- name: AttachTagToQuestion :exec
|
|
INSERT INTO question_tags (
|
|
question_id,
|
|
tag_id
|
|
) VALUES (
|
|
$1,
|
|
$2
|
|
)
|
|
ON CONFLICT (question_id, tag_id) DO NOTHING
|
|
`
|
|
|
|
type AttachTagToQuestionParams struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
TagID int64 `json:"tag_id"`
|
|
}
|
|
|
|
func (q *Queries) AttachTagToQuestion(ctx context.Context, arg AttachTagToQuestionParams) error {
|
|
_, err := q.db.Exec(ctx, attachTagToQuestion, arg.QuestionID, arg.TagID)
|
|
return err
|
|
}
|
|
|
|
const createQuestion = `-- name: CreateQuestion :one
|
|
INSERT INTO questions (
|
|
author_teacher_id,
|
|
title,
|
|
prompt,
|
|
topic,
|
|
subject,
|
|
difficulty,
|
|
source,
|
|
status,
|
|
correct_answer
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9
|
|
)
|
|
RETURNING id, author_teacher_id, title, prompt, subject, source, status, created_at, updated_at, correct_answer, topic, difficulty
|
|
`
|
|
|
|
type CreateQuestionParams struct {
|
|
AuthorTeacherID int64 `json:"author_teacher_id"`
|
|
Title string `json:"title"`
|
|
Prompt string `json:"prompt"`
|
|
Topic NullQuestionTopic `json:"topic"`
|
|
Subject pgtype.Text `json:"subject"`
|
|
Difficulty NullQuestionDifficulty `json:"difficulty"`
|
|
Source pgtype.Text `json:"source"`
|
|
Status QuestionStatus `json:"status"`
|
|
CorrectAnswer pgtype.Text `json:"correct_answer"`
|
|
}
|
|
|
|
func (q *Queries) CreateQuestion(ctx context.Context, arg CreateQuestionParams) (Question, error) {
|
|
row := q.db.QueryRow(ctx, createQuestion,
|
|
arg.AuthorTeacherID,
|
|
arg.Title,
|
|
arg.Prompt,
|
|
arg.Topic,
|
|
arg.Subject,
|
|
arg.Difficulty,
|
|
arg.Source,
|
|
arg.Status,
|
|
arg.CorrectAnswer,
|
|
)
|
|
var i Question
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.AuthorTeacherID,
|
|
&i.Title,
|
|
&i.Prompt,
|
|
&i.Subject,
|
|
&i.Source,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CorrectAnswer,
|
|
&i.Topic,
|
|
&i.Difficulty,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createTag = `-- name: CreateTag :one
|
|
INSERT INTO tags (name)
|
|
VALUES ($1)
|
|
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
|
|
RETURNING id, name, created_at
|
|
`
|
|
|
|
func (q *Queries) CreateTag(ctx context.Context, name string) (Tag, error) {
|
|
row := q.db.QueryRow(ctx, createTag, name)
|
|
var i Tag
|
|
err := row.Scan(&i.ID, &i.Name, &i.CreatedAt)
|
|
return i, err
|
|
}
|
|
|
|
const getQuestionByID = `-- name: GetQuestionByID :one
|
|
SELECT id, author_teacher_id, title, prompt, subject, source, status, created_at, updated_at, correct_answer, topic, difficulty
|
|
FROM questions
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetQuestionByID(ctx context.Context, id int64) (Question, error) {
|
|
row := q.db.QueryRow(ctx, getQuestionByID, id)
|
|
var i Question
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.AuthorTeacherID,
|
|
&i.Title,
|
|
&i.Prompt,
|
|
&i.Subject,
|
|
&i.Source,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CorrectAnswer,
|
|
&i.Topic,
|
|
&i.Difficulty,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listQuestionsByTeacher = `-- name: ListQuestionsByTeacher :many
|
|
SELECT id, author_teacher_id, title, prompt, subject, source, status, created_at, updated_at, correct_answer, topic, difficulty
|
|
FROM questions
|
|
WHERE author_teacher_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListQuestionsByTeacher(ctx context.Context, authorTeacherID int64) ([]Question, error) {
|
|
rows, err := q.db.Query(ctx, listQuestionsByTeacher, authorTeacherID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Question{}
|
|
for rows.Next() {
|
|
var i Question
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.AuthorTeacherID,
|
|
&i.Title,
|
|
&i.Prompt,
|
|
&i.Subject,
|
|
&i.Source,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.CorrectAnswer,
|
|
&i.Topic,
|
|
&i.Difficulty,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTags = `-- name: ListTags :many
|
|
SELECT id, name, created_at
|
|
FROM tags
|
|
ORDER BY name ASC
|
|
`
|
|
|
|
func (q *Queries) ListTags(ctx context.Context) ([]Tag, error) {
|
|
rows, err := q.db.Query(ctx, listTags)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Tag{}
|
|
for rows.Next() {
|
|
var i Tag
|
|
if err := rows.Scan(&i.ID, &i.Name, &i.CreatedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|