Skip to content

Auto SQL Reviewer is an AI-powered tool that automatically reviews and formats SQL queries

Notifications You must be signed in to change notification settings

gameofdatas/auto-sql-reviewer-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto SQL Reviewer & Formatter

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.

🚀 Features

  • 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.

📂 Project Structure

├── 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

🛠 Prerequisites

  • Go ≥ 1.20
  • Docker (if running Ollama inside Docker)
  • Ollama installed locally or running via Docker
  • A downloaded model (default: llama3)

⚙️ Setup Instructions

1️⃣ Clone the repository

git clone https://github.com/yourusername/auto-sql-reviewer.git
cd auto-sql-reviewer

2️⃣ Install dependencies

go mod tidy

3️⃣ Run Ollama

Option A — Native installation

Install Ollama from ollama.ai/download, then:

ollama pull llama3
ollama serve

Option B — Docker

docker run -d --name ollama \
  -p 11434:11434 \
  -v ollama:/root/.ollama \
  ollama/ollama

docker exec -it ollama ollama pull llama3

4️⃣ Environment variables

You can override the model via:

export LOCAL_LLM_MODEL=llama3

(Default: llama3)


5️⃣ Run the Go API server

go run main.go

This will start the API on http://127.0.0.1:8080.


6️⃣ Open the Web UI

Open index.html in your browser.

  • Enter SQL in the textarea
  • Click Review SQL or Format SQL
  • See results in the separate output block

📡 API Endpoints

Review SQL

curl -X POST http://127.0.0.1:8080/review \
  -H "Content-Type: application/json" \
  -d '{"sql":"SELECT * FROM orders;"}'

Format SQL

curl -X POST http://127.0.0.1:8080/format \
  -H "Content-Type: application/json" \
  -d '{"sql":"select * from orders;"}'

⚠️ Common Issues

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

📜 License

MIT License. Do whatever you want, just give credit.

About

Auto SQL Reviewer is an AI-powered tool that automatically reviews and formats SQL queries

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published