Skip to main content

Module sql

Module sql 

Source
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

FunctionDescription
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_aggAggregates (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/positionString functions
abs/round/ceil/floor/trunc/mod/power/sqrt/sign/exp/ln/log/log10/log2/pi/greatest/leastNumeric functions
coalesce/ifnull/nullifNull handling
typeof/now/current_timestamp/current_date/current_time/CASE WHENMisc

§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§

QueryOutput
The tabular output of a SQL query.
SqlEngine
Custom SQL execution engine backed by a DocumentStore reference.

Enums§

Value

Functions§

html_escape