90 lines
1.8 KiB
Go
90 lines
1.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: questions.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createQuestion = `-- name: CreateQuestion :one
|
|
INSERT INTO questions (form_id, type, title, required, position)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id, form_id, type, title, required, position
|
|
`
|
|
|
|
type CreateQuestionParams struct {
|
|
FormID uuid.UUID
|
|
Type QuestionType
|
|
Title string
|
|
Required bool
|
|
Position int32
|
|
}
|
|
|
|
func (q *Queries) CreateQuestion(ctx context.Context, arg CreateQuestionParams) (Question, error) {
|
|
row := q.db.QueryRow(ctx, createQuestion,
|
|
arg.FormID,
|
|
arg.Type,
|
|
arg.Title,
|
|
arg.Required,
|
|
arg.Position,
|
|
)
|
|
var i Question
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FormID,
|
|
&i.Type,
|
|
&i.Title,
|
|
&i.Required,
|
|
&i.Position,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteQuestionsByFormID = `-- name: DeleteQuestionsByFormID :exec
|
|
DELETE FROM questions
|
|
WHERE form_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteQuestionsByFormID(ctx context.Context, formID uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteQuestionsByFormID, formID)
|
|
return err
|
|
}
|
|
|
|
const getQuestionsByFormID = `-- name: GetQuestionsByFormID :many
|
|
SELECT id, form_id, type, title, required, position FROM questions
|
|
WHERE form_id = $1
|
|
ORDER BY position ASC
|
|
`
|
|
|
|
func (q *Queries) GetQuestionsByFormID(ctx context.Context, formID uuid.UUID) ([]Question, error) {
|
|
rows, err := q.db.Query(ctx, getQuestionsByFormID, formID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Question
|
|
for rows.Next() {
|
|
var i Question
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FormID,
|
|
&i.Type,
|
|
&i.Title,
|
|
&i.Required,
|
|
&i.Position,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|