135 lines
3.2 KiB
Go
135 lines
3.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: question_options.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type BulkCreateQuestionOptionsParams struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
OptionText string `json:"option_text"`
|
|
OptionOrder int32 `json:"option_order"`
|
|
IsCorrect bool `json:"is_correct"`
|
|
}
|
|
|
|
const CreateQuestionOption = `-- name: CreateQuestionOption :one
|
|
INSERT INTO question_options (
|
|
question_id,
|
|
option_text,
|
|
option_order,
|
|
is_correct
|
|
)
|
|
VALUES ($1, $2, COALESCE($3, 0), COALESCE($4, false))
|
|
RETURNING id, question_id, option_text, option_order, is_correct, created_at
|
|
`
|
|
|
|
type CreateQuestionOptionParams struct {
|
|
QuestionID int64 `json:"question_id"`
|
|
OptionText string `json:"option_text"`
|
|
Column3 interface{} `json:"column_3"`
|
|
Column4 interface{} `json:"column_4"`
|
|
}
|
|
|
|
func (q *Queries) CreateQuestionOption(ctx context.Context, arg CreateQuestionOptionParams) (QuestionOption, error) {
|
|
row := q.db.QueryRow(ctx, CreateQuestionOption,
|
|
arg.QuestionID,
|
|
arg.OptionText,
|
|
arg.Column3,
|
|
arg.Column4,
|
|
)
|
|
var i QuestionOption
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.OptionText,
|
|
&i.OptionOrder,
|
|
&i.IsCorrect,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteOptionsByQuestionID = `-- name: DeleteOptionsByQuestionID :exec
|
|
DELETE FROM question_options
|
|
WHERE question_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteOptionsByQuestionID(ctx context.Context, questionID int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteOptionsByQuestionID, questionID)
|
|
return err
|
|
}
|
|
|
|
const DeleteQuestionOption = `-- name: DeleteQuestionOption :exec
|
|
DELETE FROM question_options
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteQuestionOption(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteQuestionOption, id)
|
|
return err
|
|
}
|
|
|
|
const GetOptionsByQuestionID = `-- name: GetOptionsByQuestionID :many
|
|
SELECT id, question_id, option_text, option_order, is_correct, created_at
|
|
FROM question_options
|
|
WHERE question_id = $1
|
|
ORDER BY option_order
|
|
`
|
|
|
|
func (q *Queries) GetOptionsByQuestionID(ctx context.Context, questionID int64) ([]QuestionOption, error) {
|
|
rows, err := q.db.Query(ctx, GetOptionsByQuestionID, questionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []QuestionOption
|
|
for rows.Next() {
|
|
var i QuestionOption
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.QuestionID,
|
|
&i.OptionText,
|
|
&i.OptionOrder,
|
|
&i.IsCorrect,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateQuestionOption = `-- name: UpdateQuestionOption :exec
|
|
UPDATE question_options
|
|
SET
|
|
option_text = COALESCE($1, option_text),
|
|
option_order = COALESCE($2, option_order),
|
|
is_correct = COALESCE($3, is_correct)
|
|
WHERE id = $4
|
|
`
|
|
|
|
type UpdateQuestionOptionParams struct {
|
|
OptionText string `json:"option_text"`
|
|
OptionOrder int32 `json:"option_order"`
|
|
IsCorrect bool `json:"is_correct"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateQuestionOption(ctx context.Context, arg UpdateQuestionOptionParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateQuestionOption,
|
|
arg.OptionText,
|
|
arg.OptionOrder,
|
|
arg.IsCorrect,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|