AkurAI Build
Menu

Public repository / master

AkurAI-Framework / crates/sqlexec/src/lib.rs

Latest change fa37e2544d31a1199954a395f9e5b3ebb237b17f - feat(sql): aggregates (COUNT/SUM/AVG/MIN/MAX) + GROUP BY (gpt-5.5) by Ólafur Búi Ólafsson

//! AkurAI-Framework SQL executor — pure `std`, zero external dependencies.
//!
//! The back half of the query engine. Where [`akurai_sql`] turns SQL text into
//! an AST, this crate *runs* that AST over the [`akurai_storage`] B+tree:
//! it owns a catalog of table schemas, a typed row codec, a `WHERE` evaluator,
//! and an [`Executor`] that ties them together.
//!
//! ```no_run
//! use akurai_sqlexec::{Executor, Outcome};
//!
//! let mut db = Executor::open("app.db").unwrap();
//! db.execute("CREATE TABLE users (id INTEGER NOT NULL, name TEXT)").unwrap();
//! db.execute("INSERT INTO users (id, name) VALUES (1, 'ada')").unwrap();
//! if let Outcome::Rows(rs) = db.execute("SELECT name FROM users WHERE id = 1").unwrap() {
//!     assert_eq!(rs.columns, vec!["name".to_string()]);
//! }
//! ```
//!
//! ## Supported statements
//!
//! - `CREATE TABLE` — registers a schema (column names, types, `NOT NULL`),
//!   persisted in the tree so it survives reopening.
//! - `INSERT` — validates against the schema and writes one typed row under an
//!   auto-incrementing rowid.
//! - `UPDATE` — scans a table, applies the `WHERE` filter, and rewrites each
//!   matching row in place (same rowid), re-validating the `SET` values against
//!   the column types. Returns the number of rows affected.
//! - `DELETE` — scans a table, applies the `WHERE` filter, and removes each
//!   matching row. Returns the number of rows affected.
//! - `SELECT` — scans a table, applies `WHERE`, optional single-column
//!   `GROUP BY`, aggregate projection, `ORDER BY`, and `LIMIT`, and projects
//!   rows into a [`ResultSet`].
//!
//! Joins, indexes, and multi-statement transactions are deliberately out of
//! scope for this slice.

#![forbid(unsafe_code)]

mod catalog;
mod error;
mod eval;
mod exec;
mod row;
mod value;

pub use error::ExecError;
pub use exec::{Executor, Outcome};
pub use value::Value;

/// The rows a `SELECT` produces, plus the names of the projected columns.
#[derive(Debug, Clone, PartialEq)]
pub struct ResultSet {
    /// Projected column names, left to right.
    pub columns: Vec<String>,
    /// Result rows; each is one [`Value`] per projected column.
    pub rows: Vec<Vec<Value>>,
}