Skip to main content

A tool to extract SQL database schema and generate ChatGPT prompts

Project description

SQL2GPT

SQL2GPT is a Python-based tool that extracts the schema of a SQL database and generates a prompt for ChatGPT, a large language model by OpenAI. The goal of this project is to enable users to interact with ChatGPT to generate code or ask questions related to the given database schema.

Example

Table of Contents

Prerequisites

  • Python 3.11 or higher
  • MySQL client (for MySQL databases)
  • Pipenv: A Python dependency management tool

Installation

First, clone the repository:

git clone https://github.com/chand1012/sql2gpt.git
cd sql2gpt

Ensure that you have pipenv installed. If you don't have it installed, you can install it using pip:

pip install pipenv

Once you have pipenv installed, set up the environment and install the dependencies:

pipenv install

To activate the virtual environment, run:

pipenv shell

Usage

Adding a Database Connection

Add a new database connection by running:

python sql2gpt.py add <name> <database_uri>

Where <name> is the name you want to give to the connection, and <database_uri> is the URI for the database, such as:

  • PostgreSQL: postgresql://username:password@localhost/dbname
  • MySQL: mysql://username:password@localhost/dbname
  • SQLite: sqlite:///example.db

Printing the Schema

To print the schema of a database, run:

python sql2gpt.py print_schema <database_url or name>

Replace <database_url> with the appropriate database URL for your SQL database or the name of the connection you added previously.

Generating the ChatGPT Prompt

To generate the ChatGPT prompt for a given database, run:

python sql2gpt.py get_prompt <database_url or name>

Replace <database_url> with the appropriate database URL for your SQL database or the name of the connection you added previously. The generated prompt can be passed to ChatGPT to obtain code or ask questions about the database.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql2gpt-0.3.1.tar.gz (469.0 kB view details)

Uploaded Source

Built Distribution

sql2gpt-0.3.1-py3-none-any.whl (453.2 kB view details)

Uploaded Python 3

File details

Details for the file sql2gpt-0.3.1.tar.gz.

File metadata

  • Download URL: sql2gpt-0.3.1.tar.gz
  • Upload date:
  • Size: 469.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sql2gpt-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c4e4b36d8fe4c19eb10be1078bcd44a0f412a77b49e7932c4928a4b033e3daf5
MD5 6727b6c1121a87006cceffa3391926df
BLAKE2b-256 503e23bca3bb53cae3c4fc0e939a7676501c0491410a2d9a7d5acc457e25bea7

See more details on using hashes here.

File details

Details for the file sql2gpt-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: sql2gpt-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 453.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sql2gpt-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0627a86f7b3cc9101033e8d34269804bdeeb2f6a8f81fd368121e5a2245018a1
MD5 46e492caabdf3d20ce17368f0cccd8a7
BLAKE2b-256 932929e7ea01017d1ae07ea608e3705b30d5a1a66caa26f9e6a306d05a75c52f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page