Skip to main content

Module sql_entry

Module sql_entry 

Source
Expand description

§Unified SQL Execution Entry Point (Task 12)

This module provides a single, unified entry point for all SQL execution in SochDB. All SQL queries - regardless of origin - flow through this interface.

§Design Goals

  1. Single Entry Point: One function to rule them all
  2. AST-First: All SQL parsed into AST, never string-heuristics
  3. Dialect Support: MySQL, PostgreSQL, SQLite automatically detected
  4. Parameterized: Proper placeholder handling ($1, ?, @param)
  5. Tracing: Every query emits standardized telemetry

§Architecture

┌─────────────┐     ┌─────────────────────────────────┐
│   Client    │────▶│  unified_execute(sql, params)   │
└─────────────┘     └─────────────────────────────────┘
                                    │
                                    ▼
                        ┌───────────────────────┐
                        │    SQL Parser (AST)   │
                        │  - Dialect detection  │
                        │  - Error localization │
                        └───────────────────────┘
                                    │
                                    ▼
                        ┌───────────────────────┐
                        │   Statement Router    │
                        │  - SELECT → Query     │
                        │  - INSERT → Write     │
                        │  - DDL → Schema       │
                        └───────────────────────┘
                                    │
                                    ▼
                        ┌───────────────────────┐
                        │   Executor Engine     │
                        │  - Expression eval    │
                        │  - Type coercion      │
                        │  - Result formation   │
                        └───────────────────────┘

§Usage

use sochdb_client::sql_entry::{execute, execute_with_params, SqlResult};

// Simple query
let result = execute(&conn, "SELECT * FROM users WHERE id = 1")?;

// Parameterized query
let result = execute_with_params(
    &conn,
    "SELECT * FROM users WHERE name = $1",
    &[SochValue::Text("Alice".into())],
)?;

Re-exports§

pub use crate::ast_query::QueryResult;

Structs§

BatchResult
Result of batch execution
PreparedStatement
A prepared statement that can be executed multiple times.
QueryBuilder
Fluent query builder that generates and executes SQL.
QueryStats
Statistics for a single query execution

Functions§

execute
Execute a SQL query through the unified AST-based pipeline.
execute_batch
Execute multiple SQL statements in order.
execute_with_params
Execute a parameterized SQL query through the unified AST-based pipeline.
execute_with_params_and_stats
Execute a parameterized SQL query and return statistics.
execute_with_stats
Execute a SQL query and return statistics along with result.