Skip to main content

Crate hematite

Crate hematite 

Source
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

§Project Layout

The core architecture is layered:

sql -> parser -> query -> catalog -> btree -> storage
  • sql: user-facing API, script stepping, transactions, CLI-facing behavior
  • parser: lexer, AST, and syntax validation
  • query: planning, execution, coercion, metadata shaping
  • catalog: schema, row typing, metadata persistence, logical encoding
  • btree: generic key/value tree over byte payloads
  • storage: 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::*;

Modules§

btree
Generic B-tree module over opaque byte keys and values.
catalog
Relational catalog and access-method layer.
error
Error handling for Hematite database
parser
SQL query parser for converting tokens to AST
query
Query processing module
sql
SQL interface module
storage
Low-level storage primitives.