Skip to content

Velorithms/querify-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Querify AI - Natural Language to SQL Query Tool

Version Next.js TypeScript Prisma

Transform natural language questions into SQL queries using AI. Perfect for data analysts, developers, and anyone who needs to query databases without writing SQL.

✨ Features

Core Features

  • 🤖 AI-Powered SQL Generation - Convert natural language to PostgreSQL queries using Google Gemini AI
  • 📊 Multiple Chart Types - Visualize data with bar, line, and pie charts
  • 📈 Real-time Results - Execute queries and see results instantly
  • 🔒 SQL Safety Validation - Prevents dangerous operations (only SELECT allowed)
  • 💾 Query History - Track and replay previous queries
  • 📥 CSV Export - Download query results as CSV files
  • Smart Schema Detection - Automatically understands your database structure

Advanced Features

  • 🎯 Intelligent Query Optimization - AI suggests proper JOINs and aggregations
  • 📱 Responsive Design - Works on desktop, tablet, and mobile
  • ⌨️ Keyboard Shortcuts - Press Ctrl+Enter to run queries
  • 🎨 Beautiful UI - Modern, gradient-based design with smooth animations
  • 🔄 Schema Caching - Improved performance with smart caching

🚀 Quick Start

Prerequisites

  • Node.js 20+ installed
  • PostgreSQL database
  • Google Gemini API key (Get one here)

Installation

  1. Install dependencies
npm install
  1. Set up environment variables

Create a .env file in the root directory:

# Database connection
DATABASE_URL="postgresql://username:password@localhost:5432/your_database"

# Google Gemini API Key
GEMINI_API_KEY="your_gemini_api_key_here"

# Optional: Node environment
NODE_ENV="development"
  1. Set up the database
# Push Prisma schema to database
npx prisma db push

# Seed with sample data
npx prisma db seed
  1. Run the development server
npm run dev
  1. Open your browser Navigate to http://localhost:3000

📖 Usage Guide

Basic Queries

Just type natural language questions:

  • "Show me the top 5 products by revenue"
  • "How many orders does each user have?"
  • "What's the average order value?"
  • "List all users who bought a Laptop"
  • "Show monthly revenue trend for 2024"

Query Examples

Simple Aggregation:

Total number of orders

Top N with Sorting:

Top 10 customers by total spending

Time-based Analysis:

Monthly sales for 2024

Advanced Features

Query History:

  • Click the "History" button in the header
  • View all past queries with row counts and timestamps
  • Click any history item to reload that question

Export Data:

  • After running a query, click "Export CSV"
  • Downloads results as a CSV file

Chart Types:

  • Switch between Bar, Line, and Pie charts
  • Only available when results contain numeric data

Keyboard Shortcuts:

  • Ctrl + Enter or Cmd + Enter - Run query
  • Click example chips for instant queries

🗄️ Database Schema

The app comes with a sample e-commerce schema:

Tables

users - Customer information

  • id, name, email

products - Product catalog

  • id, name, price

orders - Order records

  • id, user_id, order_date, total

order_items - Order line items

  • id, order_id, product_id, quantity, unit_price

Sample Data

The seed script creates:

  • 8 users
  • 8 products
  • 40 orders with random items and dates

🛠️ Tech Stack

  • Frontend: Next.js 15, React 19, TypeScript
  • Styling: Tailwind CSS 4
  • Database: PostgreSQL with Prisma ORM
  • Charts: Recharts
  • AI: Google Gemini 2.0 Flash

🔐 Security Features

SQL Injection Prevention

  • Only SELECT queries allowed
  • Validates against dangerous keywords
  • Blocks multiple statements
  • Removes SQL comments before execution

🐛 Troubleshooting

Common Issues

"API key not configured"

  • Ensure GEMINI_API_KEY is set in your .env file
  • Restart the dev server after adding environment variables

"Database connection failed"

  • Check your DATABASE_URL format
  • Ensure PostgreSQL is running
  • Verify database credentials

"No tables found"

  • Run npx prisma db push to create tables
  • Check that you're using the correct database

🚀 Deployment

Vercel (Recommended)

  1. Push your code to GitHub
  2. Import project in Vercel
  3. Add environment variables in Vercel dashboard:
    • DATABASE_URL
    • GEMINI_API_KEY
  4. Deploy!

Compatible with: Netlify, Railway, AWS Amplify, Google Cloud Run

📈 Performance Tips

  1. Use specific questions - More specific = better SQL
  2. Include table names - AI works better with context
  3. Limit large results - Mention "top 10" or "limit 100"
  4. Use proper date formats - Specify years/months clearly

📝 License

MIT License - feel free to use this project for personal or commercial purposes.


Made with ❤️ using Next.js, TypeScript, and AI

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors