little-brother / sqlite-gui

Lightweight SQLite editor for Windows
GNU General Public License v2.0
1.07k stars 51 forks source link

Request for additional new feature of REST API: #135

Closed abeq closed 1 year ago

abeq commented 1 year ago

Hi,

POST with query like as

const query={"query":"SELECT c.fullname AS customer,b.title AS book,(b.price*ob.quantity) AS subtotal,o.id AS order_id \
FROM order_books AS ob \
INNER JOIN books AS b ON ob.book_id=b.id \
INNER JOIN orders AS o ON ob.order_id=o.id \
INNER JOIN customers AS c ON o.customer_id=c.id \
WHERE c.id=1;"};

let postdata = async ()=>{
 const response = await fetch('http://127.0.0.1/api', {
  method:'POST',
  //...snip...
  body:JSON.stringify(query) 
 });
 return response.json();
}

response.json would be:

[{"customer":"Bran Oldy","book":"Take Me With You","subtotal":1.98,"order_id":1},
{"customer":"Bran Oldy","book":"Secrets of a Charmed Life","subtotal":3.2,"order_id":1},
{"customer":"Bran Oldy","book":"The Way We Fall","subtotal":18.1,"order_id":6},
{"customer":"Bran Oldy","book":"The Girl on the Train","subtotal":99,"order_id":9,6},
{"customer":"Bran Oldy","book":"Secrets of a Charmed Life","subtotal":6.4,"order_id":12},
{"customer":"Bran Oldy","book":"Steelheart","subtotal":5.0,"order_id":12},
{"customer":"Bran Oldy","book":"Steelheart","subtotal":5.0,"order_id":15}]

I think it is useful for development. Please consider it.

little-brother commented 1 year ago

POST have to create a new row (= change a data). So GET is more appropriate verb for it. But I'm not sure why it can be usefull. Typically API don't allow to execute an arbitrary queries.

abeq commented 1 year ago

I think this REST server is for development so it is useful on early stage of prototype development (yet appropriate query is not defined). And does this REST server support GET with request body? Typical GET is not for complex query.

abeq commented 1 year ago

withdrawn