{"id":28573435,"url":"https://github.com/plasma-umass/sqlwrite","last_synced_at":"2025-06-10T21:18:10.315Z","repository":{"id":152821734,"uuid":"624078982","full_name":"plasma-umass/sqlwrite","owner":"plasma-umass","description":"SQLwrite: AI in your DBMS! Automatically converts natural language queries to SQL.","archived":false,"fork":false,"pushed_at":"2024-10-29T14:24:56.000Z","size":3047,"stargazers_count":121,"open_issues_count":0,"forks_count":9,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-10-29T17:34:29.980Z","etag":null,"topics":["database","sql","sqlite3"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plasma-umass.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2023-04-05T17:44:45.000Z","updated_at":"2024-10-29T14:25:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd259ead-5326-4f7c-8bb5-b112626df4e1","html_url":"https://github.com/plasma-umass/sqlwrite","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plasma-umass%2Fsqlwrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plasma-umass%2Fsqlwrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plasma-umass%2Fsqlwrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plasma-umass%2Fsqlwrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plasma-umass","download_url":"https://codeload.github.com/plasma-umass/sqlwrite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plasma-umass%2Fsqlwrite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259152777,"owners_count":22813225,"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":["database","sql","sqlite3"],"created_at":"2025-06-10T21:18:07.352Z","updated_at":"2025-06-10T21:18:10.305Z","avatar_url":"https://github.com/plasma-umass.png","language":"C","readme":"# SQLwrite\n\nby [Emery Berger](https://emeryberger.com)\n\nIntegrates AI into your database: automatically converts natural\nlanguage queries into SQL, and then runs the SQL query.  As far as we\nare aware, this is the first integration of LLMs to enable natural\nlanguage queries into a production database manager. Currently works\nas an extension to SQLite3 (more to come). In addition to generating\nqueries, SQLwrite also produces suggestions to improve query\nperformance (e.g., creating new indices).\n\n*NOTE*: To use SQLwrite, you must first set up an OpenAI API key. If you\nalready have an API key, you can set it as an environment variable\ncalled `OPENAI_API_KEY`. If you do not have one yet,\nyou can get a key here: https://platform.openai.com/account/api-keys\n\n```\nexport OPENAI_API_KEY=\u003cyour-api-key\u003e\n```\n\n## Examples\n\nThese example queries use a [large SQLite database with multiple tables](https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite):\n\n### Getting started\n\n```\n% export OPENAI_API_KEY=\u003cyour-api-key\u003e\n% ./sqlite3 Chinook_Sqlite.sqlite\nsqlite\u003e .load sqlwrite\nSQLwrite extension successfully initialized. You can now use natural language queries like \"select ask('show me all artists.');\".\nPlease report any issues to https://github.com/plasma-umass/sqlwrite/issues/new\n```\n\n### Basic queries\n\n```sql\nsqlite\u003e select ask('show me the total invoiced for all artists.');\n2328.6\n[SQLwrite] translation to SQL: SELECT SUM(Total) AS total_invoiced FROM Invoice;\n[SQLwrite] indexing suggestions to improve the performance for this query:\n(1): CREATE INDEX idx_invoice_total ON Invoice (Total);\n(2): CREATE INDEX idx_customer_invoice ON Invoice (CustomerId);\n```\n\n### Queries with JOINs\n\n```sql\nsqlite\u003e select ask('show me the total invoiced for all artists whose last name starts with \"S\"');\n306.98\n[SQLwrite] translation to SQL: SELECT sum(Invoice.Total) as total_invoiced FROM Invoice JOIN Customer ON Invoice.CustomerId = Customer.CustomerId WHERE Customer.LastName LIKE 'S%'\n[SQLwrite] indexing suggestions to improve the performance for this query:\n(1): CREATE INDEX idx_invoice_customer_lastname ON Invoice (CustomerId) WHERE (CustomerId IN (SELECT CustomerId FROM Customer WHERE LastName LIKE 'S%'))\n(2): CREATE INDEX idx_customer_lastname ON Customer (LastName)\n```\n\n### Complex query synthesis with multiple JOINs\n\n```sql\nsqlite\u003e select ask('give me a list of all artists (with no duplicates) whose genre is reggae');\nCidade Negra\nLenny Kravitz\nUB40\n[SQLwrite] translation to SQL: SELECT DISTINCT Artist.Name FROM Artist JOIN Album ON Album.ArtistId = Artist.ArtistId JOIN Track ON Track.AlbumId = Album.AlbumId JOIN Genre ON Track.GenreId = Genre.GenreId WHERE Genre.Name = 'Reggae';\n[SQLwrite] indexing suggestions to improve the performance for this query:\n(1): CREATE INDEX [IFK_TrackGenreReggae] ON [Track] ([GenreId]) WHERE Name = 'Reggae';\n```\n\n### Natural languages besides English!\n\n```sql\nsqlite\u003e select ask('Haz una lista de todos los músicos cuyos nombres empiezan con la letra L');\n22|Led Zeppelin\n33|Luiz Melodia\n99|Legião Urbana\n100|Lenny Kravitz\n101|Lulu Santos\n149|Lost\n162|Los Lonely Boys\n187|Los Hermanos\n201|Luciana Souza/Romero Lubambo\n223|London Symphony Orchestra \u0026 Sir Charles Mackerras\n227|Luciano Pavarotti\n228|Leonard Bernstein \u0026 New York Philharmonic\n258|Les Arts Florissants \u0026 William Christie\n[SQLwrite] translation to SQL: SELECT * FROM Artist WHERE Name LIKE 'L%';\n[SQLwrite] indexing suggestions to improve the performance for this query:\n(1): CREATE INDEX [IFK_ArtistName] ON [Artist] ([Name]);\n```\n\n## Installation\n\nDownload and run `make`. Currently Mac and Linux only. You may need to install the `curl` library.\n\n### Ubuntu\n\n```\nsudo apt install libcurl4-gnutls-dev\n```\n\n## Usage\n\nEither use the built-in SQLite (if it was built to allow extensions), or run the generated `sqlite3` file on your database:\n\n```\n./sqlite3 my_database.db\n```\n\nand then run the following command to load the SQLwrite extension:\n\n```\nselect load_extension(\"the_path_to_your_sqlwrite_directory/sqlwrite\");\n```\n\nor:\n```\n.load the_path_to_your_sqlwrite_directory/sqlwrite\n```\n\nYou can now issue English language queries by using the `ask` function:\n\n```sql\nSELECT ask('(whatever you want)');\n```\n\n## Acknowledgements\n\nSQLwrite includes SQLite3 (https://www.sqlite.org/index.html), and is\nbuilt with the assistance of several excellent libraries, whose code\nis (for now) included in this repository:\n\n* https://github.com/olrea/openai-cpp\n* https://github.com/nlohmann/json\n* https://fmt.dev/latest/index.html\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplasma-umass%2Fsqlwrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplasma-umass%2Fsqlwrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplasma-umass%2Fsqlwrite/lists"}