mq_db/lib.rs
1//! # mq-db – Markdown-specialised Embedded Database
2//!
3//! `mq-db` treats Markdown documents as **structured, hierarchical databases**
4//! rather than plain text. It builds on [`mq-markdown`]'s AST parser and
5//! adds:
6//!
7//! * **Flat block storage with row-polymorphic properties** – every heading,
8//! paragraph, code block, list, table, and front-matter entry becomes a
9//! typed [`Block`] row with its own property bag.
10//!
11//! * **Interval index (Nested Set / Pre-Post Order)** – a section hierarchy
12//! derived from heading depth is encoded as `(pre, post)` integer pairs so
13//! that ancestor/descendant checks are `O(1)` integer comparisons.
14//!
15//! * **Zone Maps** – per-document statistics (max heading depth, heading
16//! slugs, code languages, front-matter keys/tags) that let the query
17//! engine skip irrelevant documents before scanning their blocks.
18//!
19//! * **Chainable query API** – document-level and block-level predicates,
20//! `UNDER heading` section scoping, built-in linter helpers.
21//!
22//! ## Quick Start
23//!
24//! ```rust
25//! use mq_db::{DocumentStore, block::BlockType};
26//!
27//! let mut store = DocumentStore::new();
28//! store.add_str("# Hello\n\n## Architecture\n\nDetails\n\n```rust\ncode\n```\n").unwrap();
29//!
30//! // Extract all content under the "Architecture" H2
31//! let chunks = store.query()
32//! .under_heading("Architecture", Some(2))
33//! .filter(|b| matches!(b.block_type, BlockType::Paragraph | BlockType::Code))
34//! .blocks();
35//!
36//! assert_eq!(chunks.len(), 2);
37//! ```
38//!
39//! ## Structural Linting
40//!
41//! ```rust
42//! use mq_db::{DocumentStore, block::BlockType};
43//!
44//! let mut store = DocumentStore::new();
45//! store.add_str("## Section\n\n- item without intro paragraph\n").unwrap();
46//!
47//! let q = store.query();
48//! let violations = q.lint_heading_followed_by(2, &[BlockType::List]);
49//!
50//! assert_eq!(violations.len(), 1);
51//! ```
52
53pub mod block;
54pub mod document;
55pub mod error;
56pub mod index;
57pub mod indexes;
58pub mod mq_engine;
59pub mod query;
60pub mod sql;
61pub mod storage;
62pub mod store;
63pub mod tui;
64
65pub use document::Document;
66pub use error::MqdbError;
67pub use mq_engine::MqEngine;
68pub use query::{LintViolation, Query, QueryResult};
69pub use sql::{QueryOutput, SqlEngine};
70pub use storage::Storage;
71pub use storage::catalog::CatalogEntry;
72pub use store::DocumentStore;