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
- Single Entry Point: One function to rule them all
- AST-First: All SQL parsed into AST, never string-heuristics
- Dialect Support: MySQL, PostgreSQL, SQLite automatically detected
- Parameterized: Proper placeholder handling ($1, ?, @param)
- 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§
- Batch
Result - Result of batch execution
- Prepared
Statement - A prepared statement that can be executed multiple times.
- Query
Builder - Fluent query builder that generates and executes SQL.
- Query
Stats - 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.