Skip to main content

alopex_sql/
lib.rs

1//! SQL parser and planning components for the Alopex DB SQL dialect.
2//!
3//! This crate provides:
4//!
5//! - **Parser**: SQL parsing into an AST via the Nim FFI parser
6//! - **Catalog**: Table and index metadata management
7//! - **Planner**: AST to logical plan conversion with type checking
8//!
9//! # Quick Start
10//!
11//! ```
12//! use alopex_sql::{Parser, AlopexDialect};
13//! use alopex_sql::catalog::MemoryCatalog;
14//! use alopex_sql::planner::Planner;
15//!
16//! // Parse SQL using the convenience method
17//! let sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)";
18//! let dialect = AlopexDialect::default();
19//! let stmts = Parser::parse_sql(&dialect, sql).unwrap();
20//! let stmt = &stmts[0];
21//!
22//! // Plan with catalog
23//! let catalog = MemoryCatalog::new();
24//! let planner = Planner::new(&catalog);
25//! let plan = planner.plan(stmt).unwrap();
26//! ```
27
28pub mod ast;
29#[cfg(feature = "async")]
30pub mod async_api;
31pub mod catalog;
32pub mod columnar;
33pub mod dialect;
34pub mod error;
35pub mod executor;
36mod nim_bridge;
37mod nim_ffi;
38pub mod parser;
39pub mod planner;
40pub mod storage;
41#[cfg(all(feature = "tokio", not(target_arch = "wasm32")))]
42pub mod tokio_adapter;
43pub mod unified_error;
44
45// AST types
46pub use ast::{
47    Statement, StatementKind,
48    ddl::*,
49    dml::*,
50    expr::*,
51    span::{Location, Span, Spanned},
52};
53
54// Dialect and parser types
55pub use dialect::{AlopexDialect, Dialect};
56pub use error::{ParserError, Result};
57pub use parser::Parser;
58pub use unified_error::SqlError;
59
60// Catalog types (re-exported for convenience)
61pub use catalog::persistent::{CatalogOverlay, DataSourceFormat, TableType};
62pub use catalog::{
63    Catalog, ColumnMetadata, Compression, IndexMetadata, MemoryCatalog, RowIdMode, StorageOptions,
64    StorageType, TableMetadata,
65};
66
67// Planner types (re-exported for convenience)
68pub use planner::{
69    LogicalPlan, NameResolver, PlannedStatement, Planner, PlannerError, PlanningDiagnostic,
70    PlanningDiagnosticSeverity, ProjectedColumn, Projection, ResolvedColumn, ResolvedType,
71    RoutingInput, SortExpr, TableReference, TableReferenceAccess, TableReferenceExtractor,
72    TableReferenceSource, TypeChecker, TypedAssignment, TypedExpr, TypedExprKind,
73    plan_sql_for_routing, plan_statement_for_routing,
74};
75
76// Storage types
77#[cfg(feature = "tokio")]
78pub use storage::ErasedAsyncSqlTransaction;
79pub use storage::{
80    IndexScanIterator, IndexStorage, KeyEncoder, RowCodec, SqlTransaction, SqlValue, StorageError,
81    TableScanIterator, TableStorage, TxnBridge, TxnContext,
82};
83
84// Executor types
85#[cfg(feature = "tokio")]
86pub use executor::AsyncExecutor;
87pub use executor::{
88    ColumnInfo, ConstraintViolation, EvaluationError, ExecutionResult, Executor, ExecutorError,
89    QueryResult, Row,
90};
91
92// Async facade types
93#[cfg(feature = "async")]
94pub use async_api::{AsyncResult, AsyncRowStream, AsyncSqlTransaction, AsyncTxnBridge};
95#[cfg(all(feature = "tokio", not(target_arch = "wasm32")))]
96pub use tokio_adapter::{TokioAsyncSqlTransaction, TokioAsyncTxnBridge};
97
98/// `ExecutionResult` の公開 API 名。
99pub type SqlResult = ExecutionResult;
100
101#[cfg(test)]
102mod integration;