SpeakWithSQL is a simple Node.js + Express demo that lets you ask questions in plain English and get SQL queries as answers, powered by OpenAI. It’s designed to show how natural language can be used to generate SQL for real-world databases.
- Convert natural language questions to SQL queries using OpenAI
- Choose your SQL dialect (SQLite, PostgreSQL, MySQL, MSSQL)
- Modern, clean chat interface (with avatars and responsive design)
- Few-shot prompt engineering for better SQL quality
- Example academic/research database schema and dummy data
- Modular backend (Express, controllers, routes, services)
- Type a question in the chat (e.g., "List all users and their ORCID numbers.")
- Select your SQL dialect
- The backend sends your question and schema to OpenAI
- OpenAI returns a SQL query, which is shown in the chat
Prerequisites:
- Node.js (v18 or later)
- An OpenAI API key (get one here)
Installation:
- Clone the repository:
git clone https://github.com/mobilerast/speakwithsql.git cd speakwithsql
- Install dependencies:
npm install
- Add your OpenAI API key to a
.env
file:OPENAI_API_KEY=sk-...
- (Optional) Set up your SQL database using
dummy_data.sql
.
Running the App:
npm run dev
# or
npm start
Open http://localhost:3000 in your browser.
- List all users and their ORCID numbers.
- Show the names of users and the universities they are affiliated with, only for users from Boğaziçi Üniversitesi.
- How many publications does each user have? List user names with their publication counts.
- List all publications from the year 2024 with their titles and citation counts.
speakwithsql/
├── package.json
├── server.js
├── controllers/
│ └── chatController.js
├── routes/
│ └── chatRoutes.js
├── services/
│ └── openaiService.js
├── public/
│ └── index.html
├── dummy_data.sql
├── .env
└── .gitignore
Mehmet Alp ([email protected])
GitHub: https://github.com/mobilerast/speakwithsql
Learn more: https://rastmobile.com/en/services/ai-server-llm-services
This project is for demonstration and prototyping purposes. It does not execute SQL queries by default. Always review generated SQL before running it on your database.