Convert Natural Language into SQL Queries from Your Terminal
Python • Google Gemini / OpenAI • MySQL • Oracle • SQLite • Rich CLI
QueryMind is an AI-powered command-line SQL assistant that allows users to interact with databases using natural language instead of writing SQL manually.
Simply ask questions like:
"Show all students whose CGPA is above 8."
QueryMind automatically:
- Understands your request using an LLM
- Discovers your database schema
- Generates SQL for the correct database dialect
- Validates the query for safety
- Executes it on the connected database
- Displays beautifully formatted results inside the terminal
It supports MySQL, Oracle, and SQLite, making it useful for learning SQL, database administration, analytics, and rapid querying.
- Natural Language → SQL conversion
- Supports MySQL, Oracle, and SQLite
- Automatic database schema discovery
- AI understands tables, columns and relationships
- Read-only SQL safety validation
- Interactive terminal interface powered by Rich
- SQL syntax highlighting
- Query execution timing
- AI-generated SQL explanations
- Persistent query history
- Built-in slash commands
- Environment-based configuration
- Easy database switching
==================================================
QueryMind AI SQL Assistant
==================================================
Database : SQLite (college.db)
Status : Connected
You > Show all students whose CGPA is above 8
Generated SQL
SELECT *
FROM students
WHERE cgpa > 8;
Executing...
┏━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━┓
┃ ID ┃ Name ┃ Department ┃ CGPA ┃
┣━━━━╋━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━┫
┃ 1 ┃ Rahul Sharma ┃ CSE ┃ 8.4 ┃
┃ 2 ┃ Anjali Verma ┃ ECE ┃ 9.1 ┃
┃ 4 ┃ Priya Nair ┃ CSE ┃ 9.5 ┃
┗━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━┛
Rows Returned : 3
Execution Time : 4.2 ms
Ask questions in plain English.
Examples:
- Show all students
- List employees earning more than 50000
- Display customers from Kerala
- Count total orders this month
- Show departments ordered alphabetically
QueryMind works seamlessly with:
- SQLite
- MySQL
- Oracle Database
The AI automatically generates SQL based on the connected database.
Before generating SQL, QueryMind reads:
- Tables
- Columns
- Data types
- Primary Keys
- Foreign Keys
This enables more accurate SQL generation.
Every generated query is validated before execution.
Blocked statements include:
- DROP
- DELETE
- UPDATE
- INSERT
- ALTER
- CREATE
- TRUNCATE
- EXEC
- CALL
Only safe SELECT queries are executed.
Built using the Rich library.
Features include:
- Syntax highlighting
- Beautiful tables
- Status panels
- Execution timers
- Colourful banners
- Interactive prompts
Use:
/explain
The assistant explains the generated SQL in simple English.
Every session records:
- Natural language prompt
- Generated SQL
- Execution time
- Returned rows
- Timestamp
History is stored locally inside:
history/history.json
| Command | Description |
|---|---|
/help |
Show all available commands |
/connect |
Connect to a database |
/disconnect |
Disconnect current session |
/schema |
Display discovered schema |
/tables |
List all tables |
/history |
View previous queries |
/explain |
Explain the last SQL query |
/clear |
Clear terminal |
/exit |
Exit QueryMind |
querymind/
│
├── main.py
├── config.py
├── database.py
├── schema.py
├── ai.py
├── validator.py
├── executor.py
├── history.py
├── prompts.py
├── utils.py
├── sample_db.py
├── requirements.txt
├── .env
│
├── history/
│ └── history.json
│
└── README.md
git clone https://github.com/yourusername/querymind.git
cd querymindWindows
python -m venv venv
venv\Scripts\activateLinux / macOS
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate a .env file.
LLM_PROVIDER=gemini
GEMINI_API_KEY=YOUR_GEMINI_API_KEY
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
DB_TYPE=sqlite
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_NAME=college.dbGenerate a demo SQLite database.
python sample_db.pyThis creates:
college.db
containing:
- students
- departments
- courses
- enrollments
python main.pyThen simply ask:
Show all students
List employees from HR
Count all courses
Show students with CGPA above 8
- Python 3.12+
- Google Gemini API
- OpenAI API
- Rich
- SQLParse
- SQLite
- MySQL Connector
- OracleDB
- python-dotenv
QueryMind is designed with database safety in mind.
- Read-only query execution
- SQL parsing and validation
- Dangerous statements blocked
- Encourages read-only database accounts
- Prevents accidental destructive operations
- Export results to CSV, Excel and JSON
- Query auto-completion
- Database connection profiles
- Voice-to-SQL
- Docker support
- Local LLM support (Ollama)
- PostgreSQL support
- Interactive charts
- Web dashboard
- Query optimisation suggestions
Contributions are welcome.
- Fork the repository
- Create a new feature branch
git checkout -b feature/NewFeature
- Commit your changes
git commit -m "Add new feature"
- Push to your branch
git push origin feature/NewFeature
- Open a Pull Request
This project is licensed under the MIT License.
Mahinsha E.A.
If you found this project helpful, consider giving it a ⭐ on GitHub.