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 domains;
29mod drop_alter;
30mod events;
31mod hierarchy;
32mod merge;
33mod names;
34mod relations;
35mod returning;
36mod routines;
37mod sequences;
38mod tree;
39mod types;
40
41pub use dispatch::{
42    compile, parse_statements, plan_only_for_test, resolve_deferred_create_foreign_table,
43    resolve_deferred_create_table, ParsedStatement,
44};
45pub use types::{
46    parse_regobject_name, parse_regprocedure_name, parse_regtype_name, ParsedRegprocedureName,
47    ParsedRegtypeName,
48};
49
50pub(crate) fn compile_pg_expression(node: &Node) -> Result<Expr> {
51    compile_expr(node)
52}
53
54pub(crate) fn compile_pg_projections(nodes: &[Node]) -> Result<Vec<crate::ast::Projection>> {
55    compile_projections(nodes)
56}
57
58pub(crate) fn compile_pg_select(
59    select: &pg_query::protobuf::SelectStmt,
60) -> Result<crate::ast::SelectStmt> {
61    compile_select(select)
62}
63
64pub(in crate::compiler) use hierarchy::compile_table_hierarchy;
65pub(crate) use names::render_relation_component;
66pub(super) use names::{
67    compile_on_commit, compile_qualified_name, range_var_name, relation_persistence,
68    validate_create_table_envelope,
69};
70pub(in crate::compiler) use returning::compile_returning_clause;
71
72use tree::{
73    compile_column_def, compile_create_index, compile_create_table, compile_expr,
74    compile_from_node, compile_insert, compile_projections, compile_select, compile_values_lists,
75    compile_with_clause, extract_string,
76};
77
78#[cfg(test)]
79mod tests;