sqlode/query_ir
Intermediate representation shared between the query parser and the
query analyzer. TokenizedQuery carries the expanded token list
alongside the ParsedQuery metadata so analyzer layers can walk
tokens without re-tokenizing the SQL string on every pass.
StructuredQuery adds a thin structural layer that identifies the
statement kind and its major clauses (tables, SELECT items, WHERE
predicates, etc.) so inference passes can consume pre-parsed
structure instead of re-scanning the raw token list.
Types
A table or subquery in the FROM clause.
pub type FromItem {
TableRef(name: String, alias: option.Option(String))
SubqueryRef(
tokens: List(lexer.Token),
alias: option.Option(String),
)
}
Constructors
-
TableRef(name: String, alias: option.Option(String)) -
SubqueryRef( tokens: List(lexer.Token), alias: option.Option(String), )
A JOIN clause.
pub type JoinClause {
JoinClause(
table_name: String,
alias: option.Option(String),
on_tokens: option.Option(List(lexer.Token)),
)
}
Constructors
-
JoinClause( table_name: String, alias: option.Option(String), on_tokens: option.Option(List(lexer.Token)), )
A single item in a SELECT list.
pub type SelectItem {
StarItem(table_prefix: option.Option(String))
ExpressionItem(
tokens: List(lexer.Token),
alias: option.Option(String),
)
}
Constructors
-
StarItem(table_prefix: option.Option(String))*ortable.* -
ExpressionItem( tokens: List(lexer.Token), alias: option.Option(String), )An expression, possibly aliased
Top-level statement structure extracted from the token list.
pub type SqlStatement {
SelectStatement(
select_items: List(SelectItem),
from: List(FromItem),
joins: List(JoinClause),
where_tokens: option.Option(List(lexer.Token)),
group_by_tokens: option.Option(List(lexer.Token)),
having_tokens: option.Option(List(lexer.Token)),
order_by_tokens: option.Option(List(lexer.Token)),
limit_tokens: option.Option(List(lexer.Token)),
)
InsertStatement(
table_name: String,
columns: List(String),
value_groups: List(List(lexer.Token)),
returning_tokens: option.Option(List(lexer.Token)),
)
UpdateStatement(
table_name: String,
set_tokens: List(lexer.Token),
where_tokens: option.Option(List(lexer.Token)),
returning_tokens: option.Option(List(lexer.Token)),
)
DeleteStatement(
table_name: String,
where_tokens: option.Option(List(lexer.Token)),
returning_tokens: option.Option(List(lexer.Token)),
)
UnstructuredStatement(tokens: List(lexer.Token))
}
Constructors
-
SelectStatement( select_items: List(SelectItem), from: List(FromItem), joins: List(JoinClause), where_tokens: option.Option(List(lexer.Token)), group_by_tokens: option.Option(List(lexer.Token)), having_tokens: option.Option(List(lexer.Token)), order_by_tokens: option.Option(List(lexer.Token)), limit_tokens: option.Option(List(lexer.Token)), ) -
InsertStatement( table_name: String, columns: List(String), value_groups: List(List(lexer.Token)), returning_tokens: option.Option(List(lexer.Token)), ) -
UpdateStatement( table_name: String, set_tokens: List(lexer.Token), where_tokens: option.Option(List(lexer.Token)), returning_tokens: option.Option(List(lexer.Token)), ) -
DeleteStatement( table_name: String, where_tokens: option.Option(List(lexer.Token)), returning_tokens: option.Option(List(lexer.Token)), ) -
UnstructuredStatement(tokens: List(lexer.Token))Fallback for statements that don’t match the above patterns.
StructuredQuery wraps TokenizedQuery with the structured IR.
The raw token list is preserved for backward compatibility with
code that hasn’t migrated to the structured representation yet.
pub type StructuredQuery {
StructuredQuery(
base: model.ParsedQuery,
tokens: List(lexer.Token),
statement: SqlStatement,
)
}
Constructors
-
StructuredQuery( base: model.ParsedQuery, tokens: List(lexer.Token), statement: SqlStatement, )
pub type TokenizedQuery {
TokenizedQuery(
base: model.ParsedQuery,
tokens: List(lexer.Token),
)
}
Constructors
-
TokenizedQuery( base: model.ParsedQuery, tokens: List(lexer.Token), )