introduction
SQL Chat
It is an innovative, conversational SQL
client tool.
It uses natural language processing technology to allow you to perform query, modification, creation and deletion operations on the database through daily conversations just like communicating with people.
It greatly simplifies the database management process and improves the intuitiveness and efficiency of data interaction.
Under this framework, users are no longer limited to traditional SQL
statement writing, but can express their needs using expressions close to human daily language, making database operations more approachable.
Even people with non-technical background can easily get started and achieve efficient data exploration and management.
SQL Chat
A framework is used Next.js
to create database interaction tools, which are currently compatible with and support a variety of mainstream database systems, including but not limited to:
MySQL
, relational database management system;PostgreSQL
, an open source object-relational database system;MSSQL
, an enterprise-level database platform provided by Microsoft;TiDB Cloud
, a cloud-based distributedNewSQL
database.
Attached is the github address: github.com/sqlchat/sql…
Features
Text to SQL
Enter “Top 10 employees with the highest salary for each department” in the dialog box
Translated into Chinese: “The top 10 highest paid employees in each department”
SQL
AI will automatically generate sentences for you based on your expression
Execute SQL
Execute SQL
the statement to get the query results of the top 10 employees in each department. The results are completely correct.
The prompt word generated by the current AI prompt
and token
the length is given.
Install
OpenAI
Prepare the secret key, etc. before installation
OPENAI_API_KEY
: OpenAI API, key. Can be obtained officially from openai.com.OPENAI_API_ENDPOINT
: OpenAI API endpoint. Defaulthttps://api.openai.com
.NEXT_PUBLIC_ALLOW_SELF_OPENAI_KEY
: Set totrue
to allow users of the SQL Chat service to use their own keys.
Docker installation
If it is for personal use, just provide the following two parameters when starting:
NEXTAUTH_SECRET
OPENAI_API_KEY
docker run --name sqlchat --platform linux/amd64 --env NEXTAUTH_SECRET="$(openssl rand -hex 5)" --env OPENAI_API_KEY=<<YOUR OPENAI KEY>> -p 3000:3000 --hostname localhost sqlchat/sqlchat
- Pass an arbitrary value to
NEXTAUTH_SECRET
otherwisenext-auth
an error will be reported. - If you connect to a database on the same server, you need to use as
host
in the database connection configuration .host.docker.internal
host
Local installation
git
Clone the project from it
Start Postgres
the instance. Create a database:
CREATE DATABASE sqlchat;
Set up databaseschema
pnpm prisma migrate dev
Initialization data (optional)
pnpm prisma db seed
Install and run the project using pnpm
:
Install dependencies
pnpm i
Generate prisma
Client
pnpm prisma generate
Copy the sample environment variable file;
cp .env.usedb .env
Add your API key and OpenAI API
to the newly created .env
file;
run
npm run dev
Summarize
To sum up, we learned SQL Chat
that the friendly natural language dialogue interface lowers the threshold for database operations and supports multiple databases and docker
deployments.
This interaction method is gradually changing the traditional model of our interaction with databases, ushering in an era of more intelligent and humane database operations.