https://github.com/ah-naf/nlsql
Natural Language to SQL using LLM
https://github.com/ah-naf/nlsql
gin golang llm postgresql
Last synced: 3 months ago
JSON representation
Natural Language to SQL using LLM
- Host: GitHub
- URL: https://github.com/ah-naf/nlsql
- Owner: ah-naf
- Created: 2025-04-19T05:30:07.000Z (about 1 year ago)
- Default Branch: origin
- Last Pushed: 2025-04-26T16:15:25.000Z (about 1 year ago)
- Last Synced: 2025-04-26T16:39:22.251Z (about 1 year ago)
- Topics: gin, golang, llm, postgresql
- Language: TypeScript
- Homepage:
- Size: 34.3 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NL→SQL
A simple web application that lets you ask natural-language questions about your PostgreSQL database and have them converted into SQL queries by an LLM. It includes schema browsing, query confirmation for destructive statements, and result display with pagination and hover-tooltips.
---
## ✨ Features
- **Natural Language → SQL**: Describe what you want in plain English, and the app generates a SQL statement.
- **Schema Browser**: View tables, columns, data types, primary/foreign key badges, and search/filter tables.
- **Confirmation Flow**: Destructive operations (INSERT, UPDATE, DELETE, etc.) require confirmation.
- **Result Rendering**: Paginated, responsive table with hover popovers for long content.
- **Database Connection**: Connect to or create databases directly from the UI.
---
## 🔧 Environment Variables
Place a `.env` file at the project root with the following:
```ini
# For Together AI (default)
LLM_API_KEY=your-together-api-key
LLM_API_URL=https://api.together.xyz/v1/chat/completions
LLM_API_MODEL_NAME=meta-llama/Llama-3-70B-Instruct
# OR for Gemini (optional alternative)
GEMINI_API_URL=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=your-gemini-api-key
````
## 🚀 Local Development
### 1. Clone the repository
```bash
git clone https://github.com/ah-naf/nlsql.git
cd nlsql
```
### 2. Backend setup
```bash
cd backend
go mod tidy
```
### 3. Frontend setup
```bash
cd ../frontend
npm install
npm run build
```
### 4. Run the application
```bash
cd ../backend
go run cmd/main.go
```
Open `http://localhost:8080` in your browser.
---
## 🐳 Run with Docker
This project supports multi-stage Docker builds (frontend + backend). Here's how to build and run:
### 1. Build the image
```bash
docker build -t nlsql-app .
```
### 2. Run the container
```bash
docker run -p 8080:8080 nlsql-app
```
> Make sure your PostgreSQL instance is accessible from the container.
### 3. Open the app
Visit: [http://localhost:8080](http://localhost:8080)
---
## 💡 Example Prompts
* `Show all orders placed in the last 24 hours`
* `Add a new user named Alice with email alice@example.com`
* `Delete all rows from temp_sessions table`
---
## 📄 License
This project is open-source and available under the [MIT License](LICENSE).