introduction

SQL ChatIt is an innovative, conversational SQLclient 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 SQLstatement 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 ChatA framework is used Next.jsto 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 distributed NewSQLdatabase.

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”

SQLAI will automatically generate sentences for you based on your expression

Execute SQL

Execute SQLthe 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 promptand tokenthe length is given.

Install

OpenAIPrepare 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. Default https://api.openai.com.
  • NEXT_PUBLIC_ALLOW_SELF_OPENAI_KEY: Set to trueto 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_SECRETotherwise next-authan error will be reported.
  • If you connect to a database on the same server, you need to use as hostin the database connection configuration .host.docker.internalhost

Local installation

gitClone the project from it

Start Postgresthe 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 prismaClient

pnpm prisma generate

Copy the sample environment variable file;

cp .env.usedb .env

Add your API key and OpenAI APIto the newly created .envfile;

run

npm run dev

Summarize

To sum up, we learned SQL Chatthat the friendly natural language dialogue interface lowers the threshold for database operations and supports multiple databases and dockerdeployments.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *