Skip to main content

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
  1. Get API key from OpenAI Platform
  2. Set in QCraft:
qcraft config set API_KEY sk-your-openai-api-key
qcraft config set DEFAULT_PROVIDER openai
๐Ÿ  Ollama Setup
  1. Install Ollama from ollama.ai
  2. Pull a model:
ollama pull llama2
  1. 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

  1. Schema Optimization: Keep schemas concise but descriptive
  2. Query Specificity: More specific queries = better results
  3. Model Selection: Use larger models for complex queries
  4. Retry Strategy: Use assist retry with specific improvements
  5. 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

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’ Commit your changes (git commit -m 'Add amazing feature')
  4. ๐Ÿ“ค Push to the branch (git push origin feature/amazing-feature)
  5. ๐Ÿ” 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

query_crafter_cli-0.1.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

query_crafter_cli-0.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

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

Hashes for query_crafter_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee592f9ced595f9d3d32aef10dd94e20241f54974eea6cf3872a514fda576b70
MD5 b0d9d2edd7ff3f0496b5487c92050cfc
BLAKE2b-256 3e47c87abbc9231f17fe181a2794a263473085764e97194393f0f6ce3ef178c1

See more details on using hashes here.

File details

Details for the file query_crafter_cli-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for query_crafter_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b87da757330265592dccb6ad59abc68898f20dd88bc83b7845244cc1d7164c05
MD5 083c5a105b35b0f4f803081003e6e35b
BLAKE2b-256 1f1136e5b26807df20331ac9522059783e328e25fdc8b9cbdecdc31c6f15fd16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page