Expand description
Hematite is a small embeddable SQL database written in Rust.
It is designed to stay lightweight enough to repurpose and extend while still offering a surprisingly broad SQL surface: DDL, transactions, views, triggers, joins, aggregates, window functions, recursive CTEs, savepoints, rich scalar expressions, and a custom type system.
§Quick Start
use hematite::Hematite;
fn main() -> hematite::Result<()> {
let mut db = Hematite::new_in_memory()?;
db.execute("CREATE TABLE users (id INT PRIMARY KEY, name TEXT);")?;
db.execute("INSERT INTO users (id, name) VALUES (1, 'Ada');")?;
let names = db.query("SELECT name FROM users ORDER BY id;")?;
assert_eq!(names.columns, vec!["name"]);
assert_eq!(names.rows.len(), 1);
Ok(())
}§Main Entry Points
Hematiteis the high-level library facade.Connectionis the lower-level SQL connection boundary.PreparedStatementsupports repeated execution with parameters.Transactionwraps explicit transactions.ResultSet,Row, andStatementResultare the primary result types.
§Project Layout
The core architecture is layered:
sql -> parser -> query -> catalog -> btree -> storagesql: user-facing API, script stepping, transactions, CLI-facing behaviorparser: lexer, AST, and syntax validationquery: planning, execution, coercion, metadata shapingcatalog: schema, row typing, metadata persistence, logical encodingbtree: generic key/value tree over byte payloadsstorage: pager, WAL/rollback journal, page and row primitives
§More Documentation
- Repository quick start:
README.md - Internal architecture guide:
docs/architecture.md - Module and codebase guide:
docs/codebase-guide.md - SQL dialect and support matrix:
docs/sql-dialect.md
Re-exports§
pub use catalog::Catalog;pub use catalog::Column;pub use catalog::DataType;pub use catalog::Schema;pub use catalog::StoredRow;pub use catalog::Table;pub use catalog::TableCursor;pub use catalog::Value;pub use error::HematiteError;pub use error::Result;pub use parser::parser::Parser;pub use parser::Lexer;pub use sql::script_is_complete;pub use sql::Connection;pub use sql::Database;pub use sql::ExecutedStatement;pub use sql::FromRow;pub use sql::FromValue;pub use sql::Hematite;pub use sql::PreparedStatement;pub use sql::ResultSet;pub use sql::Row;pub use sql::StatementResult;pub use sql::Transaction;pub use parser::ast::*;