Giter Club home page Giter Club logo

sqlwrite's Introduction

SQLwrite

by Emery Berger

Integrates AI into your database: automatically converts natural language queries into SQL, and then runs the SQL query. As far as we are aware, this is the first integration of LLMs to enable natural language queries into a production database manager. Currently works as an extension to SQLite3, more to come!

Examples

These example queries use a large SQLite database with multiple tables:

Basic queries

% ./sqlite3 Chinook_Sqlite.sqlite
sqlite> select ask('show me the total invoiced for all artists.');
2328.6
(SQLwrite translation to SQL: SELECT sum(Invoice.Total) FROM Invoice;;)

Queries with JOINs

sqlite> select ask('show me the total invoiced for all artists whose last name starts with "S"');
306.98
(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%';)

Complex query synthesis with multiple JOINs

sqlite> select ask('give me a list of all artists (with no duplicates) whose genre is reggae');
Cidade Negra
Lenny Kravitz
UB40
(SQLwrite translation to SQL: SELECT DISTINCT Artist.Name     FROM Artist    JOIN Album ON Artist.ArtistId = Album.ArtistId    JOIN Track ON Album.AlbumId = Track.AlbumId    JOIN Genre ON Track.GenreId = Genre.GenreId    WHERE Genre.Name = 'Reggae';;)

Natural languages besides English!

sqlite> select ask('Haz una lista de todos los artistas cuyos nombres empiezan con la letra L');
Led Zeppelin
Luiz Melodia
Legião Urbana
Lenny Kravitz
Lulu Santos
Lost
Los Lonely Boys
Los Hermanos
Luciana Souza/Romero Lubambo
London Symphony Orchestra & Sir Charles Mackerras
Luciano Pavarotti
Leonard Bernstein & New York Philharmonic
Les Arts Florissants & William Christie
(SQLwrite translation to SQL: SELECT Name FROM Artist WHERE Name LIKE 'L%';)

Installation

Download and run make. Currently Mac and Linux only. You may need to install the curl library.

Ubuntu

sudo apt install libcurl4-gnutls-dev

Usage

Either use the built-in SQLite (if it was built to allow extensions), or run the generated sqlite3 file on your database:

./sqlite3 my_database.db

and then run the following command to load the SQLwrite extension:

select load_extension("the_path_to_your_sqlwrite_directory/sqlwrite");

or:

.load the_path_to_your_sqlwrite_directory/sqlwrite

You can now issue English language queries by using the ask function:

SELECT ask('(whatever you want)');

Acknowledgements

SQLwrite includes SQLite3 (https://www.sqlite.org/index.html), and is built with the assistance of several excellent libraries, whose code is (for now) included in this repository:

sqlwrite's People

Contributors

emeryberger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.