Skip to main content

uqa_sql/
compiler.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Lift a `PostgreSQL` parse tree into the internal [`Statement`] AST.
8//!
9//! The facade exposes compilation while statement-family modules own
10//! validation and lowering. Tree-shaped SELECT/DDL/expression lowering remains
11//! in the private `tree` module, and `PostgreSQL` type interpretation remains
12//! in the private `types` module.
13
14use crate::ast::{
15    AlterTableAction, AlterTableStmt, AlterViewKind, AlterViewOptionsAction, AlterViewOptionsStmt,
16    ColumnDef, DeleteStmt, DropKind, DropStmt, Expr, Statement, TableKeyConstraint,
17    TableKeyConstraintKind, TransactionStmt, UpdateStmt,
18};
19use crate::error::{Result, SQLError};
20use pg_query::protobuf::{Node, RangeVar};
21use pg_query::NodeEnum;
22use types::compile_pg_type_name;
23
24mod administrative;
25mod cursors;
26mod dispatch;
27mod dml;
28mod drop_alter;
29mod events;
30mod hierarchy;
31mod merge;
32mod names;
33mod relations;
34mod returning;
35mod routines;
36mod sequences;
37mod tree;
38mod types;
39
40pub use dispatch::{compile, plan_only_for_test};
41
42pub(crate) fn compile_pg_expression(node: &Node) -> Result<Expr> {
43    compile_expr(node)
44}
45
46pub(crate) fn compile_pg_projections(nodes: &[Node]) -> Result<Vec<crate::ast::Projection>> {
47    compile_projections(nodes)
48}
49
50pub(crate) fn compile_pg_select(
51    select: &pg_query::protobuf::SelectStmt,
52) -> Result<crate::ast::SelectStmt> {
53    compile_select(select)
54}
55
56pub(in crate::compiler) use hierarchy::compile_table_hierarchy;
57use names::render_relation_component;
58pub(super) use names::{
59    compile_on_commit, compile_qualified_name, range_var_name, relation_persistence,
60    validate_create_table_envelope,
61};
62pub(in crate::compiler) use returning::compile_returning_clause;
63
64use tree::{
65    compile_column_def, compile_create_index, compile_create_table, compile_expr,
66    compile_from_node, compile_insert, compile_projections, compile_select, compile_values_lists,
67    compile_with_clause, extract_string,
68};
69
70#[cfg(test)]
71mod tests;