Files
lincodex/backend/internal/adapter/secondary/postgres/sqlc/evidence.sql.go
T

357 lines
11 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: evidence.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const listCandidateEvidenceFacts = `-- name: ListCandidateEvidenceFacts :many
SELECT
fact.id,
fact.kind,
fact.source_type,
fact.event_id,
fact.result_id,
fact.attribution,
fact.trust,
fact.grade,
fact.basis,
fact.calibration_status,
fact.occurred_at,
fact.visibility,
COALESCE(
(
SELECT array_agg(skill.skill_code ORDER BY skill.skill_code)
FROM skill_evidence_skills AS skill
WHERE skill.fact_id = fact.id
),
'{}'::text []
)::text [] AS skills
FROM skill_evidence_facts AS fact
WHERE
fact.candidate_id = $1
AND (
$2::timestamptz IS NULL
OR (fact.occurred_at, fact.id) < (
$2::timestamptz,
$3::uuid
)
)
ORDER BY fact.occurred_at DESC, fact.id DESC
LIMIT $4
`
type ListCandidateEvidenceFactsParams struct {
CandidateID pgtype.UUID
AfterOccurredAt pgtype.Timestamptz
AfterID pgtype.UUID
RowLimit int32
}
type ListCandidateEvidenceFactsRow struct {
ID pgtype.UUID
Kind string
SourceType string
EventID pgtype.UUID
ResultID pgtype.UUID
Attribution string
Trust int16
Grade string
Basis string
CalibrationStatus string
OccurredAt pgtype.Timestamptz
Visibility string
Skills []string
}
// Skill evidence reads. The projection tables hold no answer, score, item,
// failure, or anti-cheat data, and none of these statements names the result,
// attempt, or review tables: evidence is read from its own facts only.
// The candidate's own facts, hidden ones included, newest event first. Every
// statement is scoped by the owner; the caller passes the continuation
// position of the previous page, if any, and fetches one extra row.
func (q *Queries) ListCandidateEvidenceFacts(ctx context.Context, arg ListCandidateEvidenceFactsParams) ([]ListCandidateEvidenceFactsRow, error) {
rows, err := q.db.Query(ctx, listCandidateEvidenceFacts,
arg.CandidateID,
arg.AfterOccurredAt,
arg.AfterID,
arg.RowLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListCandidateEvidenceFactsRow
for rows.Next() {
var i ListCandidateEvidenceFactsRow
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.SourceType,
&i.EventID,
&i.ResultID,
&i.Attribution,
&i.Trust,
&i.Grade,
&i.Basis,
&i.CalibrationStatus,
&i.OccurredAt,
&i.Visibility,
&i.Skills,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listCandidatePreviewEvidence = `-- name: ListCandidatePreviewEvidence :many
SELECT DISTINCT ON (skill.skill_code)
skill.skill_code AS skill,
fact.grade,
fact.trust,
fact.basis,
fact.calibration_status,
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
FROM skill_evidence_facts AS fact
INNER JOIN skill_evidence_skills AS skill
ON fact.id = skill.fact_id
WHERE
fact.candidate_id = $1
AND (skill.skill_code || '/' || fact.grade) = any($2::text [])
AND fact.kind = 'measurement'
AND fact.visibility = 'visible'
ORDER BY skill.skill_code, fact.occurred_at, fact.id
`
type ListCandidatePreviewEvidenceParams struct {
CandidateID pgtype.UUID
Categories []string
}
type ListCandidatePreviewEvidenceRow struct {
Skill string
Grade string
Trust int16
Basis string
CalibrationStatus string
ObservedYear int32
}
// The same selection for the candidate's own card preview, so the candidate
// sees what an organization would read. It is scoped by the owner and runs
// after the caller locked the effective C2 and publication; it does not apply
// an organization or a cohort.
func (q *Queries) ListCandidatePreviewEvidence(ctx context.Context, arg ListCandidatePreviewEvidenceParams) ([]ListCandidatePreviewEvidenceRow, error) {
rows, err := q.db.Query(ctx, listCandidatePreviewEvidence, arg.CandidateID, arg.Categories)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListCandidatePreviewEvidenceRow
for rows.Next() {
var i ListCandidatePreviewEvidenceRow
if err := rows.Scan(
&i.Skill,
&i.Grade,
&i.Trust,
&i.Basis,
&i.CalibrationStatus,
&i.ObservedYear,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOrganizationVisibleEvidence = `-- name: ListOrganizationVisibleEvidence :many
SELECT DISTINCT ON (skill.skill_code)
skill.skill_code AS skill,
fact.grade,
fact.trust,
fact.basis,
fact.calibration_status,
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
FROM candidate_effective_publications AS effective
INNER JOIN skill_evidence_facts AS fact
ON effective.user_id = fact.candidate_id
INNER JOIN skill_evidence_skills AS skill
ON fact.id = skill.fact_id
WHERE
effective.user_id = $1
AND 'categories' = any(effective.fields)
AND (skill.skill_code || '/' || fact.grade) = any($2::text [])
AND fact.kind = 'measurement'
AND fact.visibility = 'visible'
AND NOT EXISTS (
SELECT 1
FROM candidate_hidden_organizations AS hidden
WHERE
hidden.user_id = effective.user_id
AND hidden.organization_id = $3
)
ORDER BY skill.skill_code, fact.occurred_at, fact.id
`
type ListOrganizationVisibleEvidenceParams struct {
CandidateID pgtype.UUID
Categories []string
OrganizationID pgtype.UUID
}
type ListOrganizationVisibleEvidenceRow struct {
Skill string
Grade string
Trust int16
Basis string
CalibrationStatus string
ObservedYear int32
}
// The evidence that one organization may read about one candidate: one fact
// for each category of the card, the fact that supports the confirmed grade
// of that category (the earliest one that passed exactly that grade, so a
// lower grade or a retake adds nothing). The statement selects from the
// effective publication view (published and backed by an unrevoked C2) and
// excludes the candidates that hide the reading organization, so no row means
// nothing to read, whatever the reason. The card must publish the categories
// field and only visible measurements qualify. The categories come from the
// caller as "specialization/grade" pairs taken from the card that was just
// projected, so the answer never names a skill the card does not show. The columns are
// an allowlist: no identifier of the fact, the event, the result, or the
// candidate leaves, the instant is cut to the year, and the basis and the
// calibration (the same for every candidate) say that the fact is a synthetic
// demonstration.
func (q *Queries) ListOrganizationVisibleEvidence(ctx context.Context, arg ListOrganizationVisibleEvidenceParams) ([]ListOrganizationVisibleEvidenceRow, error) {
rows, err := q.db.Query(ctx, listOrganizationVisibleEvidence, arg.CandidateID, arg.Categories, arg.OrganizationID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListOrganizationVisibleEvidenceRow
for rows.Next() {
var i ListOrganizationVisibleEvidenceRow
if err := rows.Scan(
&i.Skill,
&i.Grade,
&i.Trust,
&i.Basis,
&i.CalibrationStatus,
&i.ObservedYear,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listOrganizationVisibleEvidenceBatch = `-- name: ListOrganizationVisibleEvidenceBatch :many
SELECT DISTINCT ON (wanted.candidate_id, skill.skill_code)
wanted.candidate_id::uuid AS candidate_id,
skill.skill_code AS skill,
fact.grade,
fact.trust,
fact.basis,
fact.calibration_status,
extract(YEAR FROM fact.occurred_at AT TIME ZONE 'UTC')::integer AS observed_year
FROM (
SELECT
candidate_ids.candidate_id,
wanted_categories.category
FROM unnest($1::uuid []) WITH ORDINALITY AS candidate_ids (candidate_id, position)
INNER JOIN unnest($2::text []) WITH ORDINALITY AS wanted_categories (category, position)
ON candidate_ids.position = wanted_categories.position
) AS wanted
INNER JOIN candidate_effective_publications AS effective
ON wanted.candidate_id = effective.user_id
INNER JOIN skill_evidence_facts AS fact
ON effective.user_id = fact.candidate_id
INNER JOIN skill_evidence_skills AS skill
ON fact.id = skill.fact_id
WHERE
'categories' = any(effective.fields)
AND (skill.skill_code || '/' || fact.grade) = wanted.category
AND fact.kind = 'measurement'
AND fact.visibility = 'visible'
AND NOT EXISTS (
SELECT 1
FROM candidate_hidden_organizations AS hidden
WHERE
hidden.user_id = effective.user_id
AND hidden.organization_id = $3
)
ORDER BY wanted.candidate_id, skill.skill_code, fact.occurred_at, fact.id
`
type ListOrganizationVisibleEvidenceBatchParams struct {
CandidateIds []pgtype.UUID
Categories []string
OrganizationID pgtype.UUID
}
type ListOrganizationVisibleEvidenceBatchRow struct {
CandidateID pgtype.UUID
Skill string
Grade string
Trust int16
Basis string
CalibrationStatus string
ObservedYear int32
}
// The same organization read for a whole candidate set, so a search reads the
// evidence of every listed candidate in one statement. The pairs come from the
// caller as two parallel arrays, one row per candidate and category of the card
// that was just projected. The statement repeats every barrier of the single
// read: the effective publication view, NOT EXISTS over the candidates that
// hide the organization, the categories field, and only visible measurements.
// The candidate identifier is returned for the caller to group by and never
// leaves the server; the other columns are the same allowlist.
func (q *Queries) ListOrganizationVisibleEvidenceBatch(ctx context.Context, arg ListOrganizationVisibleEvidenceBatchParams) ([]ListOrganizationVisibleEvidenceBatchRow, error) {
rows, err := q.db.Query(ctx, listOrganizationVisibleEvidenceBatch, arg.CandidateIds, arg.Categories, arg.OrganizationID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListOrganizationVisibleEvidenceBatchRow
for rows.Next() {
var i ListOrganizationVisibleEvidenceBatchRow
if err := rows.Scan(
&i.CandidateID,
&i.Skill,
&i.Grade,
&i.Trust,
&i.Basis,
&i.CalibrationStatus,
&i.ObservedYear,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}