sqlode/query_validation

Post-parse query validation shared by generate and verify.

These checks reject configurations that would otherwise reach the codegen stage in a state the generator cannot express safely. Centralising them here means verify and generate reach the same verdict for any given config: verify can be used as a trustworthy pre-generation CI gate, and the checks cannot drift apart again by accident.

Types

A problem a post-parse check surfaced. Callers wrap the variant in their own error type (a GenerateError for the generator, a Finding string for the verifier) so the shared diagnostic text stays identical across commands.

pub type ValidationError {
  DuplicateName(name: String, paths: List(String))
  NormalizedNameCollision(
    function_name: String,
    names: List(String),
    paths: List(String),
  )
  UnsupportedAnnotation(
    query_name: String,
    command: String,
    detail: String,
  )
  UnsupportedArrayForEngine(query_name: String, engine: String)
}

Constructors

  • DuplicateName(name: String, paths: List(String))
  • NormalizedNameCollision(
      function_name: String,
      names: List(String),
      paths: List(String),
    )
  • UnsupportedAnnotation(
      query_name: String,
      command: String,
      detail: String,
    )
  • UnsupportedArrayForEngine(query_name: String, engine: String)

Values

pub fn error_to_string(error: ValidationError) -> String
pub fn validate_array_engine_support(
  engine: model.Engine,
  queries: List(model.AnalyzedQuery),
) -> Result(Nil, ValidationError)

Reject array parameters for engines that cannot carry them. Only PostgreSQL supports native array binding at the adapter layer today.

pub fn validate_native_annotations(
  queries: List(model.AnalyzedQuery),
) -> Result(Nil, ValidationError)

Reject annotations that clash with the native runtime. Call only when the block targets the native runtime; raw-runtime projects can still emit :execresult and should not be filtered by this check.

pub fn validate_no_duplicate_names(
  queries: List(query_ir.TokenizedQuery),
) -> Result(Nil, ValidationError)

Reject two tokenized queries that declare the same annotation name, or whose names normalize to the same Gleam identifier (the snake_case function_name that queries/params/decoders are derived from). Either shape would leave the generator emitting duplicate declarations and fail the Gleam compile. Literal duplicates are reported first so operators see the simpler diagnostic when both cases hit at once.

pub fn validate_unsupported_annotations(
  queries: List(model.AnalyzedQuery),
) -> Result(Nil, ValidationError)

Reject annotations that are not yet supported by any codegen path (:batchone, :batchmany, :batchexec, :copyfrom). The failure names a supported alternative so operators can fix the annotation without digging through docs.

Search Document