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