A simple web-based tool to review and format SQL queries using a local Large Language Model (LLM) via Ollama. It provides two main features:
- Review SQL → Detect performance issues, anti-patterns, and suggest improvements.
- Format SQL → Return clean, properly indented SQL with standard casing.
- Uses a local LLM model (default:
llama3) for processing. - REST API backend written in Go.
- Simple HTML/JS frontend.
- Works entirely offline once the model is downloaded.
- No streaming — faster to return a complete response.
├── cmd
│ └── server
│ └── main.go
├── go.mod
├── go.sum
├── internal
│ ├── api
│ │ ├── format.go
│ │ └── review.go
│ └── llm
│ ├── localllm.go
│ ├── openai.go
│ └── provider.go
├── readme.md
└── static
└── index.html
- Go ≥ 1.20
- Docker (if running Ollama inside Docker)
- Ollama installed locally or running via Docker
- A downloaded model (default:
llama3)
git clone https://github.com/yourusername/auto-sql-reviewer.git
cd auto-sql-reviewergo mod tidyInstall Ollama from ollama.ai/download, then:
ollama pull llama3
ollama servedocker run -d --name ollama \
-p 11434:11434 \
-v ollama:/root/.ollama \
ollama/ollama
docker exec -it ollama ollama pull llama3You can override the model via:
export LOCAL_LLM_MODEL=llama3(Default: llama3)
go run main.goThis will start the API on http://127.0.0.1:8080.
Open index.html in your browser.
- Enter SQL in the textarea
- Click Review SQL or Format SQL
- See results in the separate output block
curl -X POST http://127.0.0.1:8080/review \
-H "Content-Type: application/json" \
-d '{"sql":"SELECT * FROM orders;"}'curl -X POST http://127.0.0.1:8080/format \
-H "Content-Type: application/json" \
-d '{"sql":"select * from orders;"}'| Issue | Cause | Fix |
|---|---|---|
model "llama3" not found |
Model not pulled | Run ollama pull llama3 inside container or locally |
| Slow responses | Large models take time to process | Use smaller model (llama2, mistral, etc.) |
permission denied /var/run/docker.sock |
Docker socket access issue | Add user to docker group: sudo usermod -aG docker $USER |
MIT License. Do whatever you want, just give credit.