Expand description
Custom SQL execution engine for mq-db.
Executes SQL queries directly against the in-memory DocumentStore
without copying data into an external database. Uses sqlparser to parse
SQL and evaluates predicates natively against Block data — including the
O(1) under(pre, post, anc_pre, anc_post) interval-index function.
§Virtual Schema
-- documents table
SELECT id, path, title, tags FROM documents;
-- blocks table
SELECT id, document_id, block_type, content, pre, post, depth, lang,
properties FROM blocks;§Built-in Functions
| Function | Description |
|---|---|
under(pre, post, anc_pre, anc_post) | O(1) interval ancestor check |
json_extract(json, path) | Extract value from JSON string |
mq(program, content) | Run an mq program against Markdown content |
count/min/max/sum/avg/group_concat/string_agg | Aggregates (count and group_concat/string_agg support DISTINCT) |
lower/upper/length/trim/ltrim/rtrim/concat/concat_ws/replace/left/right/lpad/rpad/reverse/repeat/initcap/ascii/chr/instr/split_part/substring/substr/position | String functions |
abs/round/ceil/floor/trunc/mod/power/sqrt/sign/exp/ln/log/log10/log2/pi/greatest/least | Numeric functions |
coalesce/ifnull/nullif | Null handling |
typeof/now/current_timestamp/current_date/current_time/CASE WHEN | Misc |
§Example
use mq_db::{DocumentStore, SqlEngine};
let mut store = DocumentStore::new();
store.add_str("# Hello\n\n## Architecture\n\nDetails\n\n```rust\ncode\n```\n").unwrap();
let engine = SqlEngine::new(&store).unwrap();
let out = engine.execute(
"SELECT block_type, content FROM blocks WHERE block_type = 'heading'"
).unwrap();
assert!(!out.rows.is_empty());Structs§
- Query
Output - The tabular output of a SQL query.
- SqlEngine
- Custom SQL execution engine backed by a
DocumentStorereference.