Skip to main content

Module validate

Module validate 

Source
Expand description

validate_query_as — the single entry point for query_as! validation.

Algorithm:

  1. Look up struct_name in the registry via get_by_struct; if absent → StructNotRegistered. This returns the SQL table name alongside the entry (struct ident ≠ SQL table name in general).
  2. Run the LIMIT 0 dry-run.
  3. On success: compute name-subset diff (struct fields ⊆ result columns).
  4. On 42P01 (undefined_table): extract the SQL table name from the error, seed from registry if known (then retry once), or emit TablesNotRegistered.
  5. On 42703 (undefined_column) or 42601 (syntax): forward as diagnostics.

§Key design note: struct name vs. table name

The registry is dual-indexed: by SQL table name (for 42P01 seed-and-retry, which receives the SQL name from Hyper) and by Rust struct ident (for the initial lookup, since query_as!(User, …) passes “User”, not “users”). validate_query_as always receives the struct ident; Registry::seed_if_known always receives the SQL table name from Hyper’s error.

No syn/quote/proc-macro2 types in this module’s public API.

Functions§

validate_query_as
Validate that sql is structurally compatible with struct_name.
validate_scalar_sql
Validate a scalar SQL string: runs the dry-run and checks the result projects exactly one column. Used by query_scalar!.