first commit
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: question_options.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createQuestionOption = `-- name: CreateQuestionOption :one
|
||||
INSERT INTO question_options (form_id, question_id, label, position)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, form_id, question_id, label, position
|
||||
`
|
||||
|
||||
type CreateQuestionOptionParams struct {
|
||||
FormID uuid.UUID
|
||||
QuestionID uuid.UUID
|
||||
Label string
|
||||
Position int32
|
||||
}
|
||||
|
||||
func (q *Queries) CreateQuestionOption(ctx context.Context, arg CreateQuestionOptionParams) (QuestionOption, error) {
|
||||
row := q.db.QueryRow(ctx, createQuestionOption,
|
||||
arg.FormID,
|
||||
arg.QuestionID,
|
||||
arg.Label,
|
||||
arg.Position,
|
||||
)
|
||||
var i QuestionOption
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.FormID,
|
||||
&i.QuestionID,
|
||||
&i.Label,
|
||||
&i.Position,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteOptionsByFormID = `-- name: DeleteOptionsByFormID :exec
|
||||
DELETE FROM question_options
|
||||
WHERE form_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteOptionsByFormID(ctx context.Context, formID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteOptionsByFormID, formID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getOptionsByFormID = `-- name: GetOptionsByFormID :many
|
||||
SELECT id, form_id, question_id, label, position FROM question_options
|
||||
WHERE form_id = $1
|
||||
ORDER BY question_id, position ASC
|
||||
`
|
||||
|
||||
func (q *Queries) GetOptionsByFormID(ctx context.Context, formID uuid.UUID) ([]QuestionOption, error) {
|
||||
rows, err := q.db.Query(ctx, getOptionsByFormID, formID)
|
||||
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.FormID,
|
||||
&i.QuestionID,
|
||||
&i.Label,
|
||||
&i.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getOptionsByQuestionID = `-- name: GetOptionsByQuestionID :many
|
||||
SELECT id, form_id, question_id, label, position FROM question_options
|
||||
WHERE form_id = $1 AND question_id = $2
|
||||
ORDER BY position ASC
|
||||
`
|
||||
|
||||
type GetOptionsByQuestionIDParams struct {
|
||||
FormID uuid.UUID
|
||||
QuestionID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) GetOptionsByQuestionID(ctx context.Context, arg GetOptionsByQuestionIDParams) ([]QuestionOption, error) {
|
||||
rows, err := q.db.Query(ctx, getOptionsByQuestionID, arg.FormID, arg.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.FormID,
|
||||
&i.QuestionID,
|
||||
&i.Label,
|
||||
&i.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user