CLI tool for natural language to any database query conversion
Project description
๐ QUERY-CRAFTER-CLI (QCraft)
โโโโโโโ โโโ โโโโโโโโโโโโโโโโโโ โโโ โโโ โโโโโโโโโโโโโโ โโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโ โโโ
โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โโโ
โโโ โโโโโโ โโโโโโโโโ โโโโโโโโ โโโโโโโ โโโ โโโโโโโโโโโโโโโโโโโโโโ โโโ โโโโโโ โโโโโโโโ โโโ โโโ โโโ
โโโโโ โโโโโโ โโโโโโโโโ โโโโโโโโ โโโโโ โโโ โโโโโโโโโโโโโโโโโโโโโโ โโโ โโโโโโ โโโโโโโโ โโโ โโโ โโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโ โโโ โโโโโโโโโโโ โโโโโโ โโโโโโ โโโ โโโโโโโโโโโ โโโ โโโโโโโโโโโโโโโโโโโ
โโโโโโโ โโโโโโโ โโโโโโโโโโโ โโโ โโโ โโโโโโโโโโ โโโโโโ โโโโโโ โโโ โโโโโโโโโโโ โโโ โโโโโโโโโโโโโโโโโโ
๐ฏ Convert Natural Language to SQL or nay database query with AI Power
Transform your thoughts into database queries instantly
๐ What is QCraft?
QCraft is a revolutionary command-line interface that bridges the gap between human language and database queries. Whether you're a developer, data analyst, or database administrator, QCraft empowers you to generate complex SQL, NoSQL, and other database queries using natural language.
graph LR
A[๐ญ Natural Language] -->|QCraft Magic| B[๐ AI Processing]
B --> C[โก SQL Query]
C --> D[๐ Auto-copied to Clipboard]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#e8f5e8
style D fill:#fff3e0
๐ฌ See QCraft in Action
# get your schema form databse, as schema.sql or just put any king of schem in a file like main_scehma01.txt
# somple use this file to share sceham to the cli tool
$ qcraft method --extract "main_schema01.txt"
# Set your database schema
$ qcraft method --paste "CREATE TABLE orders (id INT, customer_name VARCHAR(100), amount DECIMAL(10,2), order_date DATE)"
# Configure your database type
$ qcraft query-type PostgreSQL
# Convert natural language to SQL
$ qcraft convert "Show me all orders above $500 from last month" --provider free
Result:
SELECT * FROM orders
WHERE amount > 500
AND order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')
AND order_date < DATE_TRUNC('month', CURRENT_DATE);
๐ Quick Start
Installation
npm install -g qcraft-cli
30-Second Setup
# 1. Set your database schema
qcraft method --paste "YOUR_DATABASE_SCHEMA"
# or if schema file availabel just auto extract it
$ qcraft method --extract "main_schema01.txt"
# 2. Choose your database type
qcraft query-type "PostgreSQL"
# 3. Start converting!
qcraft convert "Get all users who signed up this week" --provider free
๐ฅ Key Features
| Feature | Description | Status |
|---|---|---|
| ๐ฃ๏ธ Natural Language Processing | Convert plain English to SQL | โ |
| ๐ฏ Multi-Database Support | PostgreSQL, MySQL, MongoDB, SQLite & more | โ |
| ๐ค Multiple AI Providers | OpenAI, Ollama, LMStudio, Free tier | โ |
| ๐ Auto-Clipboard | Generated queries copied automatically | โ |
| ๐ Query Refinement | Retry and improve queries easily | โ |
| ๐ก Smart Explanations | Understand what your queries do | โ |
| โ๏ธ Configuration Management | Save settings for seamless workflow | โ |
| ๐จ Beautiful CLI Interface | Intuitive and visually appealing | โ |
๐ How QCraft Works
flowchart TD
Start([๐ฌ Start QCraft]) --> Schema{๐ Schema Set?}
Schema -->|No| SetSchema[๐ Set Database Schema]
SetSchema --> DbType[๐ง Configure Database Type]
Schema -->|Yes| DbType
DbType --> Convert[๐ฃ๏ธ Enter Natural Language Query]
Convert --> AI[๐ค AI Processing]
AI --> SQL[โก Generated SQL Query]
SQL --> Clipboard[๐ Auto-copy to Clipboard]
Clipboard --> Satisfied{๐ Satisfied?}
Satisfied -->|No| Refine[๐ Refine Query]
Refine --> AI
Satisfied -->|Yes| Done([๐ Done!])
style Start fill:#e1f5fe
style SetSchema fill:#f3e5f5
style Convert fill:#e8f5e8
style SQL fill:#fff3e0
style Done fill:#e8f5e8
๐ ๏ธ Command Reference
๐ Schema Management
# Paste schema directly
qcraft method --paste "CREATE TABLE users (id INT, name VARCHAR(50), email VARCHAR(100))"
# Extract schema from file
qcraft method --extract schema.sql
๐ง Database Configuration
# Set database type
qcraft query-type "PostgreSQL"
qcraft query-type "MongoDB"
qcraft query-type "MySQL"
๐ Query Conversion
# Basic conversion with free provider
qcraft convert "Find all active users" --provider free
# Use OpenAI with specific model
qcraft convert "Get top 10 customers by revenue" --provider openai --model gpt-4o-mini
# Use local Ollama
qcraft convert "Show recent orders" --provider ollama --model llama2
๐ ๏ธ Query Assistance
# Retry with improvements
qcraft assist retry "add ORDER BY date DESC" --provider free
# Get detailed explanation
qcraft assist explain --provider openai
โ๏ธ Configuration Management
# Set configuration values
qcraft config set DEFAULT_PROVIDER openai
qcraft config set API_KEY sk-your-api-key-here
# View current settings
qcraft config get SCHEMA
qcraft config list
# Clear all settings
qcraft config flush
๐ค AI Provider Options
Choose Your AI Power
| Provider | Cost | Setup Required | Best For | Models Available |
|---|---|---|---|---|
| ๐ Free | Free | None | Quick testing, learning | Built-in model |
| ๐ง OpenAI | Paid | API key | Best quality, complex queries | GPT-4, GPT-3.5-turbo |
| ๐ Ollama | Free | Local install | Privacy, offline use | Llama2, Mistral, CodeLlama |
| ๐ฅ๏ธ LMStudio | Free | Local install | GUI management | Various local models |
Setting Up Providers
๐ง OpenAI Setup
- Get API key from OpenAI Platform
- Set in QCraft:
qcraft config set API_KEY sk-your-openai-api-key
qcraft config set DEFAULT_PROVIDER openai
๐ Ollama Setup
- Install Ollama from ollama.ai
- Pull a model:
ollama pull llama2
- Configure QCraft:
qcraft config set DEFAULT_PROVIDER ollama
๐ Complete Workflow Example
Let's build a complete example from scratch:
1๏ธโฃ Database Schema Setup
qcraft method --paste "
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
product_name VARCHAR(100),
quantity INT,
price DECIMAL(10,2),
order_date DATE,
status VARCHAR(20)
);
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
registration_date DATE,
total_spent DECIMAL(12,2)
);"
2๏ธโฃ Configure Database Type
qcraft query-type "PostgreSQL"
3๏ธโฃ Natural Language Queries
# Simple query
qcraft convert "Show all pending orders" --provider free
# โ SELECT * FROM orders WHERE status = 'pending';
# Complex join query
qcraft convert "Get customer names and their total order count for customers who spent more than $1000" --provider free
# โ SELECT c.name, COUNT(o.order_id) as order_count
# FROM customers c
# JOIN orders o ON c.customer_id = o.customer_id
# WHERE c.total_spent > 1000
# GROUP BY c.customer_id, c.name;
# Aggregation with date filtering
qcraft convert "Find the top 5 products by revenue in the last 3 months" --provider free
# โ SELECT product_name, SUM(quantity * price) as revenue
# FROM orders
# WHERE order_date >= CURRENT_DATE - INTERVAL '3 months'
# GROUP BY product_name
# ORDER BY revenue DESC
# LIMIT 5;
4๏ธโฃ Query Refinement
# If the query needs improvement
qcraft assist retry "add customer email to the results" --provider free
# Get explanation
qcraft assist explain --provider free
๐ Database Support Matrix
| Database | SQL Queries | NoSQL Queries | Aggregations | Joins | Subqueries |
|---|---|---|---|---|---|
| PostgreSQL | โ | โ | โ | โ | โ |
| MySQL | โ | โ | โ | โ | โ |
| SQLite | โ | โ | โ | โ | โ |
| MongoDB | โ | โ | โ | โ | โ |
| Oracle | โ | โ | โ | โ | โ |
| SQL Server | โ | โ | โ | โ | โ |
๐ก Pro Tips & Best Practices
๐ฏ Writing Better Natural Language Queries
graph TD
A[๐ Natural Language Query] --> B{Is it Specific?}
B -->|No| C[โ Too Vague]
B -->|Yes| D{Mentions Tables?}
D -->|No| E[โ ๏ธ Could be Better]
D -->|Yes| F{Includes Criteria?}
F -->|No| G[โ Good]
F -->|Yes| H[๐ Excellent!]
C --> C1[Example: 'Get data']
E --> E1[Example: 'Show recent items']
G --> G1[Example: 'Get customers from users table']
H --> H1[Example: 'Get active customers from users table created in last 30 days, sorted by name']
โ Do This
- โ "Get customers who ordered in January 2024, sorted by total spent"
- โ "Find products with low inventory (less than 10 units)"
- โ "Show top 5 salespeople by revenue this quarter"
- โ "List all orders with their customer names and product details"
โ Avoid This
- โ "Get some data"
- โ "Show me stuff"
- โ "Find things"
- โ "Get everything"
๐ Provider Selection Guide
flowchart TD
Start([Need a Query?]) --> Purpose{What's your purpose?}
Purpose -->|Quick Testing| Free[๐ Use Free Provider]
Purpose -->|Production Use| Quality{Need Best Quality?}
Purpose -->|Privacy Concerned| Local[๐ Use Ollama/LMStudio]
Quality -->|Yes| OpenAI[๐ง Use OpenAI]
Quality -->|Budget Conscious| Free
Free --> FreeResult[โ No setup, instant start]
OpenAI --> OpenAIResult[โ Best accuracy, requires API key]
Local --> LocalResult[โ Complete privacy, offline capable]
โก Performance Tips
- Schema Optimization: Keep schemas concise but descriptive
- Query Specificity: More specific queries = better results
- Model Selection: Use larger models for complex queries
- Retry Strategy: Use
assist retrywith specific improvements - Configuration: Set defaults to avoid repetitive commands
๐ง Advanced Configuration
Environment Variables
Create a .qcraft.env file in your project:
# AI Provider Settings
QCRAFT_DEFAULT_PROVIDER=openai
QCRAFT_API_KEY=sk-your-api-key-here
QCRAFT_DEFAULT_MODEL=gpt-4o-mini
# Database Settings
QCRAFT_DEFAULT_DB_TYPE=PostgreSQL
# Output Settings
QCRAFT_AUTO_COPY=true
QCRAFT_VERBOSE=false
Custom Schema Templates
Save frequently used schemas:
# E-commerce schema
qcraft config set ECOMMERCE_SCHEMA "CREATE TABLE products...; CREATE TABLE orders..."
# Analytics schema
qcraft config set ANALYTICS_SCHEMA "CREATE TABLE events...; CREATE TABLE users..."
Batch Processing
Process multiple queries from a file:
# Create queries.txt with one natural language query per line
qcraft batch-convert queries.txt --provider openai --output results.sql
๐จ Customization
CLI Themes
# Set your preferred theme
qcraft config set THEME dark
qcraft config set THEME light
qcraft config set THEME cyberpunk
Output Formats
# Different output formats
qcraft convert "get users" --format sql
qcraft convert "get users" --format json
qcraft convert "get users" --format explain
๐ค Contributing
We welcome contributions! Here's how you can help:
Development Setup
# Clone the repository
git clone https://github.com/yourusername/qcraft-cli.git
cd qcraft-cli
# Install dependencies
npm install
# Run in development mode
npm run dev
# Run tests
npm test
Contributing Guidelines
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature) - ๐ Commit your changes (
git commit -m 'Add amazing feature') - ๐ค Push to the branch (
git push origin feature/amazing-feature) - ๐ Open a Pull Request
๐ Roadmap
๐ง Coming Soon
- Web Interface: Browser-based GUI for QCraft
- VS Code Extension: IDE integration
- Query History: Save and reuse previous queries
- Team Collaboration: Share schemas and queries
- Performance Analytics: Query optimization suggestions
- More AI Providers: Anthropic Claude, Google Bard
- Schema Auto-detection: Extract schema from existing databases
- Query Validation: Syntax checking before execution
๐ฏ Future Versions
- v2.0: Web dashboard and team features
- v2.1: Advanced query optimization
- v2.2: Multi-database support in single queries
- v3.0: Visual query builder integration
๐ Troubleshooting
Common Issues
โ "Schema not set" error
Solution:
# Check current schema
qcraft config get SCHEMA
# Set schema if empty
qcraft method --paste "YOUR_SCHEMA_HERE"
โ API key errors
Solution:
# Verify API key is set
qcraft config get API_KEY
# Set API key
qcraft config set API_KEY your-api-key-here
# Try with free provider first
qcraft convert "test query" --provider free
โ Generated query doesn't work
Solution:
# Get explanation
qcraft assist explain --provider free
# Retry with more specific instructions
qcraft assist retry "fix the column names" --provider free
Debug Mode
Enable verbose logging:
qcraft convert "your query" --verbose --provider free
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- ๐ค OpenAI for powering our AI capabilities
- ๐ฆ Ollama team for local AI support
- ๐ The open-source community for inspir
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file query_crafter_cli-0.1.0.tar.gz.
File metadata
- Download URL: query_crafter_cli-0.1.0.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee592f9ced595f9d3d32aef10dd94e20241f54974eea6cf3872a514fda576b70
|
|
| MD5 |
b0d9d2edd7ff3f0496b5487c92050cfc
|
|
| BLAKE2b-256 |
3e47c87abbc9231f17fe181a2794a263473085764e97194393f0f6ce3ef178c1
|
File details
Details for the file query_crafter_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: query_crafter_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b87da757330265592dccb6ad59abc68898f20dd88bc83b7845244cc1d7164c05
|
|
| MD5 |
083c5a105b35b0f4f803081003e6e35b
|
|
| BLAKE2b-256 |
1f1136e5b26807df20331ac9522059783e328e25fdc8b9cbdecdc31c6f15fd16
|