Expand description
Multi-table JOIN support scaffolding.
This module introduces two helpers that per-dialect parsers (postgres, mysql, sqlite) can call when they detect a JOIN in a query:
AliasMap— a lookup from alias-or-table-name to aTableDefreference, built by scanning the FROM/JOIN clauses.parse_join_clauses— walks a query’s FROM clause, returning the alias map. Errors on OUTER/USING/NATURAL joins with a pointer to the v1.2 roadmap.resolve_multi_table_select_column— given a qualified select expression likeusers.idoru.name AS username, look up the table and column in the alias map and return a fully-typedColumnDefwithsource_tablepopulated.
The helpers are not yet wired into any dialect parser. The existing
ensure_supported_select_expr
guard still rejects qualified selects in every dialect. A follow-up PR
per dialect (postgres, mysql, sqlite) will flip each to call into
these helpers when JOIN clauses are present.
Scope for v1.1: INNER JOIN only, qualified columns only, no SELECT *
across joins. OUTER JOIN nullability propagation, USING, NATURAL
JOIN, lateral joins, and self-joins with aliases are v1.2 work — they
would require ColumnDef.nullable to become per-query-context rather
than per-schema.
Structs§
- Alias
Map - Maps alias (or bare table name) to the underlying
TableDef. Both the alias and the table name are valid qualifiers for a column, so both are stored when an alias is present.
Functions§
- has_
outer_ join - Returns true if the query’s outer FROM clause contains a JOIN.
Run this instead of matching
\bJOIN\bagainst the full SQL — matching against the full SQL false-positives on JOINs inside subqueries. - parse_
join_ clauses - Walk a query’s FROM clause and return the alias → table mapping. Returns an empty map (no join detected) when the query has no FROM clause. Returns an error for OUTER / USING / NATURAL / CROSS joins with a message pointing to the v1.2 roadmap.
- resolve_
multi_ table_ columns - Resolve a SELECT column list against a multi-table JOIN context.
Shared across dialect parsers (postgres, mysql, sqlite): they detect
the JOIN via
has_outer_join, pull the columns-part out of the SELECT, and call this function to build the typedColumnDeflist. - resolve_
multi_ table_ select_ column - Resolve a qualified select expression (like
users.idoru.name AS username) against anAliasMap. Returns a fully-typedColumnDefwithsource_tablepopulated so codegen can disambiguate colliding names.