Expand description
§mq-db – Markdown-specialised Embedded Database
mq-db treats Markdown documents as structured, hierarchical databases
rather than plain text. It builds on [mq-markdown]’s AST parser and
adds:
-
Flat block storage with row-polymorphic properties – every heading, paragraph, code block, list, table, and front-matter entry becomes a typed [
Block] row with its own property bag. -
Interval index (Nested Set / Pre-Post Order) – a section hierarchy derived from heading depth is encoded as
(pre, post)integer pairs so that ancestor/descendant checks areO(1)integer comparisons. -
Zone Maps – per-document statistics (max heading depth, heading slugs, code languages, front-matter keys/tags) that let the query engine skip irrelevant documents before scanning their blocks.
-
Chainable query API – document-level and block-level predicates,
UNDER headingsection scoping, built-in linter helpers.
§Quick Start
use mq_db::{DocumentStore, block::BlockType};
let mut store = DocumentStore::new();
store.add_str("# Hello\n\n## Architecture\n\nDetails\n\n```rust\ncode\n```\n").unwrap();
// Extract all content under the "Architecture" H2
let chunks = store.query()
.under_heading("Architecture", Some(2))
.filter(|b| matches!(b.block_type, BlockType::Paragraph | BlockType::Code))
.blocks();
assert_eq!(chunks.len(), 2);§Structural Linting
use mq_db::{DocumentStore, block::BlockType};
let mut store = DocumentStore::new();
store.add_str("## Section\n\n- item without intro paragraph\n").unwrap();
let q = store.query();
let violations = q.lint_heading_followed_by(2, &[BlockType::List]);
assert_eq!(violations.len(), 1);Re-exports§
pub use document::Document;pub use error::MqdbError;pub use mq_engine::MqEngine;pub use query::LintViolation;pub use query::Query;pub use query::QueryResult;pub use sql::QueryOutput;pub use sql::SqlEngine;pub use storage::Storage;pub use storage::catalog::CatalogEntry;pub use store::DatabaseAlias;pub use store::DocumentStore;pub use store::ReindexReport;pub use store::StoreStats;
Modules§
- block
- discover
- Markdown file discovery helper shared by the
mq-dbCLI and other front-ends (e.g.mq-mcp’sdb_indextool) that index files/directories given by the caller. - document
- error
- index
- indexes
- Secondary indexes for fast block lookups in the SQL engine.
- mq_
engine - mq query engine integration for mq-db.
- query
- sql
- Custom SQL execution engine for mq-db.
- storage
- store
- tui
- Terminal User Interface for mq-db using ratatui + crossterm.