RezinaLMS-BackEnd/db/query/question_options.sql
Yared Yemane eb1d0c68e2 Speed up API paths with batch question loads, request memoization, and soft caches.
Also replace question options on update so placement grading stays consistent with admin edits, and tune the Postgres pool defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-01 00:06:43 -07:00

46 lines
1.0 KiB
SQL

-- 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 *;
-- name: GetOptionsByQuestionID :many
SELECT *
FROM question_options
WHERE question_id = $1
ORDER BY option_order;
-- name: GetOptionsByQuestionIDs :many
SELECT *
FROM question_options
WHERE question_id = ANY($1::BIGINT[])
ORDER BY question_id, option_order;
-- 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;
-- name: DeleteQuestionOption :exec
DELETE FROM question_options
WHERE id = $1;
-- name: DeleteOptionsByQuestionID :exec
DELETE FROM question_options
WHERE question_id = $1;
-- name: BulkCreateQuestionOptions :copyfrom
INSERT INTO question_options (
question_id,
option_text,
option_order,
is_correct
) VALUES ($1, $2, $3, $4);