Introduction to Databas
Databas is a toy SQLite-like database system implemented in Rust for educational purposes. It demonstrates core database concepts including page-based storage, SQL parsing, and query execution.This is a work-in-progress educational project. It is not intended for production use.
What is Databas?
Databas implements a simplified relational database system that uses many of the same concepts found in SQLite:- Page-based storage with a custom binary format
- SQL parser that handles SELECT, INSERT, and CREATE TABLE statements
- Command-line interface for interactive queries
- B-tree data structures for efficient table storage
- Page cache with clock replacement algorithm
Key features
SQL Parser
Hand-written lexer and parser supporting SELECT, INSERT, and CREATE TABLE statements with expressions, WHERE clauses, ORDER BY, and LIMIT.
Page-based Storage
Custom binary format with 4KB pages, magic number validation, and checksums. Supports both leaf and interior B-tree pages.
Type System
Supports INT, FLOAT, and TEXT column types with PRIMARY KEY and NULLABLE constraints.
Interactive CLI
Command-line interface with REPL mode for executing queries and viewing parsed SQL statements.
Architecture overview
Databas is organized as a Rust workspace with three main crates:databas_cli
The command-line interface that provides:- Interactive REPL with
>>>prompt - Single query execution mode
- SQL statement parsing and display
databas_core
The core database engine implementing:DatabaseHeader- Database metadata with magic numberdatabas format1\0DiskManager- File I/O operations for reading and writing pagesPageCache- In-memory cache with clock replacement and pin guardsTablePage- B-tree page structures (leaf and interior nodes)- Page checksums for data integrity
databas_sql_parser
The SQL parsing layer featuring:Lexer- Tokenizes SQL statementsParser- Builds abstract syntax trees using Pratt parsing- Support for expressions, operators, aggregates, and literals
- Error handling with position tracking
Get started
Quickstart
Build from source and run your first queries
Architecture
Deep dive into the database internals
Example queries
Databas supports standard SQL syntax for table creation, data insertion, and queries:Why Databas?
This project is designed for learning:- Understand database internals - See how page-based storage actually works
- Learn Rust - Practical example of systems programming with Rust
- Study parsing - Hand-written lexer and parser implementation
- Explore data structures - B-trees, page caches, and disk management