Coder Social home page Coder Social logo

whoiskatrin / sql-translator Goto Github PK

View Code? Open in Web Editor NEW
4.0K 4.0K 329.0 4.18 MB

SQL Translator is a tool for converting natural language queries into SQL code using artificial intelligence. This project is 100% free and open source.

Home Page: https://www.sqltranslate.app/

License: MIT License

TypeScript 84.91% JavaScript 6.90% CSS 6.11% Dockerfile 2.08%
data-analysis data-engineering dataquery datascience dataset openai postgresql query sql

sql-translator's People

Contributors

aarohmankad avatar abhinav2712 avatar andybrooker avatar code-arnab avatar difagume avatar eduardconstantin avatar ggallon avatar koayon avatar mirarifhasan avatar munierujp avatar nattyxo avatar necipakgz avatar nerohin avatar obaraelijah avatar plusv avatar ruanyl avatar sadmann7 avatar whoiskatrin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sql-translator's Issues

Dark/light toggle is broken

This is how it looks when you enter the first time on the website:

image

You can replicate this issue by using incognito.
Also, the border on the right card is different from the one on the left.

Some of the text is not readable

Hello,

While looking at this project I found some of the text is not read, white text on white background. please see images.

image
image

introduce test cases to this project

introduce test cases to this project

Test results:
FAIL test/jointQuery.test.ts (18.901 s)
● Console

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the total order count group by color of cars"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the total order count group by color of cars and sex of customer"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the count of cars that are green"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

● Joint Query › show me the total order count group by color of cars

expect(received).toEqual(expected) // deep equality

- Expected  - 3
+ Received  + 3

- SELECT cars.color, SUM(order.count) as total_order_count FROM cars
+ SELECT color, COUNT(order_id) AS total_order_count FROM cars 
- JOIN order ON cars.car_id = order.car_id
+ JOIN order ON cars.id = order.car_id
-  GROUP BY cars.color;
+ GROUP BY color;

  15 |         const case1: TestCase = { inputText, sql};
  16 |         const result = translateToSQL(case1.inputText, process.env.OPENAI_API_KEY, tableSchema);
> 17 |         expect(await result).toEqual(case1.sql);
     |                              ^
  18 |     });
  19 |     it("show me the total order count group by color of cars and sex of customer",async () => {
  20 |         const inputText = "show me the total order count group by color of cars and sex of customer";

  at test/jointQuery.test.ts:17:30
  at step (test/jointQuery.test.ts:33:23)
  at Object.next (test/jointQuery.test.ts:14:53)
  at fulfilled (test/jointQuery.test.ts:5:58)

● Joint Query › show me the total order count group by color of cars and sex of customer

expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 5

- SELECT COUNT(*) FROM cars;
+ SELECT color, sex, COUNT(order_id) AS total_order_count 
+ FROM cars 
+ INNER JOIN order ON cars.id = order.car_id 
+ INNER JOIN customer ON order.cus_id = customer.cus_id 
+ GROUP BY color, sex;

  22 |         const case1: TestCase = { inputText, sql};
  23 |         const result = translateToSQL(case1.inputText, process.env.OPENAI_API_KEY, tableSchema);
> 24 |         expect(await result).toEqual(case1.sql);
     |                              ^
  25 |     });
  26 |     it("show me the count of cars that are green",async () => {
  27 |         const inputText = "show me the count of cars that are green";

  at test/jointQuery.test.ts:24:30
  at step (test/jointQuery.test.ts:33:23)
  at Object.next (test/jointQuery.test.ts:14:53)
  at fulfilled (test/jointQuery.test.ts:5:58)

● Joint Query › show me the count of cars that are green

expect(received).toEqual(expected) // deep equality

- Expected  - 5
+ Received  + 1

- SELECT cars.color, customer.sex, SUM(order.count) as total_order_count
- FROM cars
- JOIN order ON cars.car_id = order.car_id
- JOIN customer ON order.cus_id = customer.cus_id
- GROUP BY cars.color, customer.sex;
+ SELECT COUNT(*) FROM cars WHERE color = 'Green';

  29 |         const case1: TestCase = { inputText, sql};
  30 |         const result = translateToSQL(case1.inputText, process.env.OPENAI_API_KEY, tableSchema);
> 31 |         expect(await result).toEqual(case1.sql);
     |                              ^
  32 |     });
  33 | });

  at test/jointQuery.test.ts:31:30
  at step (test/jointQuery.test.ts:33:23)
  at Object.next (test/jointQuery.test.ts:14:53)
  at fulfilled (test/jointQuery.test.ts:5:58)

FAIL test/singleQuery.test.ts (19.299 s)
● Console

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me all the cars that are red"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the count of cars"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the count of cars that are green"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the customer that age older than 20 years"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

console.log
  Translate this natural language query into SQL without changing the case of the entries given by me:
  
  "show me the total order count that date between '2023-03-01' AND '2023-03-31'"
  
  Use this table schema:
  
  CREATE TABLE cars (id INT, make TEXT, model TEXT, year INT, color TEXT);CREATE TABLE customer (cus_id INT, name TEXT, sex INT, age INT);CREATE TABLE order (order_id INT, car_id INT, cus_id INT, number INT, price DOUBLE, date DATE);
  
  SQL Query:

  at src/translateToSQL.ts:6:11

● Single Query › show me the total order count that date between '2023-03-01' AND '2023-03-31'

expect(received).toEqual(expected) // deep equality

Expected: "SELECT sum(count) FROM order WHERE date BETWEEN '2023-03-01' AND '2023-03-31';"
Received: "SELECT COUNT(order_id) FROM order WHERE date BETWEEN '2023-03-01' AND '2023-03-31';"

  43 |         const case1: TestCase = { inputText, sql};
  44 |         const result = translateToSQL(case1.inputText, process.env.OPENAI_API_KEY, tableSchema);
> 45 |         expect(await result).toEqual(case1.sql);
     |                              ^
  46 |     });
  47 | });

  at test/singleQuery.test.ts:45:30
  at step (test/singleQuery.test.ts:33:23)
  at Object.next (test/singleQuery.test.ts:14:53)
  at fulfilled (test/singleQuery.test.ts:5:58)

Test Suites: 2 failed, 2 total
Tests: 4 failed, 4 passed, 8 total
Snapshots: 0 total
Time: 20.693 s
Ran all test suites.

How about a little Ui/Ux retouch ?

I founded super interesting the tool, but while trying to use I experience some little issues like to much tiny text areas to fit content, and I could not help my self to wire up a little Ui iteration to help with that 😂
If you find it useful let me know, will be happy to help.

Resources:

Previews

sql-translator-concept

Leaking the API key?

Hey @whoiskatrin, nice project, congrats!

I was curious about its implementation and noticed that the openai API key is publicly visible. That's because the props from getServerSideProps are injected into the page. This might lead to unexpected billing costs If someone decides to abuse it.

Screenshot 2023-03-12 at 08 14 28

Have you considered using an API route for the translation part where you could use the API key without exposing it to the public??

Encountered the following error after clicking Generate SQL

After creating a new table schema, I entered the following in the Human Language: “show me all student”, and encountered the following error after clicking Generate SQL. What is the reason for this issue?

Table Schema:
create table student(id int,name string);

Error while translating Human language into SQL

Thanks for the awesome repository! I've followed all the steps, and I've successfully loaded the page on localhost. However, when attempting to convert human language into SQL, I encountered the following error.
sql-error

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.