elif-orm 0.7.1

Production-ready ORM with migrations, database services, connection pooling, and query builder
Documentation
// Legacy compatibility layer - use the new optimizer module for new code
// This file maintains backward compatibility while redirecting to the new modular structure

pub use crate::loading::optimizer::{
    ExecutionResult, ExecutionStats, OptimizationStrategy, PlanAnalysis, PlanExecutor, QueryNode,
    QueryOptimizer, QueryPlan, RiskLevel,
};

use crate::{
    error::OrmResult,
    loading::{
        batch_loader::BatchLoader,
        optimizer::{
            analyzer::QueryOptimizer as NewQueryOptimizer,
            executor::PlanExecutor as NewPlanExecutor,
        },
    },
};
use serde_json::Value as JsonValue;
use std::collections::HashMap;

/// Legacy OptimizedQueryExecutor - now wraps the new modular implementation
pub struct OptimizedQueryExecutor {
    executor: NewPlanExecutor,
    optimizer: NewQueryOptimizer,
}

impl OptimizedQueryExecutor {
    /// Create a new optimized query executor
    pub fn new(batch_loader: BatchLoader) -> Self {
        Self {
            executor: NewPlanExecutor::new(batch_loader),
            optimizer: NewQueryOptimizer::new(),
        }
    }

    /// Execute a query plan with optimization
    pub async fn execute_optimized(
        &self,
        plan: &mut QueryPlan,
        connection: &sqlx::PgPool,
    ) -> OrmResult<HashMap<String, Vec<JsonValue>>> {
        // Optimize the plan first
        let _strategies = self.optimizer.optimize_plan(plan)?;

        // Execute the optimized plan
        let result = self.executor.execute_plan(plan, connection).await?;

        Ok(result.results)
    }

    /// Execute plan with detailed analysis
    pub async fn execute_with_analysis(
        &self,
        plan: &mut QueryPlan,
        connection: &sqlx::PgPool,
    ) -> OrmResult<(HashMap<String, Vec<JsonValue>>, ExecutionStats)> {
        // Optimize the plan first
        let _strategies = self.optimizer.optimize_plan(plan)?;

        // Execute the optimized plan
        let result = self.executor.execute_plan(plan, connection).await?;

        Ok((result.results, result.stats))
    }

    /// Analyze a query plan without executing it
    pub fn analyze_plan(&self, plan: &QueryPlan) -> OrmResult<PlanAnalysis> {
        self.optimizer.analyze_plan(plan)
    }
}