Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚡ Text to SQL — Universal Prompt-to-SQL AI Generator

Python 3.10+ Flask AI-Powered License: MIT

A state-of-the-art Natural Language to SQL conversion engine and interactive query workbench. Translates complex plain-English questions into optimized, syntactically flawless SQL queries with schema awareness, automatic relational JOIN detection, self-correction, and multi-dialect translation.


🌟 Key Capabilities

1. 🧠 Hybrid Dual-Engine Architecture

  • Neural AI Engine (Default): Powered by Google Gemini 2.5 Flash and Groq LLaMA 3.3 / Qwen for 100% human-level accuracy on complex multi-table joins, subqueries, CTEs, window functions, and nested aggregations.
  • Smart Local Rule Engine (Offline Fallback): Automatically activates when offline or running with zero API keys.

2. 🗄️ Full Schema & Relationship Discovery

  • Sample Databases: Connect to built-in SQLite databases (E-Commerce, Company HR, University).
  • Custom Database Upload: Upload any .db or .sqlite file for instant schema mapping and live query testing.
  • Foreign Key Awareness: Automatically detects foreign keys and creates accurate JOIN conditions with table alias qualification (p.price, c.name, o.total_amount).

3. 🌐 Multi-Dialect SQL Translation

Instantly generates syntax for:

  • SQLite (Standard SQL)
  • MySQL
  • PostgreSQL
  • Microsoft SQL Server (T-SQL)
  • Oracle SQL

4. 💻 Interactive Query Workbench

  • Live execution on connected databases or in-memory preview.
  • Detailed SQL clause breakdown (SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT).
  • Natural language explanation of generated queries.
  • One-click copy and CSV Export.

🚀 Quickstart Guide

1. Clone & Install Dependencies

git clone https://github.com/harshrameshnerkar/Text-to-SQL.git
cd Text-to-SQL
pip install -r requirements.txt

2. Configure API Keys (Optional for 100% Precision)

Copy the example environment template:

cp .env.example .env

Add your free Google Gemini or Groq API key in .env:

GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_here

(Get a free key from Google AI Studio or Groq Console - no credit card required).

3. Run the Application

python app.py

Open http://localhost:5000 in your browser.


📂 Project Structure

Text-to-SQL/
├── app.py                      # Flask web application server & REST APIs
├── sql_engine.py               # Hybrid Neural AI & Schema-Aware SQL Engine
├── init_db.py                  # Sample database generator
├── requirements.txt            # Python dependencies
├── .env.example                # Environment variables template
├── .gitignore                  # Git ignore rules (protects .env)
├── README.md                   # Documentation
│
├── databases/                  # SQLite sample databases
│   ├── ecommerce.db
│   ├── company.db
│   └── university.db
│
├── templates/
│   └── index.html              # Glassmorphic Dark-Mode UI
│
└── static/
    ├── style.css               # Design system & responsive styles
    └── main.js                 # Frontend state, schema explorer & API connector

👤 Author

Harsh Nerkar


📄 License

This project is licensed under the MIT License.

About

⚡ Universal Text-to-SQL AI Generator powered by Google Gemini & Groq LLMs with multi-table relational schema awareness, self-correction, and multi-dialect SQL support.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages