A lightweight, web-based SQL engine built with Python and FastAPI. This project features a custom SQL parser and executor that allows users to run SQL queries against a JSON-based storage system through a modern web interface.
- Web Interface: Clean, dark-themed UI for writing and executing SQL queries.
- Custom SQL Engine: Includes a hand-written tokenizer, parser, and executor.
- JSON Storage: Data is persisted in JSON format, making it easy to inspect and manage.
- Multi-Query Support: Execute multiple SQL statements separated by semicolons.
- Real-time Results: View query results in an interactive table with execution timing.
online_sql/
├── main.py # FastAPI application & API routes
├── requirements.txt # Python dependencies
├── engine/ # Core SQL Engine logic
│ ├── tokenizer.py # Lexical analysis
│ ├── parser.py # Syntactic analysis (AST generation)
│ ├── executor.py # Query execution logic
│ └── storage.py # JSON-based data persistence
├── data/ # Database storage (JSON files)
│ └── default/ # Default database namespace
└── static/ # Frontend assets
└── index.html # Web interface
- Python 3.8+
-
Clone the repository:
git clone <repository-url> cd online_sql
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python main.py
-
Access the UI: Open your browser and navigate to
http://localhost:8000
You can run standard SQL commands via the web interface:
CREATE TABLE users (id INT, name VARCHAR, email VARCHAR);INSERT INTO users VALUES (1, 'John Doe', 'john@example.com');
INSERT INTO users VALUES (2, 'Jane Smith', 'jane@example.com');SELECT * FROM users WHERE id = 1;- Tokenizer: Breaks the raw SQL string into a stream of tokens (keywords, identifiers, operators).
- Parser: Analyzes the token stream to build an Abstract Syntax Tree (AST) based on SQL grammar.
- Executor: Traverses the AST and performs the requested operations (Reading/Writing to JSON files in the
data/directory). - API: FastAPI handles the communication between the frontend and the engine.