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

  1. Frontend – built with Next.js, providing a chat UI.
  2. LLM backend – calls the OpenAI API (or any compatible endpoint such as Ollama) to turn natural‑language prompts into SQL statements.
  3. 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.
  4. 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/sqlchat
    

    The container runs the full app on http://localhost:3000. If you need to connect to a local DB, use host.docker.internal as the host name.

  • Self‑host with a database

    1. Copy the appropriate example env file (.env.usedb for full features or .env.nodb for a single‑user demo).
    2. Fill in OPENAI_API_KEY (or point OPENAI_API_ENDPOINT to a self‑hosted model like Ollama).
    3. If you enable NEXT_PUBLIC_USE_DATABASE=true, set DATABASE_URL to a PostgreSQL connection string and run the Prisma migrations (pnpm prisma migrate dev).
    4. Start the app with pnpm dev (or via Docker as shown above).

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.0 on 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


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