audb-codegen 0.1.11

Code generation for AuDB compile-time database applications
//! HyperQL → Manifold Query Compiler
//!
//! This module compiles HyperQL queries from gold files into optimized Rust code
//! that calls Manifold APIs directly. No runtime query parsing or interpretation.
//!
//! ## Compilation Pipeline
//!
//! ```text
//! Gold File Query Block
//!//! Parse HyperQL Source
//!//! HyperQL AST (Statement)
//!//! Pattern Recognition
//!//! Manifold Code Generation
//!//! Generated Rust Code (TokenStream)
//! ```
//!
//! ## Supported Query Patterns
//!
//! - **Point Query**: `SELECT * WHERE id = :param` → `Entity::get()`
//! - **Filter Query**: `SELECT * WHERE conditions` → `PropertyTable` scan
//! - **Projection**: `SELECT field1, field2` → Custom result type
//! - **Ordered**: `ORDER BY, LIMIT` → Sort + truncate
//! - **Relationship**: `TRAVERSE` → `GraphTable` operations
//! - **Aggregation**: `COUNT, SUM, AVG` → Inline fold operations
//!
//! ## Usage
//!
//! ```ignore
//! use audb_codegen::hyperql::HyperQLCompiler;
//! use audb::model::Query;
//!
//! let compiler = HyperQLCompiler::new();
//! let query = Query::new(...);
//! let code = compiler.compile(&query)?;
//! ```

pub mod code_generator;
pub mod compiler;
pub mod filter_compiler;
pub mod pattern_matcher;
pub mod type_mapper;

// Re-export main API
pub use code_generator::CodeGenerator;
pub use compiler::HyperQLCompiler;
pub use filter_compiler::FilterCompiler;
pub use pattern_matcher::{
    AggregateFunction, FilterCondition, FilterOperator, FilterValue, LiteralValue, OrderByClause,
    PatternMatcher, QueryPattern, TraverseInfo,
};
pub use type_mapper::TypeMapper;

/// Result type for compiler operations
pub type CompilerResult<T> = Result<T, CompilerError>;

/// Errors that can occur during compilation
#[derive(Debug, thiserror::Error)]
pub enum CompilerError {
    #[error("Failed to parse HyperQL query: {0}")]
    ParseError(String),

    #[error("Unknown table '{table}'. Available tables: {available}")]
    UnknownTable { table: String, available: String },

    #[error("Unknown schema '{schema}'")]
    UnknownSchema { schema: String },

    #[error("Type mismatch: expected {expected}, got {actual}")]
    TypeMismatch { expected: String, actual: String },

    #[error("Unsupported query pattern: {0}")]
    UnsupportedPattern(String),

    #[error("Invalid filter expression: {0}")]
    InvalidFilter(String),

    #[error("Code generation error: {0}")]
    CodeGenError(String),
}