A lightweight, from-scratch relational database management system (RDBMS) built entirely in C++. This project demonstrates how a real SQL database works under the hood, taking a raw string query and putting it through a full compilation pipeline to physically modify data on a hard drive.
- Zero Dependencies: Built entirely using the C++17 Standard Library without relying on external parsing tools (like Bison/Yacc) or storage libraries.
- Custom Pipeline: Features a hand-written Lexical Analyzer, Recursive Descent Parser, and Abstract Syntax Tree (AST).
- Persistent Storage: Translates in-memory data structures into physical
.csvfiles so data survives across reboots.
- Interactive REPL: A fully functioning command-line interface (
sqlight>) to enter queries and receive formatted table outputs. - DDL (Data Definition Language): Create and destroy tables dynamically (
CREATE TABLE,DROP TABLE,SHOW TABLES). - CRUD Operations: Full data manipulation support (
INSERT,SELECT,UPDATE,DELETE). - Where Clauses: Support for targeted data manipulation using
WHEREfilters. - Disk Persistence: Automatically loads tables from the
data/directory on startup and saves them upon modification.
- No Concurrency: This engine is designed for a single user and does not support transactions, locking, or multi-threading.
- No Advanced Queries: Currently does not support
JOINs,GROUP BY,ORDER BY, or complex nestedWHEREclauses (likeAND/OR). - Performance: The storage engine uses sequential scans (
O(N)) to find data. It does not implement B-Trees or database indexing yet.
Fork this repository and clone it to your local machine:
git clone https://github.com/your-username/sql-engine.git
cd sql-engineYou will need CMake and a modern C++ compiler installed on your system.
For Windows (PowerShell):
# Generate the build files
cmake -B build
# Compile the executable
cmake --build buildFor Linux / WSL / macOS (Bash):
# Generate the build files
cmake -B build
# Compile the executable
cmake --build buildOnce compiled, you can start the interactive REPL:
Windows:
./build/sql-engine.exeLinux / macOS:
./build/sql-engine(Type .exit to quit the engine at any time).
When you type a query like SELECT * FROM users; and press Enter, it goes through a 5-step pipeline. We have thoroughly documented each step in the docs/ folder:
- Lexer: The string is chopped into tiny tokens (e.g.,
SELECT,*,FROM,users). - Parser: The tokens are evaluated against strict SQL grammar rules to ensure the syntax is valid.
- AST (Abstract Syntax Tree): The parser packages the validated query into a structured object (e.g., a
SelectStatement). - Executor: Evaluates the AST object and figures out which backend system commands need to be run.
- Storage Engine: The backend system that physically creates files, searches for rows, and edits the data on your hard drive.
Feel free to explore the docs/ folder to dive deeper into the C++ implementation of each step!
- B.Tech Computer Science (final year)
- Focus: Systems programming · Database internals · Low-latency software
- Built sql-engine from scratch as a hands-on exploration of compilation pipelines, AST parsing, and persistent storage in C++17.
This project is licensed under the MIT License - see the LICENSE file for details. You are free to fork, modify, and use this project for your own learning and development!

