Skip to main content

Module query

Module query 

Source
Expand description

SQL query engine over files.

run parses a SELECT statement, resolves file paths from the FROM clause relative to a base directory, executes the query in memory, and returns the result as a CanonicalValue::Array of row objects. The supported surface is deliberately small: SELECT with column references, aliases, and arithmetic; WHERE; GROUP BY with SUM, AVG, COUNT, MIN, and MAX; HAVING (evaluated on projected aliases); ORDER BY; LIMIT; DISTINCT; INNER JOIN and LEFT JOIN with ON; and a FROM clause that accepts a single file, a quoted glob pattern, or a comma-separated list of tables (which produces a cross join).

Every format the sheeter engine reads can appear in FROM, so a single query can mix .xlsx, .csv, .json, .ndjson, .yaml, .xml, .toml, .ods, and .sql files without conversion.

§Examples

use sheeter_engine::query;
use std::fs;

let dir = tempfile::tempdir().unwrap();
fs::write(dir.path().join("users.csv"), "id,name\n1,Alice\n2,Bob\n").unwrap();
let result = query::run("SELECT name FROM users.csv WHERE id = 2", dir.path()).unwrap();
assert_eq!(result.to_json().unwrap(), r#"[{"name":"Bob"}]"#);

Functions§

run
Executes a SELECT statement over files in base_dir.