Skip to main content

hematite/
lib.rs

1//! Hematite is a small embeddable SQL database written in Rust.
2//!
3//! It is designed to stay lightweight enough to repurpose and extend while still offering a
4//! surprisingly broad SQL surface: DDL, transactions, views, triggers, joins, aggregates, window
5//! functions, recursive CTEs, savepoints, rich scalar expressions, and a custom type system.
6//!
7//! # Quick Start
8//!
9//! ```no_run
10//! use hematite::Hematite;
11//!
12//! fn main() -> hematite::Result<()> {
13//!     let mut db = Hematite::new_in_memory()?;
14//!     db.execute("CREATE TABLE users (id INT PRIMARY KEY, name TEXT);")?;
15//!     db.execute("INSERT INTO users (id, name) VALUES (1, 'Ada');")?;
16//!
17//!     let names = db.query("SELECT name FROM users ORDER BY id;")?;
18//!     assert_eq!(names.columns, vec!["name"]);
19//!     assert_eq!(names.rows.len(), 1);
20//!     Ok(())
21//! }
22//! ```
23//!
24//! # Main Entry Points
25//!
26//! - [`Hematite`] is the high-level library facade.
27//! - [`Connection`] is the lower-level SQL connection boundary.
28//! - [`PreparedStatement`] supports repeated execution with parameters.
29//! - [`Transaction`] wraps explicit transactions.
30//! - [`ResultSet`], [`Row`], and [`StatementResult`] are the primary result types.
31//!
32//! # Project Layout
33//!
34//! The core architecture is layered:
35//!
36//! ```text
37//! sql -> parser -> query -> catalog -> btree -> storage
38//! ```
39//!
40//! - `sql`: user-facing API, script stepping, transactions, CLI-facing behavior
41//! - `parser`: lexer, AST, and syntax validation
42//! - `query`: planning, execution, coercion, metadata shaping
43//! - `catalog`: schema, row typing, metadata persistence, logical encoding
44//! - `btree`: generic key/value tree over byte payloads
45//! - `storage`: pager, WAL/rollback journal, page and row primitives
46//!
47//! # More Documentation
48//!
49//! - Repository quick start: `README.md`
50//! - Internal architecture guide: `docs/architecture.md`
51//! - Module and codebase guide: `docs/codebase-guide.md`
52//! - SQL dialect and support matrix: `docs/sql-dialect.md`
53
54pub mod btree;
55pub mod catalog;
56pub mod error;
57pub mod parser;
58pub mod query;
59pub mod sql;
60pub mod storage;
61
62#[cfg(test)]
63mod architecture_tests;
64
65#[cfg(test)]
66pub mod test_utils;
67
68pub use catalog::{Catalog, Column, DataType, Schema, StoredRow, Table, TableCursor, Value};
69pub use error::{HematiteError, Result};
70pub use parser::parser::Parser;
71pub use parser::{ast::*, Lexer};
72pub use sql::{
73    script_is_complete, Connection, Database, ExecutedStatement, FromRow, FromValue, Hematite,
74    PreparedStatement, ResultSet, Row, StatementResult, Transaction,
75};