Skip to content

anshuman0123/sql_engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Online SQL Engine

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.

🚀 Features

  • 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.

📁 Project Structure

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

🛠️ Installation & Setup

Prerequisites

  • Python 3.8+

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd online_sql
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the application:

    python main.py
  4. Access the UI: Open your browser and navigate to http://localhost:8000

📝 Usage

You can run standard SQL commands via the web interface:

Create a Table

CREATE TABLE users (id INT, name VARCHAR, email VARCHAR);

Insert Data

INSERT INTO users VALUES (1, 'John Doe', 'john@example.com');
INSERT INTO users VALUES (2, 'Jane Smith', 'jane@example.com');

Query Data

SELECT * FROM users WHERE id = 1;

⚙️ How it Works

  1. Tokenizer: Breaks the raw SQL string into a stream of tokens (keywords, identifiers, operators).
  2. Parser: Analyzes the token stream to build an Abstract Syntax Tree (AST) based on SQL grammar.
  3. Executor: Traverses the AST and performs the requested operations (Reading/Writing to JSON files in the data/ directory).
  4. API: FastAPI handles the communication between the frontend and the engine.

📜 License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors