Transform natural language questions into SQL queries using AI. Perfect for data analysts, developers, and anyone who needs to query databases without writing SQL.
- 🤖 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
- 🎯 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
- Node.js 20+ installed
- PostgreSQL database
- Google Gemini API key (Get one here)
- Install dependencies
npm install- 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"- Set up the database
# Push Prisma schema to database
npx prisma db push
# Seed with sample data
npx prisma db seed- Run the development server
npm run dev- Open your browser Navigate to http://localhost:3000
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"
Simple Aggregation:
Total number of orders
Top N with Sorting:
Top 10 customers by total spending
Time-based Analysis:
Monthly sales for 2024
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 + EnterorCmd + Enter- Run query- Click example chips for instant queries
The app comes with a sample e-commerce schema:
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
The seed script creates:
- 8 users
- 8 products
- 40 orders with random items and dates
- Frontend: Next.js 15, React 19, TypeScript
- Styling: Tailwind CSS 4
- Database: PostgreSQL with Prisma ORM
- Charts: Recharts
- AI: Google Gemini 2.0 Flash
- Only SELECT queries allowed
- Validates against dangerous keywords
- Blocks multiple statements
- Removes SQL comments before execution
"API key not configured"
- Ensure
GEMINI_API_KEYis set in your.envfile - Restart the dev server after adding environment variables
"Database connection failed"
- Check your
DATABASE_URLformat - Ensure PostgreSQL is running
- Verify database credentials
"No tables found"
- Run
npx prisma db pushto create tables - Check that you're using the correct database
- Push your code to GitHub
- Import project in Vercel
- Add environment variables in Vercel dashboard:
DATABASE_URLGEMINI_API_KEY
- Deploy!
Compatible with: Netlify, Railway, AWS Amplify, Google Cloud Run
- Use specific questions - More specific = better SQL
- Include table names - AI works better with context
- Limit large results - Mention "top 10" or "limit 100"
- Use proper date formats - Specify years/months clearly
MIT License - feel free to use this project for personal or commercial purposes.
Made with ❤️ using Next.js, TypeScript, and AI