Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local JavaScript Function to Format SQL queries like SQLFormat.org performs without the web call?

Currently, I can format my SQL queries programmatically by making POST request to the http://sqlformat.org/api/v1/format API; but there is a limitation of 500 request can be served per hour from the single IP as mentioned here http://sqlformat.org/api/#usage.

enter image description here

I am wondering if there is a local Javascript or other mechanism available in by which I can achieve the same result as obtained from the SQLFormat.org website locally without going to the web?

like image 297
user850234 Avatar asked Oct 31 '22 15:10

user850234


1 Answers

There is a javascript library to do that https://github.com/zeroturnaround/sql-formatter

Usage:

import sqlFormatter from "sql-formatter";
console.log(sqlFormatter.format("SELECT * FROM table1"));

This will output:

SELECT
  *
FROM
  table1
like image 92
REDDY PRASAD Avatar answered Nov 09 '22 12:11

REDDY PRASAD