-- Real attempts in ascending identifier order, so that a caller can walk all of -- them in pages. Only the identifier and the time span are read. -- name: ListAssessmentTraceAttempts :many SELECT id, created_at, expires_at FROM assessment_attempts WHERE kind IN ('root', 'corrective') AND id > sqlc.arg(after_id) ORDER BY id LIMIT sqlc.arg(row_limit); -- The unmarked statements of real attempts whose text, with runs of white space -- collapsed, contains the fragment. The fragment is matched literally: position -- is not a pattern. The scan reads the stored variant of every item, which is -- fine for an operator command and not for a request path. -- name: FindAssessmentTraceStatements :many SELECT item.attempt_id, (item.variant ->> 'Statement')::text AS statement FROM assessment_attempt_items AS item INNER JOIN assessment_attempts AS attempt ON item.attempt_id = attempt.id WHERE attempt.kind IN ('root', 'corrective') AND position(sqlc.arg(fragment)::text IN regexp_replace((item.variant ->> 'Statement')::text, '\s+', ' ', 'g')) > 0 ORDER BY item.attempt_id, item.ordinal LIMIT sqlc.arg(row_limit); -- name: InsertAssessmentLeakTrace :exec INSERT INTO assessment_leak_traces ( id, actor, searched_at, text_digest, key_version, text_runes, status, method, attempt_id, candidates, evidence_bits ) VALUES ( sqlc.arg(id), sqlc.arg(actor), sqlc.arg(searched_at), sqlc.arg(text_digest), sqlc.arg(key_version), sqlc.arg(text_runes), sqlc.arg(status), sqlc.narg(method), sqlc.narg(attempt_id), sqlc.arg(candidates), sqlc.arg(evidence_bits) );