About this project
# ChatGPT Prompt for SQL Writing
This utility generates prompts for writing SQL queries with LLMs like ChatGPT. Given a database URL and table name, it creates a copy-paste-ready prompt containing:
- **Table Structure Snapshot**: Columns, types, and organization of the table.
- **Sample Rows**: INSERT statements illustrating the data in the table.
- **Table and Field Comments**: Any comments on tables or columns are included.
## Usage
Install via pip:
```shell
pip install llm-sql-prompt
```
Basic usage:
```shell
Usage: llm-sql-prompt [OPTIONS] DATABASE_URL [TABLE_NAME]
Options:
--help Show this message and exit.
```
Generate a prompt from a Postgres database:
```shell
llm-sql-prompt postgresql://postgres:postgres@localhost:5555/database_name table_name | pbcopy
llm-sql-prompt $DATABASE_URL
```
From a local SQLite database:
```shell
llm-sql-prompt "$HOME/Library/Application Support/BeeperTexts/index.db" --all
```
## Local CLI Development
Run `just install_editable` to install the checkout globally in editable mode, so source changes are reflected without reinstalling. This requires `uv`, `just`, `zsh`, and `jq`. If mise is available, the recipe also updates every installed `pipx:llm-sql-prompt` environment so mise can use the local checkout. Re-run after mise upgrades, which replace those editable installations.
### Tunneling to a Remote Port
For working with a production database via SSH tunneling, the README provides shell functions (`find_random_open_port` and `ssh-tunnel`) to simplify the process.
## TODO
- [x] Postgres support
- [x] Single entrypoint
- [x] Use DB comments on columns and tables
- [x] Multiple tables
- [ ] Prompt tweaking
- [ ] Understand prompt size limits and sample records until one fits
Comments
0 people shared their preference · Deer Point appears after 10 participants
Sign in to join the discussion.