sqlchat/sqlchat
Chat-based SQL Client and Editor for the next decade
SQL Chat – a chat‑based SQL client powered by LLMs
What it is
- A web app that lets you talk to a database in natural language. You type or speak a request (e.g. “show me the top 5 customers by revenue last month”) and the system translates it into SQL, runs the query, and returns the result in the chat window.
- It also supports data‑modifying commands (INSERT/UPDATE/DELETE) and can handle multiple database engines.
Why it matters
- Traditional SQL clients require you to remember syntax, switch between UI panels, and manually write queries. By using a conversational interface, developers and analysts can work faster, especially when they’re not SQL experts.
- It showcases the emerging Developer Tools 2.0 trend: AI‑augmented interfaces that replace complex GUIs with simple chat.
How it works
- Frontend – built with Next.js, providing a chat UI.
- LLM backend – calls the OpenAI API (or any compatible endpoint such as Ollama) to turn natural‑language prompts into SQL statements.
- Database adapters – currently supports MySQL, PostgreSQL, MSSQL, TiDB Cloud, and OceanBase. The generated SQL is sent to the selected database and the result is displayed.
- Optional services – when a PostgreSQL database is configured, the app can store user accounts, enforce per‑user quotas, handle payments, and collect usage metrics.
Running it yourself
Docker (quick start)
docker run --name sqlchat \ --platform linux/amd64 \ --env NEXTAUTH_SECRET=$(openssl rand -hex 5) \ --env OPENAI_API_KEY=YOUR_KEY \ -p 3000:3000 sqlchat/sqlchatThe container runs the full app on
http://localhost:3000. If you need to connect to a local DB, usehost.docker.internalas the host name.Self‑host with a database
- Copy the appropriate example env file (
.env.usedbfor full features or.env.nodbfor a single‑user demo). - Fill in
OPENAI_API_KEY(or pointOPENAI_API_ENDPOINTto a self‑hosted model like Ollama). - If you enable
NEXT_PUBLIC_USE_DATABASE=true, setDATABASE_URLto a PostgreSQL connection string and run the Prisma migrations (pnpm prisma migrate dev). - Start the app with
pnpm dev(or via Docker as shown above).
- Copy the appropriate example env file (
Key configuration knobs
OPENAI_API_KEY– required for the LLM; you can also let users provide their own key (NEXT_PUBLIC_ALLOW_SELF_OPENAI_KEY=true).OPENAI_API_ENDPOINT– lets you swap OpenAI for a local model.NEXT_PUBLIC_USE_DATABASE– toggles the account/quota/payment layer.NEXT_PUBLIC_ALLOW_SELF_OPENAI_KEY– enables a “bring‑your‑own‑key” mode for end users.
Typical use cases
- Quick ad‑hoc data exploration for analysts who know the question but not the exact SQL.
- Prototyping queries while learning a new schema.
- Building a SaaS front‑end (like sqlchat.ai) that offers AI‑driven database access with user accounts and billing.
Limitations & gotchas
- The quality of generated SQL depends on the LLM and the prompt; complex queries may need manual tweaking.
- When using the hosted service (sqlchat.ai) you must whitelist
0.0.0.0on your DB because Vercel deployments use dynamic IPs. - OpenAI usage incurs cost and quota limits; the app surfaces errors when the key runs out of credit.
Where to learn more
- Live demo & hosted version: https://sqlchat.ai
- Repository: https://github.com/sqlchat/sqlchat (includes Docker instructions, Prisma schema, and UI code)
- Privacy policy: https://sqlchat.ai/privacy
SQL Chat is an open‑source, AI‑enhanced developer tool that turns natural‑language conversation into executable SQL, making database interaction faster and more accessible.
Related
- Project
- Project
- Project
- Project