{"id":17552576,"url":"https://github.com/iloveitaly/sql-ai-prompt-generator","last_synced_at":"2025-10-04T03:33:26.174Z","repository":{"id":193117013,"uuid":"688154569","full_name":"iloveitaly/sql-ai-prompt-generator","owner":"iloveitaly","description":"Utility to generate ChatGPT prompts for SQL writing, offering table structure snapshots and sample row data from Postgres and sqlite databases.","archived":false,"fork":false,"pushed_at":"2025-03-03T22:58:51.000Z","size":132,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T05:41:13.238Z","etag":null,"topics":["chatgpt","database","llms","postgres","prompt","sql","sqlite"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/llm-sql-prompt/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iloveitaly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["iloveitaly"]}},"created_at":"2023-09-06T19:02:52.000Z","updated_at":"2025-03-29T20:26:04.000Z","dependencies_parsed_at":"2023-09-06T21:55:58.127Z","dependency_job_id":"7d95db30-9ccd-4d0f-b441-dc9b2f339b16","html_url":"https://github.com/iloveitaly/sql-ai-prompt-generator","commit_stats":null,"previous_names":["iloveitaly/sql-ai-prompt-generator"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloveitaly%2Fsql-ai-prompt-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloveitaly%2Fsql-ai-prompt-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloveitaly%2Fsql-ai-prompt-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iloveitaly%2Fsql-ai-prompt-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iloveitaly","download_url":"https://codeload.github.com/iloveitaly/sql-ai-prompt-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250545550,"owners_count":21448228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","database","llms","postgres","prompt","sql","sqlite"],"created_at":"2024-10-21T05:43:14.791Z","updated_at":"2025-10-04T03:33:21.133Z","avatar_url":"https://github.com/iloveitaly.png","language":"Python","funding_links":["https://github.com/sponsors/iloveitaly"],"categories":[],"sub_categories":[],"readme":"# ChatGPT Prompt for SQL Writing\n\nGenerate a prompt for writing SQL queries with LLMs like ChatGPT. Drop your database URL and table name into the script and it will generate a prompt for you to copy and paste into your favorite LLM.\n\n## What this does\n\n- Snapshot of Table Structure: Understand the columns, types, and organization of your table at a glance.\n- Sample Rows: Includes INSERT statements to describe the data in your table.\n- Extracts Table and Field Comments: If you have comments on your tables or columns, they will be included in the prompt.\n\n## Usage\n\nInstall the package:\n\n```shell\npip install llm-sql-prompt\n```\n\nHere's how to use it:\n\n```shell\nUsage: llm-sql-prompt [OPTIONS] DATABASE_URL [TABLE_NAME]\n\nOptions:\n  --help  Show this message and exit.\n```\n\nGenerate a prompt from a postgres database:\n\n```shell\nllm-sql-prompt postgresql://postgres:postgres@localhost:5555/database_name table_name | pbcopy\nllm-sql-prompt $DATABASE_URL\n```\n\nFrom a local sqlite database:\n\n```shell\nllm-sql-prompt \"$HOME/Library/Application Support/BeeperTexts/index.db\" --all\n```\n\n### Tunneling to a remote port\n\nIf you find yourself wanting to tunnel into a remote box and work with a production database, here's some helpful commands so you don't need to remember the weird SSH tunneling syntax:\n\n```shell\nfunction find_random_open_port() {\n  local start_port=${1:-1024}\n  local max_attempts=100\n  local attempt=0\n  local port=$start_port\n\n  while (( attempt \u003c max_attempts )); do\n    if ! nc -z localhost $port 2\u003e/dev/null; then\n      echo $port\n      return\n    fi\n    port=$((port + 1))\n    attempt=$((attempt + 1))\n  done\n\n  echo \"No open port found after $max_attempts attempts, starting from $start_port.\" \u003e /dev/stderr\n  return 1\n}\n\n\nfunction ssh-tunnel() {\n  if [ $# -lt 2 ]; then\n    echo \"Usage: ssh-tunnel remote_host remote_port [local_port]\"\n    echo \"This function sets up SSH port forwarding.\"\n    return 1\n  fi\n\n  local remote_host=$1\n  local remote_port=$2\n  local local_port=${3:-$(find-random-open-port $remote_port)}\n\n  if [[ -z $local_port ]]; then\n    echo \"Failed to find an open local port.\"\n    return 1\n  fi\n\n  echo \"Forwarding local port $local_port to remote port $remote_port on $remote_host...\"\n  set -x\n  ssh $remote_host -L ${local_port}:localhost:${remote_port}\n}\n```\n\n## TODO\n\nSuper basic script, needs a lot of work\n\n- [x] pg support\n- [x] one entrypoint\n- [x] use DB comments on columns + tables\n- [x] multiple tables\n- [ ] prompt tweaking\n- [ ] understand prompt size limits and sample records until one fits","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filoveitaly%2Fsql-ai-prompt-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filoveitaly%2Fsql-ai-prompt-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filoveitaly%2Fsql-ai-prompt-generator/lists"}