├── assets ├── supershot.png ├── sql-ease-sqr.png └── buildspace-logo.png ├── public ├── favicon.ico ├── favicon.png ├── black-button.png ├── query-analysis.ico ├── violet-button.png └── vercel.svg ├── next.config.js ├── pages ├── _app.js ├── _document.js ├── api │ └── generate.js ├── index.js └── styles.css ├── .gitignore ├── package.json ├── README.md └── yarn.lock /assets/supershot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/assets/supershot.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/public/favicon.png -------------------------------------------------------------------------------- /assets/sql-ease-sqr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/assets/sql-ease-sqr.png -------------------------------------------------------------------------------- /public/black-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/public/black-button.png -------------------------------------------------------------------------------- /public/query-analysis.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/public/query-analysis.ico -------------------------------------------------------------------------------- /public/violet-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/public/violet-button.png -------------------------------------------------------------------------------- /assets/buildspace-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjun-ms/SQL-Ease/HEAD/assets/buildspace-logo.png -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | } 5 | 6 | module.exports = nextConfig 7 | -------------------------------------------------------------------------------- /pages/_app.js: -------------------------------------------------------------------------------- 1 | import './styles.css'; 2 | 3 | function App({ Component, pageProps }) { 4 | return 5 | } 6 | export default App; 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | 38 | .env -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scratchpad", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@emotion/react": "^11.10.5", 13 | "@emotion/styled": "^11.10.5", 14 | "eslint": "8.27.0", 15 | "eslint-config-next": "13.0.3", 16 | "framer-motion": "^6.5.1", 17 | "next": "^13.0.7", 18 | "openai": "^4.0.0", 19 | "react": "^18.2.0", 20 | "react-dom": "^18.2.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pages/_document.js: -------------------------------------------------------------------------------- 1 | import { Html, Head, Main, NextScript } from 'next/document' 2 | 3 | export default function Document() { 4 | return ( 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | 6 | --- 7 | 8 |

9 |

Are you tired of struggling with SQL syntax? 🤨

10 |

Introducing an AI-powered web app to generate SQL query from plain english 📃

11 |

