Skip to content

Chat-based SQL Client and Editor for the next decade

License

Notifications You must be signed in to change notification settings

zhangbinhui/sqlchat

 
 

Repository files navigation

SQL Chat banner

SQL Chat

vercel

English | 中文 | Español

What

SQL Chat is a chat-based SQL client, which uses natural language to communicate with the database to implement operations such as query, modification, addition, and deletion of the database.

Screenshot

Screenshot

Screenshot

Why

As we enter the Developer Tools 2.0 era, there is a massive opportunity to rebuild the existing tools using the chat-based interface. SQL Client is no exception. Instead of navigating across many UI controls, a chat-based interface is much more intuitive. Of course, only if that works, and our goal is to deliver that experience.

How

SQL Chat is built by Next.js, it supports the following databases and will add more over time:

  • MySQL
  • PostgreSQL
  • MSSQL
  • TiDB Cloud

Data Privacy

See SQL Chat Privacy Policy.

IP Whitelisting

If you use sqlchat.ai to connect to your database, you need to add 0.0.0.0 (allow all connections) to the database whitelist IP. Because sqlchat.AI is hosted on Vercel which uses dynamic IP. If this is a concern, please consider the self-host option below.

Self-host with Docker

docker run --name sqlchat --platform linux/amd64 -env NEXTAUTH_SECRET=xxx -p 3000:3000 sqlchat/sqlchat

OpenAI related variables:

  • OPENAI_API_KEY: OpenAI API key. You can get one from here.

  • OPENAI_API_ENDPOINT: OpenAI API endpoint. Defaults to https://api.openai.com.

Database related variables:

  • NEXT_PUBLIC_DATABASE_LESS: Set to true to start SQL Chat in database-less mode. This will disable following features:
    1. Account system.
    2. Per-user quota enforcement.
    3. Payment.
    4. Usage data collection.
  • DATABASE_URL: Applicable if NEXT_PUBLIC_DATABASE_LESS is false. Postgres connection string to store data. e.g. postgresql://postgres:YOUR_PASSWORD@localhost:5432/sqlchat?schema=sqlchat.
docker run --name sqlchat --platform linux/amd64 --env NEXTAUTH_SECRET=xxx --env OPENAI_API_KEY=yyy --env OPENAI_API_ENDPOINT=zzz -p 3000:3000 sqlchat/sqlchat

Local Development

  1. Install dependencies

    pnpm i
  2. Generate prisma client

    pnpm prisma generate
  3. Make a copy of the example environment variables file:

    cp .env.example .env
  4. Add your API key and OpenAI API Endpoint(optional) to the newly created .env file.

Setup database

You can skip this section with NEXT_PUBLIC_DATABASE_LESS=true if you don't build features requiring database

  1. Start a Postgres instance. For mac, you can use StackbBricks, DBngin or Postgres.app.

  2. Create a database:

    CREATE DATABASE sqlchat;

    In .env file, assign the connection string to environment variable DATABASE_URL and DATABASE_DIRECT_URL. This article explains why we need two URLs.

  3. Set up database schema

    pnpm prisma migrate dev
  4. (Optional) Seed data

    pnpm prisma db seed

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=sqlchat/sqlchat&type=Date)](https://star-history.com/#sqlchat/sqlchat&Date)

## Community

[![Hang out on Discord](https://img.shields.io/badge/%20-Hang%20out%20on%20Discord-5865F2?style=for-the-badge&logo=discord&labelColor=EEEEEE)](https://discord.gg/z6kakemDjm)

[![Follow us on Twitter](https://img.shields.io/badge/Follow%20us%20on%20Twitter-1DA1F2?style=for-the-badge&logo=twitter&labelColor=EEEEEE)](https://twitter.com/Bytebase)

<img width="256" src="https://raw.githubusercontent.com/sqlchat/sqlchat/main/public/wechat-qrcode.webp" alt="sqlchat">

## Sponsors

<p>
<a href="https://www.bytebase.com">
  <img src="https://raw.githubusercontent.com/sqlchat/sqlchat/main/public/bytebase.webp" width=300>
</a>
</p>

## License

This project is under the BSL License. See the [LICENSE](LICENSE) file for the full license text.

## FAQ

<details><summary>How to self host SQL Chat?</summary>
<p>

- You can deploy SQL Chat to Vercel with one click

<a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fsqlchat%2Fsqlchat&env=OPENAI_API_KEY"><img src="https://img.shields.io/badge/deploy%20on-Vercel-brightgreen.svg?style=for-the-badge&logo=vercel" alt="vercel"></a>

- You can deploy your SQL Chat with docker in seconds

```bash
docker run --name sqlchat --platform linux/amd64 -p 3000:3000 sqlchat/sqlchat

How to use my OpenAI API key?

  • You can set the OPENAI_API_KEY in environment variable.

    docker run --name sqlchat --platform linux/amd64 --env OPENAI_API_KEY=xxx -p 3000:3000 sqlchat/sqlchat
  • You can set the OPENAI_API_KEY in setting dialog.

It always says that I have a network connection issue?

Please make sure you have a stable network connection which can access the OpenAI API endpoint. If you cannot access the OpenAI API endpoint, you can try to set the OPENAI_API_ENDPOINT in UI or environment variable.

About

Chat-based SQL Client and Editor for the next decade

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.7%
  • Other 1.3%