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, ColumnDef, DeleteStmt, DropKind, DropStmt, Expr, Statement,
16    TableKeyConstraint, TableKeyConstraintKind, TransactionStmt, UpdateStmt,
17};
18use crate::error::{Result, SQLError};
19use pg_query::protobuf::{Node, RangeVar};
20use pg_query::NodeEnum;
21use types::compile_pg_type_name;
22
23mod administrative;
24mod dispatch;
25mod dml;
26mod drop_alter;
27mod merge;
28mod names;
29mod relations;
30mod returning;
31mod routines;
32mod sequences;
33mod tree;
34mod types;
35
36pub use dispatch::{compile, plan_only_for_test};
37
38pub(crate) fn compile_pg_expression(node: &Node) -> Result<Expr> {
39    compile_expr(node)
40}
41
42pub(crate) fn compile_pg_projections(nodes: &[Node]) -> Result<Vec<crate::ast::Projection>> {
43    compile_projections(nodes)
44}
45
46use names::render_relation_component;
47pub(super) use names::{
48    compile_qualified_name, range_var_name, validate_create_table_envelope,
49    validate_durable_create_relation,
50};
51pub(in crate::compiler) use returning::compile_returning_clause;
52
53use tree::{
54    compile_column_def, compile_create_index, compile_create_table, compile_expr,
55    compile_from_node, compile_insert, compile_projections, compile_select, compile_values_lists,
56    compile_with_clause, extract_string,
57};
58
59#[cfg(test)]
60mod tests;