SQL2JSON
Library that serves two main purposes:
- Converts SQL queries to JSON representation of the query.
- Converts JSON representation of the query to SQL (as supported by ElasticSearch's SQL plugin
Example:
With this SQL
SELECT * FROM tablename WHERE a > 2 and b < 3 or c = 2
Return this object:
SQL support
Supported
select
queriesdelete
queries- field alias
*
in select clause- functions with and without arguments
- basic math operators
- constants
Unsupported
- Anything other than
select
anddelete
queries - Subqueries
- Joins
- conditionals
- pretty much everything that's not covered in the tests
Installation
npm install --save sql2json
Use
To convert sql to json:
const Sql2json = sql2json;<sql>
The library has a function that it convert json object to sql
To convert json to sql:
const Json2sql = json2sql;Json2sql