12 | 13 | --- 14 | ❤️ If you like the product, consider an upvote → 15 | [SQL Ease](https://www.producthunt.com/posts/sql-ease) 16 | 17 |
18 | 19 | ![SQL Ease](/assets/supershot.png) 20 | 21 |
22 | 23 | ## Features ❤️‍🔥 24 | 25 | - Generate SQL Queries from Plain English 26 | - Cross platform 27 | 28 |
29 | 30 | ## Demo 📼 31 | 32 | [![SQL Query generator using AI #shorts](https://img.youtube.com/vi/S_bu1qPaz_w/0.jpg)](https://www.youtube.com/watch?v=S_bu1qPaz_w) 33 | 34 |
35 | 36 | ## Environment Variables 🔑 37 | 38 | To run this project, you will need to add the following environment variables to your .env file 39 | 40 | `OPENAI_API_KEY` 41 | 42 |
43 | 44 | ## Run Locally 🏃🏻 45 | 46 | Clone the project 47 | 48 | ```bash 49 | git clone https://github.com/arjun-ms/SQL-Ease.git 50 | ``` 51 | 52 | Go to the project directory 53 | 54 | ```bash 55 | cd SQL-Ease 56 | ``` 57 | 58 | Install dependencies 59 | 60 | ```bash 61 | npm install 62 | ``` 63 | 64 | Start the server 65 | 66 | ```bash 67 | npm run start 68 | ``` 69 | 70 |
71 | 72 | ## Contributing 📜 73 | 74 | Pull requests are welcome. For major changes, please open an issue first 75 | to discuss what you would like to change. 76 | 77 | Please make sure to update tests as appropriate. 78 | 79 |
80 | 81 | ## Feedback 📮 82 | 83 | If you have any feedback, please reach out to us at arjunachu123.aa@gmail.com 84 | 85 | -------------------------------------------------------------------------------- /pages/api/generate.js: -------------------------------------------------------------------------------- 1 | // import { Configuration, OpenAIApi } from 'openai'; 2 | 3 | // const configuration = new Configuration({ 4 | // apiKey: process.env.OPENAI_API_KEY, 5 | // }); 6 | 7 | // const openai = new OpenAIApi(configuration); 8 | 9 | // const basePromptPrefix = "Write an SQL query for: "; 10 | // const generateAction = async (req, res) => { 11 | // // Run first prompt 12 | // console.log(`API: ${basePromptPrefix}${req.body.userInput}`) 13 | 14 | // const baseCompletion = await openai.createCompletion({ 15 | // model: 'text-davinci-003', 16 | // prompt: `${basePromptPrefix}${req.body.userInput}`, 17 | // temperature: 0.7, 18 | // max_tokens: 250, 19 | // }); 20 | 21 | // const basePromptOutput = baseCompletion.data.choices.pop(); 22 | 23 | // res.status(200).json({ output: basePromptOutput }); 24 | // }; 25 | 26 | // export default generateAction; 27 | 28 | 29 | 30 | //================================= GROQ INFERENCE ================================ 31 | 32 | 33 | 34 | import OpenAI from "openai"; 35 | 36 | const client = new OpenAI({ 37 | apiKey: process.env.GROQ_API_KEY, // keep this safe in .env.local 38 | baseURL: "https://api.groq.com/openai/v1", 39 | }); 40 | 41 | const basePromptPrefix = ` 42 | Role: You are an expert SQL query writer with deep knowledge of relational databases. 43 | Task: Given a natural language request, write a correct, optimized SQL query that fulfills the request. 44 | Context: Assume a generic SQL database (PostgreSQL-compatible). 45 | - Do not include explanations, comments, or extra text. 46 | - Only return the SQL query as plain text. 47 | Request: 48 | `; 49 | 50 | const generateAction = async (req, res) => { 51 | try { 52 | console.log(`API: ${basePromptPrefix}${req.body.userInput}`); 53 | 54 | const response = await client.responses.create({ 55 | // model: "mixtral-8x7b-instruct", // Groq recommends Mixtral for SQL/text 56 | model: "openai/gpt-oss-120b", // gpt oss model 57 | input: `${basePromptPrefix}${req.body.userInput}`, 58 | temperature: 0.8, 59 | max_output_tokens: 250, 60 | }); 61 | 62 | // response.output is an array of structured outputs, easier to flatten: 63 | const outputText = response.output_text; 64 | 65 | res.status(200).json({ output: outputText }); 66 | } catch (error) { 67 | console.error(error); 68 | res.status(500).json({ error: "Something went wrong." }); 69 | } 70 | }; 71 | 72 | export default generateAction; 73 | -------------------------------------------------------------------------------- /pages/index.js: -------------------------------------------------------------------------------- 1 | import Head from 'next/head'; 2 | import Image from 'next/image'; 3 | // import buildspaceLogo from '../assets/buildspace-logo.png'; 4 | import { useState } from 'react'; 5 | 6 | const Home = () => { 7 | const [userInput, setUserInput] = useState(''); 8 | const [apiOutput, setApiOutput] = useState('') 9 | const [isGenerating, setIsGenerating] = useState(false) 10 | 11 | const callGenerateEndpoint = async () => { 12 | setIsGenerating(true); 13 | 14 | console.log("Calling API...") 15 | const response = await fetch('/api/generate', { 16 | method: 'POST', 17 | headers: { 18 | 'Content-Type': 'application/json', 19 | }, 20 | body: JSON.stringify({ userInput }), 21 | }); 22 | 23 | if (!response.ok) { 24 | // Handle HTTP errors (like 405, 500, etc.) 25 | const errorData = await response.json().catch(() => ({})); 26 | throw new Error(errorData.error || "Something went wrong"); 27 | } 28 | 29 | const data = await response.json(); 30 | const { output } = data; 31 | // console.log("OpenAI replied...", output.text) 32 | 33 | // setApiOutput(`${output.text}`); 34 | 35 | // Groq API response 36 | console.log("API replied...", output); 37 | setApiOutput(output); 38 | 39 | setIsGenerating(false); 40 | } 41 | const onUserChangedText = (event) => { 42 | console.log(event.target.value); 43 | setUserInput(event.target.value); 44 | }; 45 | return ( 46 |
47 |
48 |
49 |
50 |

Generate SQL Queries from Natural Language

51 |
52 |
53 |

Write a quick sentence about what you want the query to be about (ex. Find name of all students in the table, Fetch current date-time from the system, create a table called heroes).

54 |
55 |
56 | {/* Add this code here*/} 57 |
58 |