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, AlterViewAction, AlterViewKind, AlterViewStmt, DeleteStmt,
16    DropKind, DropStmt, Expr, Statement, TableKeyConstraint, TableKeyConstraintKind,
17    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::{
41    compile, plan_only_for_test, resolve_deferred_create_foreign_table,
42    resolve_deferred_create_table,
43};
44pub use types::{
45    parse_regobject_name, parse_regprocedure_name, parse_regtype_name, ParsedRegprocedureName,
46    ParsedRegtypeName,
47};
48
49pub(crate) fn compile_pg_expression(node: &Node) -> Result<Expr> {
50    compile_expr(node)
51}
52
53pub(crate) fn compile_pg_projections(nodes: &[Node]) -> Result<Vec<crate::ast::Projection>> {
54    compile_projections(nodes)
55}
56
57pub(crate) fn compile_pg_select(
58    select: &pg_query::protobuf::SelectStmt,
59) -> Result<crate::ast::SelectStmt> {
60    compile_select(select)
61}
62
63pub(in crate::compiler) use hierarchy::compile_table_hierarchy;
64use names::render_relation_component;
65pub(super) use names::{
66    compile_on_commit, compile_qualified_name, range_var_name, relation_persistence,
67    validate_create_table_envelope,
68};
69pub(in crate::compiler) use returning::compile_returning_clause;
70
71use tree::{
72    compile_column_def, compile_create_index, compile_create_table, compile_expr,
73    compile_from_node, compile_insert, compile_projections, compile_select, compile_values_lists,
74    compile_with_clause, extract_string,
75};
76
77#[cfg(test)]
78mod tests;