Skip to content

Learn Rust πŸ¦€ & Golang πŸ”΅ with a Mini-SQLite Database Engine πŸ—οΈ (for Python users)

Notifications You must be signed in to change notification settings

kimtth/mini-sqlite-engine-py-go-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

mini sqlite

Polyglot SQL Engine 🧭

An educational project demonstrating a tiny SQL database engine implemented in three languages (Python, Go, Rust). Each implementation is a learning scaffold that covers parsing, query execution, a simple storage layer, a CLI shell and a minimal web UI. πŸŽ“ (Code generated by LLM)

Directories in the workspace πŸ“

  • mini_sqlite_python/ β€” Python edition (concise, easiest to run and modify) 🐍

    • README: mini_sqlite_python/README.md
    • Quick run:
      • CLI: python main.py ▢️
      • Web: python main.py --web 🌐
    • Data files: mini_sqlite_python/data/*.dat (auto-created per database)
  • mini_sqlite_golang/ β€” Golang edition (balanced simplicity and performance) 🐹

    • README: mini_sqlite_golang/README.md
    • Quick run:
      • CLI: go run main.go ▢️
      • Web: go run main.go -web 🌐
    • Data files: mini_sqlite_golang/data/*.dat (auto-created per database)
  • mini_sqlite_rust/ β€” Rust edition (type-safe, high performance) πŸ¦€

    • README: mini_sqlite_rust/README.md
    • Quick run:
      • Build: cargo build --release πŸ› οΈ
      • CLI: cargo run --release ▢️
      • Web: cargo run --release -- --web 🌐
    • Data files: mini_sqlite_rust/data/*.dat (auto-created per database)

SQL shell & Web UI

1. Web UI (Web Browser)

web_ui

2. SQL shell (CLI)

Welcome to the mini SQL shell. Type 'exit' to quit.
db> CREATE DATABASE demo;
Database 'demo' ready.
db> USE demo;
Using database 'demo'.
db> CREATE TABLE users (id INT, name TEXT, email TEXT);
Table 'users' created.
db> INSERT INTO users VALUES (1, 'Alice', 'alice@example.com');
1 row inserted.
db> INSERT INTO users VALUES (2, 'Bob', 'bob@example.com');
1 row inserted.
db> SELECT * FROM users;
id | name | email
1 | Alice | alice@example.com
2 | Bob | bob@example.com
db> SELECT name, email FROM users WHERE id = 2;
name | email
Bob | bob@example.com
db> UPDATE users SET email = 'alice.smith@example.com' WHERE id = 1;
1 row(s) updated.
db> ALTER TABLE users ADD COLUMN age INT;
Column 'age' added to 'users'.
db> UPDATE users SET age = 30 WHERE id = 1;
1 row(s) updated.
db> SELECT * FROM users;
id | name | email | age
1 | Alice | alice.smith@example.com | 30
2 | Bob | bob@example.com | None
db>

Purpose & Scope 🎯

This project is intentionally small and educational:

  • Demonstrates parser β†’ executor β†’ storage pipeline βš™οΈ
  • Uses file-backed B-Tree pages persisted as compact .dat files πŸ—„οΈ
  • Provides a REPL (db>) and a tiny web UI for querying πŸ’»
  • Focuses on clarity over completeness or production-readiness βœ…
  • The BTreeStroage in the code is not an actual B-Tree. For simplicity, replace it with an in-memory dictionary.

Where to start πŸš€

  1. Choose an implementation folder (python/go/rust). πŸ“‚
  2. Read that folder's README for implementation-specific instructions. πŸ“–
  3. Try the example queries in examples/sample.sql inside each subproject (where present). πŸ§ͺ
  4. The root contains AGENT.MD (project goals and scaffolding plan) β€” see AGENT.MD. πŸ“‹
  5. Use the language-specific READMEs for in-depth commands, structure and next steps. πŸ”§

Not implemented / Missing features ❗

The implementations in this workspace are intentionally minimal and educational. The following common relational-database features are not implemented yet and are good targets for future work:

Expand
  • Query Capabilities

    • Extended WHERE clause support (AND, OR, complex expressions)
    • Aggregation functions (COUNT, SUM, AVG, MIN, MAX)
    • ORDER BY and GROUP BY clauses
    • Subqueries and correlated subqueries
    • Window functions (ROW_NUMBER, RANK, etc.)
    • Prepared statements and query parameterization
  • Storage & Persistence

    • Write-ahead logging (WAL) for durability and crash-recovery
    • Background compaction and segment merging
    • Page-level caching and eviction policies
    • Checkpointing and snapshotting
  • Transactions & Concurrency

    • Serializable / snapshot isolation levels
    • Lock manager or MVCC for concurrent access
    • Transaction rollback and rollback segments
    • Two-phase commit for distributed transactions
  • Indexing & Query Optimization

    • B+tree persistent indexes for faster range scans
    • Hash indexes for equality lookups
    • Cost-based query planner and basic optimizations
    • Statistics collection for planning
  • Error Handling & Validation

    • Comprehensive error messages and error codes
    • Input validation and SQL syntax diagnostics
    • Transaction rollback support on error
    • Strict type checking and casting rules

Further reading

Contributing & Licensing 🀝

  • Educational / MIT

Acknowledgments πŸ™

Built as a learning resource to understand database internals and storage engine design. πŸ“š

About

Learn Rust πŸ¦€ & Golang πŸ”΅ with a Mini-SQLite Database Engine πŸ—οΈ (for Python users)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published