├── .gitignore ├── .gptignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── Pipfile ├── Pipfile.lock ├── README.md ├── config.py ├── pyproject.toml ├── sql2gpt.py ├── tapes ├── demo.gif └── demo.tape └── util.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/** 2 | env 3 | sql2gpt.egg-info 4 | dist 5 | -------------------------------------------------------------------------------- /.gptignore: -------------------------------------------------------------------------------- 1 | Pipfile.lock 2 | .vscode/** 3 | .gitignore 4 | .gptignore 5 | LICENSE 6 | tapes/** 7 | env/** 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.tabSize": 4 3 | } 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | chandler@chand1012.dev. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2023 Chandler Lofland 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the “Software”), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | sqlalchemy = "*" 8 | psycopg2-binary = "*" 9 | mysqlclient = "*" 10 | fire = "*" 11 | 12 | [dev-packages] 13 | autopep8 = "*" 14 | setuptools = "*" 15 | setuptools-scm = "*" 16 | wheel = "*" 17 | build = "*" 18 | twine = "*" 19 | 20 | [requires] 21 | python_version = "3.11" 22 | 23 | [scripts] 24 | build = "python -m build" 25 | clean = "rm -rf dist sql2gpt.egg-info" 26 | upload = "twine upload dist/*" 27 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "fba565af46f9f53c26bd2e064b8accef1f77b710029efd52ca0bfb3fb8808480" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "3.11" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "fire": { 20 | "hashes": [ 21 | "sha256:a6b0d49e98c8963910021f92bba66f65ab440da2982b78eb1bbf95a0a34aacc6" 22 | ], 23 | "index": "pypi", 24 | "version": "==0.5.0" 25 | }, 26 | "mysqlclient": { 27 | "hashes": [ 28 | "sha256:0d1cd3a5a4d28c222fa199002810e8146cffd821410b67851af4cc80aeccd97c", 29 | "sha256:828757e419fb11dd6c5ed2576ec92c3efaa93a0f7c39e263586d1ee779c3d782", 30 | "sha256:996924f3483fd36a34a5812210c69e71dea5a3d5978d01199b78b7f6d485c855", 31 | "sha256:b355c8b5a7d58f2e909acdbb050858390ee1b0e13672ae759e5e784110022994", 32 | "sha256:c1ed71bd6244993b526113cca3df66428609f90e4652f37eb51c33496d478b37", 33 | "sha256:c812b67e90082a840efb82a8978369e6e69fc62ce1bda4ca8f3084a9d862308b", 34 | "sha256:dea88c8d3f5a5d9293dfe7f087c16dd350ceb175f2f6631c9cf4caf3e19b7a96" 35 | ], 36 | "index": "pypi", 37 | "version": "==2.1.1" 38 | }, 39 | "psycopg2-binary": { 40 | "hashes": [ 41 | "sha256:02c0f3757a4300cf379eb49f543fb7ac527fb00144d39246ee40e1df684ab514", 42 | "sha256:02c6e3cf3439e213e4ee930308dc122d6fb4d4bea9aef4a12535fbd605d1a2fe", 43 | "sha256:0645376d399bfd64da57148694d78e1f431b1e1ee1054872a5713125681cf1be", 44 | "sha256:0892ef645c2fabb0c75ec32d79f4252542d0caec1d5d949630e7d242ca4681a3", 45 | "sha256:0d236c2825fa656a2d98bbb0e52370a2e852e5a0ec45fc4f402977313329174d", 46 | "sha256:0e0f754d27fddcfd74006455b6e04e6705d6c31a612ec69ddc040a5468e44b4e", 47 | "sha256:15e2ee79e7cf29582ef770de7dab3d286431b01c3bb598f8e05e09601b890081", 48 | "sha256:1876843d8e31c89c399e31b97d4b9725a3575bb9c2af92038464231ec40f9edb", 49 | "sha256:1f64dcfb8f6e0c014c7f55e51c9759f024f70ea572fbdef123f85318c297947c", 50 | "sha256:2ab652e729ff4ad76d400df2624d223d6e265ef81bb8aa17fbd63607878ecbee", 51 | "sha256:30637a20623e2a2eacc420059be11527f4458ef54352d870b8181a4c3020ae6b", 52 | "sha256:34b9ccdf210cbbb1303c7c4db2905fa0319391bd5904d32689e6dd5c963d2ea8", 53 | "sha256:38601cbbfe600362c43714482f43b7c110b20cb0f8172422c616b09b85a750c5", 54 | "sha256:441cc2f8869a4f0f4bb408475e5ae0ee1f3b55b33f350406150277f7f35384fc", 55 | "sha256:498807b927ca2510baea1b05cc91d7da4718a0f53cb766c154c417a39f1820a0", 56 | "sha256:4ac30da8b4f57187dbf449294d23b808f8f53cad6b1fc3623fa8a6c11d176dd0", 57 | "sha256:4c727b597c6444a16e9119386b59388f8a424223302d0c06c676ec8b4bc1f963", 58 | "sha256:4d67fbdaf177da06374473ef6f7ed8cc0a9dc640b01abfe9e8a2ccb1b1402c1f", 59 | "sha256:4dfb4be774c4436a4526d0c554af0cc2e02082c38303852a36f6456ece7b3503", 60 | "sha256:4ea29fc3ad9d91162c52b578f211ff1c931d8a38e1f58e684c45aa470adf19e2", 61 | "sha256:51537e3d299be0db9137b321dfb6a5022caaab275775680e0c3d281feefaca6b", 62 | "sha256:61b047a0537bbc3afae10f134dc6393823882eb263088c271331602b672e52e9", 63 | "sha256:6460c7a99fc939b849431f1e73e013d54aa54293f30f1109019c56a0b2b2ec2f", 64 | "sha256:65bee1e49fa6f9cf327ce0e01c4c10f39165ee76d35c846ade7cb0ec6683e303", 65 | "sha256:65c07febd1936d63bfde78948b76cd4c2a411572a44ac50719ead41947d0f26b", 66 | "sha256:71f14375d6f73b62800530b581aed3ada394039877818b2d5f7fc77e3bb6894d", 67 | "sha256:7a40c00dbe17c0af5bdd55aafd6ff6679f94a9be9513a4c7e071baf3d7d22a70", 68 | "sha256:7e13a5a2c01151f1208d5207e42f33ba86d561b7a89fca67c700b9486a06d0e2", 69 | "sha256:7f0438fa20fb6c7e202863e0d5ab02c246d35efb1d164e052f2f3bfe2b152bd0", 70 | "sha256:8122cfc7cae0da9a3077216528b8bb3629c43b25053284cc868744bfe71eb141", 71 | "sha256:8338a271cb71d8da40b023a35d9c1e919eba6cbd8fa20a54b748a332c355d896", 72 | "sha256:84d2222e61f313c4848ff05353653bf5f5cf6ce34df540e4274516880d9c3763", 73 | "sha256:8a6979cf527e2603d349a91060f428bcb135aea2be3201dff794813256c274f1", 74 | "sha256:8a76e027f87753f9bd1ab5f7c9cb8c7628d1077ef927f5e2446477153a602f2c", 75 | "sha256:964b4dfb7c1c1965ac4c1978b0f755cc4bd698e8aa2b7667c575fb5f04ebe06b", 76 | "sha256:9972aad21f965599ed0106f65334230ce826e5ae69fda7cbd688d24fa922415e", 77 | "sha256:a8c28fd40a4226b4a84bdf2d2b5b37d2c7bd49486b5adcc200e8c7ec991dfa7e", 78 | "sha256:ae102a98c547ee2288637af07393dd33f440c25e5cd79556b04e3fca13325e5f", 79 | "sha256:af335bac6b666cc6aea16f11d486c3b794029d9df029967f9938a4bed59b6a19", 80 | "sha256:afe64e9b8ea66866a771996f6ff14447e8082ea26e675a295ad3bdbffdd72afb", 81 | "sha256:b4b24f75d16a89cc6b4cdff0eb6a910a966ecd476d1e73f7ce5985ff1328e9a6", 82 | "sha256:b6c8288bb8a84b47e07013bb4850f50538aa913d487579e1921724631d02ea1b", 83 | "sha256:b83456c2d4979e08ff56180a76429263ea254c3f6552cd14ada95cff1dec9bb8", 84 | "sha256:bfb13af3c5dd3a9588000910178de17010ebcccd37b4f9794b00595e3a8ddad3", 85 | "sha256:c3dba7dab16709a33a847e5cd756767271697041fbe3fe97c215b1fc1f5c9848", 86 | "sha256:c48d8f2db17f27d41fb0e2ecd703ea41984ee19362cbce52c097963b3a1b4365", 87 | "sha256:c7e62ab8b332147a7593a385d4f368874d5fe4ad4e341770d4983442d89603e3", 88 | "sha256:c83a74b68270028dc8ee74d38ecfaf9c90eed23c8959fca95bd703d25b82c88e", 89 | "sha256:cacbdc5839bdff804dfebc058fe25684cae322987f7a38b0168bc1b2df703fb1", 90 | "sha256:cf4499e0a83b7b7edcb8dabecbd8501d0d3a5ef66457200f77bde3d210d5debb", 91 | "sha256:cfec476887aa231b8548ece2e06d28edc87c1397ebd83922299af2e051cf2827", 92 | "sha256:d26e0342183c762de3276cca7a530d574d4e25121ca7d6e4a98e4f05cb8e4df7", 93 | "sha256:d4e6036decf4b72d6425d5b29bbd3e8f0ff1059cda7ac7b96d6ac5ed34ffbacd", 94 | "sha256:d57c3fd55d9058645d26ae37d76e61156a27722097229d32a9e73ed54819982a", 95 | "sha256:dfa74c903a3c1f0d9b1c7e7b53ed2d929a4910e272add6700c38f365a6002820", 96 | "sha256:e3ed340d2b858d6e6fb5083f87c09996506af483227735de6964a6100b4e6a54", 97 | "sha256:e78e6e2a00c223e164c417628572a90093c031ed724492c763721c2e0bc2a8df", 98 | "sha256:e9182eb20f41417ea1dd8e8f7888c4d7c6e805f8a7c98c1081778a3da2bee3e4", 99 | "sha256:e99e34c82309dd78959ba3c1590975b5d3c862d6f279f843d47d26ff89d7d7e1", 100 | "sha256:f6a88f384335bb27812293fdb11ac6aee2ca3f51d3c7820fe03de0a304ab6249", 101 | "sha256:f81e65376e52f03422e1fb475c9514185669943798ed019ac50410fb4c4df232", 102 | "sha256:ffe9dc0a884a8848075e576c1de0290d85a533a9f6e9c4e564f19adf8f6e54a7" 103 | ], 104 | "index": "pypi", 105 | "version": "==2.9.6" 106 | }, 107 | "six": { 108 | "hashes": [ 109 | "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", 110 | "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" 111 | ], 112 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", 113 | "version": "==1.16.0" 114 | }, 115 | "sqlalchemy": { 116 | "hashes": [ 117 | "sha256:07950fc82f844a2de67ddb4e535f29b65652b4d95e8b847823ce66a6d540a41d", 118 | "sha256:0a865b5ec4ba24f57c33b633b728e43fde77b968911a6046443f581b25d29dd9", 119 | "sha256:0b49f1f71d7a44329a43d3edd38cc5ee4c058dfef4487498393d16172007954b", 120 | "sha256:13f984a190d249769a050634b248aef8991acc035e849d02b634ea006c028fa8", 121 | "sha256:1b69666e25cc03c602d9d3d460e1281810109e6546739187044fc256c67941ef", 122 | "sha256:1d06e119cf79a3d80ab069f064a07152eb9ba541d084bdaee728d8a6f03fd03d", 123 | "sha256:246712af9fc761d6c13f4f065470982e175d902e77aa4218c9cb9fc9ff565a0c", 124 | "sha256:34eb96c1de91d8f31e988302243357bef3f7785e1b728c7d4b98bd0c117dafeb", 125 | "sha256:4c3020afb144572c7bfcba9d7cce57ad42bff6e6115dffcfe2d4ae6d444a214f", 126 | "sha256:4f759eccb66e6d495fb622eb7f4ac146ae674d829942ec18b7f5a35ddf029597", 127 | "sha256:68ed381bc340b4a3d373dbfec1a8b971f6350139590c4ca3cb722fdb50035777", 128 | "sha256:6b72dccc5864ea95c93e0a9c4e397708917fb450f96737b4a8395d009f90b868", 129 | "sha256:6e84ab63d25d8564d7a8c05dc080659931a459ee27f6ed1cf4c91f292d184038", 130 | "sha256:734805708632e3965c2c40081f9a59263c29ffa27cba9b02d4d92dfd57ba869f", 131 | "sha256:78612edf4ba50d407d0eb3a64e9ec76e6efc2b5d9a5c63415d53e540266a230a", 132 | "sha256:7e472e9627882f2d75b87ff91c5a2bc45b31a226efc7cc0a054a94fffef85862", 133 | "sha256:865392a50a721445156809c1a6d6ab6437be70c1c2599f591a8849ed95d3c693", 134 | "sha256:8d118e233f416d713aac715e2c1101e17f91e696ff315fc9efbc75b70d11e740", 135 | "sha256:8d3ece5960b3e821e43a4927cc851b6e84a431976d3ffe02aadb96519044807e", 136 | "sha256:93c78d42c14aa9a9e0866eacd5b48df40a50d0e2790ee377af7910d224afddcf", 137 | "sha256:95719215e3ec7337b9f57c3c2eda0e6a7619be194a5166c07c1e599f6afc20fa", 138 | "sha256:9838bd247ee42eb74193d865e48dd62eb50e45e3fdceb0fdef3351133ee53dcf", 139 | "sha256:aa5c270ece17c0c0e0a38f2530c16b20ea05d8b794e46c79171a86b93b758891", 140 | "sha256:ac6a0311fb21a99855953f84c43fcff4bdca27a2ffcc4f4d806b26b54b5cddc9", 141 | "sha256:ad5363a1c65fde7b7466769d4261126d07d872fc2e816487ae6cec93da604b6b", 142 | "sha256:b3e5864eba71a3718236a120547e52c8da2ccb57cc96cecd0480106a0c799c92", 143 | "sha256:bbda1da8d541904ba262825a833c9f619e93cb3fd1156be0a5e43cd54d588dcd", 144 | "sha256:c6e27189ff9aebfb2c02fd252c629ea58657e7a5ff1a321b7fc9c2bf6dc0b5f3", 145 | "sha256:c8239ce63a90007bce479adf5460d48c1adae4b933d8e39a4eafecfc084e503c", 146 | "sha256:d209594e68bec103ad5243ecac1b40bf5770c9ebf482df7abf175748a34f4853", 147 | "sha256:d5327f54a9c39e7871fc532639616f3777304364a0bb9b89d6033ad34ef6c5f8", 148 | "sha256:db4bd1c4792da753f914ff0b688086b9a8fd78bb9bc5ae8b6d2e65f176b81eb9", 149 | "sha256:e4780be0f19e5894c17f75fc8de2fe1ae233ab37827125239ceb593c6f6bd1e2", 150 | "sha256:e4a019f723b6c1e6b3781be00fb9e0844bc6156f9951c836ff60787cc3938d76", 151 | "sha256:e62c4e762d6fd2901692a093f208a6a6575b930e9458ad58c2a7f080dd6132da", 152 | "sha256:e730603cae5747bc6d6dece98b45a57d647ed553c8d5ecef602697b1c1501cf2", 153 | "sha256:ebc4eeb1737a5a9bdb0c24f4c982319fa6edd23cdee27180978c29cbb026f2bd", 154 | "sha256:ee2946042cc7851842d7a086a92b9b7b494cbe8c3e7e4627e27bc912d3a7655e", 155 | "sha256:f005245e1cb9b8ca53df73ee85e029ac43155e062405015e49ec6187a2e3fb44", 156 | "sha256:f49c5d3c070a72ecb96df703966c9678dda0d4cb2e2736f88d15f5e1203b4159", 157 | "sha256:f61ab84956dc628c8dfe9d105b6aec38afb96adae3e5e7da6085b583ff6ea789" 158 | ], 159 | "index": "pypi", 160 | "version": "==2.0.9" 161 | }, 162 | "termcolor": { 163 | "hashes": [ 164 | "sha256:91ddd848e7251200eac969846cbae2dacd7d71c2871e92733289e7e3666f48e7", 165 | "sha256:dfc8ac3f350788f23b2947b3e6cfa5a53b630b612e6cd8965a015a776020b99a" 166 | ], 167 | "markers": "python_version >= '3.7'", 168 | "version": "==2.2.0" 169 | }, 170 | "typing-extensions": { 171 | "hashes": [ 172 | "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb", 173 | "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4" 174 | ], 175 | "markers": "python_version >= '3.7'", 176 | "version": "==4.5.0" 177 | } 178 | }, 179 | "develop": { 180 | "autopep8": { 181 | "hashes": [ 182 | "sha256:86e9303b5e5c8160872b2f5ef611161b2893e9bfe8ccc7e2f76385947d57a2f1", 183 | "sha256:f9849cdd62108cb739dbcdbfb7fdcc9a30d1b63c4cc3e1c1f893b5360941b61c" 184 | ], 185 | "index": "pypi", 186 | "version": "==2.0.2" 187 | }, 188 | "bleach": { 189 | "hashes": [ 190 | "sha256:1a1a85c1595e07d8db14c5f09f09e6433502c51c595970edc090551f0db99414", 191 | "sha256:33c16e3353dbd13028ab4799a0f89a83f113405c766e9c122df8a06f5b85b3f4" 192 | ], 193 | "markers": "python_version >= '3.7'", 194 | "version": "==6.0.0" 195 | }, 196 | "build": { 197 | "hashes": [ 198 | "sha256:af266720050a66c893a6096a2f410989eeac74ff9a68ba194b3f6473e8e26171", 199 | "sha256:d5b71264afdb5951d6704482aac78de887c80691c52b88a9ad195983ca2c9269" 200 | ], 201 | "index": "pypi", 202 | "version": "==0.10.0" 203 | }, 204 | "certifi": { 205 | "hashes": [ 206 | "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3", 207 | "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18" 208 | ], 209 | "markers": "python_version >= '3.6'", 210 | "version": "==2022.12.7" 211 | }, 212 | "charset-normalizer": { 213 | "hashes": [ 214 | "sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6", 215 | "sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1", 216 | "sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e", 217 | "sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373", 218 | "sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62", 219 | "sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230", 220 | "sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be", 221 | "sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c", 222 | "sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0", 223 | "sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448", 224 | "sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f", 225 | "sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649", 226 | "sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d", 227 | "sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0", 228 | "sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706", 229 | "sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a", 230 | "sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59", 231 | "sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23", 232 | "sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5", 233 | "sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb", 234 | "sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e", 235 | "sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e", 236 | "sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c", 237 | "sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28", 238 | "sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d", 239 | "sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41", 240 | "sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974", 241 | "sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce", 242 | "sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f", 243 | "sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1", 244 | "sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d", 245 | "sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8", 246 | "sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017", 247 | "sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31", 248 | "sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7", 249 | "sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8", 250 | "sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e", 251 | "sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14", 252 | "sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd", 253 | "sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d", 254 | "sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795", 255 | "sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b", 256 | "sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b", 257 | "sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b", 258 | "sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203", 259 | "sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f", 260 | "sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19", 261 | "sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1", 262 | "sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a", 263 | "sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac", 264 | "sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9", 265 | "sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0", 266 | "sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137", 267 | "sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f", 268 | "sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6", 269 | "sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5", 270 | "sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909", 271 | "sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f", 272 | "sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0", 273 | "sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324", 274 | "sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755", 275 | "sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb", 276 | "sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854", 277 | "sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c", 278 | "sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60", 279 | "sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84", 280 | "sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0", 281 | "sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b", 282 | "sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1", 283 | "sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531", 284 | "sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1", 285 | "sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11", 286 | "sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326", 287 | "sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df", 288 | "sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab" 289 | ], 290 | "markers": "python_version >= '3.7'", 291 | "version": "==3.1.0" 292 | }, 293 | "docutils": { 294 | "hashes": [ 295 | "sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6", 296 | "sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc" 297 | ], 298 | "markers": "python_version >= '3.7'", 299 | "version": "==0.19" 300 | }, 301 | "idna": { 302 | "hashes": [ 303 | "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4", 304 | "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" 305 | ], 306 | "markers": "python_version >= '3.5'", 307 | "version": "==3.4" 308 | }, 309 | "importlib-metadata": { 310 | "hashes": [ 311 | "sha256:63ace321e24167d12fbb176b6015f4dbe06868c54a2af4f15849586afb9027fd", 312 | "sha256:eb1a7933041f0f85c94cd130258df3fb0dec060ad8c1c9318892ef4192c47ce1" 313 | ], 314 | "markers": "python_version >= '3.7'", 315 | "version": "==6.4.1" 316 | }, 317 | "jaraco.classes": { 318 | "hashes": [ 319 | "sha256:2353de3288bc6b82120752201c6b1c1a14b058267fa424ed5ce5984e3b922158", 320 | "sha256:89559fa5c1d3c34eff6f631ad80bb21f378dbcbb35dd161fd2c6b93f5be2f98a" 321 | ], 322 | "markers": "python_version >= '3.7'", 323 | "version": "==3.2.3" 324 | }, 325 | "keyring": { 326 | "hashes": [ 327 | "sha256:771ed2a91909389ed6148631de678f82ddc73737d85a927f382a8a1b157898cd", 328 | "sha256:ba2e15a9b35e21908d0aaf4e0a47acc52d6ae33444df0da2b49d41a46ef6d678" 329 | ], 330 | "markers": "python_version >= '3.7'", 331 | "version": "==23.13.1" 332 | }, 333 | "markdown-it-py": { 334 | "hashes": [ 335 | "sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30", 336 | "sha256:7c9a5e412688bc771c67432cbfebcdd686c93ce6484913dccf06cb5a0bea35a1" 337 | ], 338 | "markers": "python_version >= '3.7'", 339 | "version": "==2.2.0" 340 | }, 341 | "mdurl": { 342 | "hashes": [ 343 | "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", 344 | "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" 345 | ], 346 | "markers": "python_version >= '3.7'", 347 | "version": "==0.1.2" 348 | }, 349 | "more-itertools": { 350 | "hashes": [ 351 | "sha256:cabaa341ad0389ea83c17a94566a53ae4c9d07349861ecb14dc6d0345cf9ac5d", 352 | "sha256:d2bc7f02446e86a68911e58ded76d6561eea00cddfb2a91e7019bbb586c799f3" 353 | ], 354 | "markers": "python_version >= '3.7'", 355 | "version": "==9.1.0" 356 | }, 357 | "packaging": { 358 | "hashes": [ 359 | "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61", 360 | "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f" 361 | ], 362 | "markers": "python_version >= '3.7'", 363 | "version": "==23.1" 364 | }, 365 | "pkginfo": { 366 | "hashes": [ 367 | "sha256:4b7a555a6d5a22169fcc9cf7bfd78d296b0361adad412a346c1226849af5e546", 368 | "sha256:8fd5896e8718a4372f0ea9cc9d96f6417c9b986e23a4d116dda26b62cc29d046" 369 | ], 370 | "markers": "python_version >= '3.6'", 371 | "version": "==1.9.6" 372 | }, 373 | "pycodestyle": { 374 | "hashes": [ 375 | "sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053", 376 | "sha256:8a4eaf0d0495c7395bdab3589ac2db602797d76207242c17d470186815706610" 377 | ], 378 | "markers": "python_version >= '3.6'", 379 | "version": "==2.10.0" 380 | }, 381 | "pygments": { 382 | "hashes": [ 383 | "sha256:77a3299119af881904cd5ecd1ac6a66214b6e9bed1f2db16993b54adede64094", 384 | "sha256:f7e36cffc4c517fbc252861b9a6e4644ca0e5abadf9a113c72d1358ad09b9500" 385 | ], 386 | "markers": "python_version >= '3.7'", 387 | "version": "==2.15.0" 388 | }, 389 | "pyproject-hooks": { 390 | "hashes": [ 391 | "sha256:283c11acd6b928d2f6a7c73fa0d01cb2bdc5f07c57a2eeb6e83d5e56b97976f8", 392 | "sha256:f271b298b97f5955d53fb12b72c1fb1948c22c1a6b70b315c54cedaca0264ef5" 393 | ], 394 | "markers": "python_version >= '3.7'", 395 | "version": "==1.0.0" 396 | }, 397 | "readme-renderer": { 398 | "hashes": [ 399 | "sha256:cd653186dfc73055656f090f227f5cb22a046d7f71a841dfa305f55c9a513273", 400 | "sha256:f67a16caedfa71eef48a31b39708637a6f4664c4394801a7b0d6432d13907343" 401 | ], 402 | "markers": "python_version >= '3.7'", 403 | "version": "==37.3" 404 | }, 405 | "requests": { 406 | "hashes": [ 407 | "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa", 408 | "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf" 409 | ], 410 | "markers": "python_version >= '3.7' and python_version < '4'", 411 | "version": "==2.28.2" 412 | }, 413 | "requests-toolbelt": { 414 | "hashes": [ 415 | "sha256:18565aa58116d9951ac39baa288d3adb5b3ff975c4f25eee78555d89e8f247f7", 416 | "sha256:62e09f7ff5ccbda92772a29f394a49c3ad6cb181d568b1337626b2abb628a63d" 417 | ], 418 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", 419 | "version": "==0.10.1" 420 | }, 421 | "rfc3986": { 422 | "hashes": [ 423 | "sha256:50b1502b60e289cb37883f3dfd34532b8873c7de9f49bb546641ce9cbd256ebd", 424 | "sha256:97aacf9dbd4bfd829baad6e6309fa6573aaf1be3f6fa735c8ab05e46cecb261c" 425 | ], 426 | "markers": "python_version >= '3.7'", 427 | "version": "==2.0.0" 428 | }, 429 | "rich": { 430 | "hashes": [ 431 | "sha256:22b74cae0278fd5086ff44144d3813be1cedc9115bdfabbfefd86400cb88b20a", 432 | "sha256:b5d573e13605423ec80bdd0cd5f8541f7844a0e71a13f74cf454ccb2f490708b" 433 | ], 434 | "markers": "python_version >= '3.7'", 435 | "version": "==13.3.4" 436 | }, 437 | "setuptools": { 438 | "hashes": [ 439 | "sha256:257de92a9d50a60b8e22abfcbb771571fde0dbf3ec234463212027a4eeecbe9a", 440 | "sha256:e728ca814a823bf7bf60162daf9db95b93d532948c4c0bea762ce62f60189078" 441 | ], 442 | "index": "pypi", 443 | "version": "==67.6.1" 444 | }, 445 | "setuptools-scm": { 446 | "hashes": [ 447 | "sha256:6c508345a771aad7d56ebff0e70628bf2b0ec7573762be9960214730de278f27", 448 | "sha256:73988b6d848709e2af142aa48c986ea29592bbcfca5375678064708205253d8e" 449 | ], 450 | "index": "pypi", 451 | "version": "==7.1.0" 452 | }, 453 | "six": { 454 | "hashes": [ 455 | "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", 456 | "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" 457 | ], 458 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", 459 | "version": "==1.16.0" 460 | }, 461 | "twine": { 462 | "hashes": [ 463 | "sha256:929bc3c280033347a00f847236564d1c52a3e61b1ac2516c97c48f3ceab756d8", 464 | "sha256:9e102ef5fdd5a20661eb88fad46338806c3bd32cf1db729603fe3697b1bc83c8" 465 | ], 466 | "index": "pypi", 467 | "version": "==4.0.2" 468 | }, 469 | "typing-extensions": { 470 | "hashes": [ 471 | "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb", 472 | "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4" 473 | ], 474 | "markers": "python_version >= '3.7'", 475 | "version": "==4.5.0" 476 | }, 477 | "urllib3": { 478 | "hashes": [ 479 | "sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305", 480 | "sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42" 481 | ], 482 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", 483 | "version": "==1.26.15" 484 | }, 485 | "webencodings": { 486 | "hashes": [ 487 | "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", 488 | "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" 489 | ], 490 | "version": "==0.5.1" 491 | }, 492 | "wheel": { 493 | "hashes": [ 494 | "sha256:cd1196f3faee2b31968d626e1731c94f99cbdb67cf5a46e4f5656cbee7738873", 495 | "sha256:d236b20e7cb522daf2390fa84c55eea81c5c30190f90f29ae2ca1ad8355bf247" 496 | ], 497 | "index": "pypi", 498 | "version": "==0.40.0" 499 | }, 500 | "zipp": { 501 | "hashes": [ 502 | "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b", 503 | "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556" 504 | ], 505 | "markers": "python_version >= '3.7'", 506 | "version": "==3.15.0" 507 | } 508 | } 509 | } 510 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQL2GPT 2 | 3 | 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. 4 | 5 | ![Example](tapes/demo.gif) 6 | 7 | ## Table of Contents 8 | 9 | * [Prerequisites](#prerequisites) 10 | * [Installation](#installation) 11 | * [Usage](#usage) 12 | + [Adding a Database Connection](#adding-a-database-connection) 13 | + [Printing the Schema](#printing-the-schema) 14 | + [Generating the ChatGPT Prompt](#generating-the-chatgpt-prompt) 15 | * [License](#license) 16 | 17 | ## Prerequisites 18 | 19 | * Python 3.11 or higher 20 | * MySQL client (for MySQL databases) 21 | * Pipenv: A Python dependency management tool 22 | 23 | ## Installation 24 | 25 | First, clone the repository: 26 | 27 | ```bash 28 | git clone https://github.com/chand1012/sql2gpt.git 29 | cd sql2gpt 30 | ``` 31 | 32 | Ensure that you have pipenv installed. If you don't have it installed, you can install it using pip: 33 | 34 | ```bash 35 | pip install pipenv 36 | ``` 37 | 38 | Once you have pipenv installed, set up the environment and install the dependencies: 39 | 40 | ```bash 41 | pipenv install 42 | ``` 43 | 44 | To activate the virtual environment, run: 45 | 46 | ```bash 47 | pipenv shell 48 | ``` 49 | 50 | ## Usage 51 | 52 | ### Adding a Database Connection 53 | 54 | Add a new database connection by running: 55 | 56 | ```bash 57 | python sql2gpt.py add 58 | ``` 59 | 60 | Where `` is the name you want to give to the connection, and `` is the URI for the database, such as: 61 | 62 | * PostgreSQL: `postgresql://username:password@localhost/dbname` 63 | * MySQL: `mysql://username:password@localhost/dbname` 64 | * SQLite: `sqlite:///example.db` 65 | 66 | ### Printing the Schema 67 | 68 | To print the schema of a database, run: 69 | 70 | ```bash 71 | python sql2gpt.py print_schema 72 | ``` 73 | 74 | Replace with the appropriate database URL for your SQL database or the name of the connection you added previously. 75 | 76 | ### Generating the ChatGPT Prompt 77 | 78 | To generate the ChatGPT prompt for a given database, run: 79 | 80 | ```bash 81 | python sql2gpt.py get_prompt 82 | ``` 83 | 84 | Replace 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. 85 | 86 | ## License 87 | 88 | This project is licensed under the MIT License. 89 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | CONFIG_DIR = ".sql2gpt" 5 | 6 | 7 | def load(config_dir=CONFIG_DIR) -> dict: 8 | # Define config directory and file paths 9 | config_dir = os.path.join(os.path.expanduser("~"), config_dir) 10 | dbs_file = os.path.join(config_dir, "dbs.json") 11 | 12 | # Create config directory if it doesn't exist 13 | if not os.path.exists(config_dir): 14 | os.makedirs(config_dir) 15 | 16 | # Create dbs.json file with an empty JSON object if it doesn't exist 17 | if not os.path.exists(dbs_file): 18 | with open(dbs_file, "w") as file: 19 | json.dump({}, file) 20 | 21 | # Load and return the config as a dictionary 22 | with open(dbs_file, "r") as file: 23 | config = json.load(file) 24 | 25 | return config 26 | 27 | 28 | def add(name: str, database_url: str, config_dir=CONFIG_DIR) -> None: 29 | config = load(config_dir) 30 | config[name] = database_url 31 | # save the config 32 | config_dir = os.path.join(os.path.expanduser("~"), config_dir) 33 | dbs_file = os.path.join(config_dir, "dbs.json") 34 | with open(dbs_file, "w") as file: 35 | json.dump(config, file) 36 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools", "setuptools-scm"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "sql2gpt" 7 | authors = [{ name = "Your Name", email = "your.email@example.com" }] 8 | description = "A tool to extract SQL database schema and generate ChatGPT prompts" 9 | readme = "README.md" 10 | requires-python = ">=3.10" 11 | keywords = ["sql", "chatgpt", "database", "schema"] 12 | license = { text = "MIT" } 13 | classifiers = [ 14 | "Development Status :: 3 - Alpha", 15 | "License :: OSI Approved :: MIT License", 16 | "Programming Language :: Python :: 3", 17 | "Programming Language :: Python :: 3.10", 18 | ] 19 | dependencies = ["sqlalchemy", "psycopg2-binary", "mysqlclient", "fire"] 20 | version = "0.3.1" 21 | 22 | [project.urls] 23 | Source = "https://github.com/chand1012/sql2gpt" 24 | 25 | [project.scripts] 26 | sql2gpt = "sql2gpt:main" 27 | -------------------------------------------------------------------------------- /sql2gpt.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | import fire 4 | from sqlalchemy import create_engine, MetaData, Table, inspect 5 | 6 | import config 7 | from util import get_db_type, is_uri 8 | 9 | 10 | def get_schemas(database_url): 11 | print("Connecting to database...") 12 | engine = create_engine(database_url) 13 | meta = MetaData() 14 | 15 | print("Inspecting database...") 16 | inspector = inspect(engine) 17 | schemas = [] 18 | for table_name in inspector.get_table_names(): 19 | table = Table(table_name, meta, autoload_with=engine) 20 | schema_string = f"{table_name}(" 21 | columns = [] 22 | for column in table.columns: 23 | columns.append(f"{column.name} {column.type}") 24 | schema_string += ", ".join(columns) + ")" 25 | schemas.append(schema_string) 26 | 27 | print("Done") 28 | print('-'*72) 29 | return schemas 30 | 31 | 32 | class SQL2GPT: 33 | def __init__(self): 34 | self.config = config.load() 35 | self.prompt = "I have a {} SQL database. I am going to give you the schema in the following format: table_name(column_name column_type, column_name column_type, ...), followed by END. After END, you will be given instructions on how to use the schema information. Here is the schema:\n\n{}\nEND" 36 | 37 | def get_uri(self, i) -> Union[str, None]: 38 | database_url = i 39 | if not is_uri(database_url): 40 | database_url = self.config.get(database_url, None) 41 | if not database_url: 42 | print( 43 | "Database not found in URL. Add with `sql2gpt add `.") 44 | return None 45 | return database_url 46 | 47 | def print_schema(self, database_url): 48 | database_url = self.get_uri(database_url) 49 | schemas = get_schemas(database_url) 50 | print("\n".join(schemas)) 51 | 52 | def get_prompt(self, database_url): 53 | database_url = self.get_uri(database_url) 54 | db_type = get_db_type(database_url) 55 | schemas = get_schemas(database_url) 56 | print(self.prompt.format(db_type, "\n".join(schemas))) 57 | 58 | def add(self, name: str, database_uri: str): 59 | config.add(name, database_uri) 60 | print("Database added successfully.") 61 | 62 | 63 | def main(): 64 | fire.Fire(SQL2GPT) 65 | 66 | 67 | if __name__ == "__main__": 68 | main() 69 | -------------------------------------------------------------------------------- /tapes/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chand1012/sql2gpt/a8090eb07ccd61f3f32487e52a10add729ceac5f/tapes/demo.gif -------------------------------------------------------------------------------- /tapes/demo.tape: -------------------------------------------------------------------------------- 1 | Output tapes/demo.gif 2 | 3 | Set Shell "zsh" 4 | Set FontSize 32 5 | Set Width 1600 6 | Set Height 900 7 | 8 | Type "python sql2gpt.py add arail sqlite:///$HOME/.arail/arail.db" Sleep 500ms Enter 9 | Sleep 1s 10 | Type "python sql2gpt.py print_schema arail" Sleep 500ms Enter 11 | Sleep 3s 12 | Type "python sql2gpt.py get_prompt arail" Sleep 500ms Enter 13 | Sleep 10s 14 | -------------------------------------------------------------------------------- /util.py: -------------------------------------------------------------------------------- 1 | from urllib.parse import urlparse, urlsplit 2 | 3 | 4 | def get_db_type(database_url): 5 | # Parse the URL 6 | parsed_url = urlparse(database_url) 7 | 8 | # Extract and return the database type (scheme) 9 | return parsed_url.scheme 10 | 11 | 12 | def is_uri(string): 13 | # Split the string into URL components 14 | parsed_url = urlsplit(string) 15 | 16 | # Check if the URL has a valid scheme and netloc (network location) 17 | return bool(parsed_url.scheme) and bool(parsed_url.netloc) 18 | --------------------------------------------------------------------------------