can stringify a JSON into a SQL and viceversa parse a SQL statement and serialize it into a JSON
npm install mifei-clone-sql92-jsonwhy fork ? because support the insert ,update sql .
> can stringify a JSON into a SQL and viceversa parse a SQL statement and serialize it into a JSON
Installation |
API |
Examples |
Recipes |
References |
License






With npm do
``bash`
npm install sql92-json
Add this to your HTML page
`html`
Both CommonJS and ES6 imports are supported. Code snippets below use
require, it is also possible to do
`javascript`
import { parse, stringify } from 'sql92-json'
> Convert a JSON to SQL
Both require('sql92-json').stringify and require('sql92-json/stringify') are valid.
`javascript
var json2sql = require('sql92-json').stringify
console.log(json2sql({ SELECT: ['*'], FROM: ['revenue'] }))
//
// SELECT *
// FROM revenue
//
`
> Convert an SQL to JSON
Both require('sql92-json').parse and require('sql92-json/parse') are valid.
`javascript
var sql2json = require('sql92-json').parse
console.log(sql2json('SELECT * FROM revenue')
// {
// SELECT: ['*'],
// FROM: ['revenue']
// }
`
* Add resultset limit (WiP)
* Compute resultset count
* Prepend pool header
* Table list (PoC)
See [examples] folder where every .json file has its homonym .sql.
See for example the following [example JSON][exampleJSON] and its [corresponding SQL][exampleSQL].
`json`
{
"SELECT": [ { "COUNT": "*", "AS": "num" } ],
"FROM": [
{
"SELECT": ["*"],
"FROM": ["mytable"],
"WHERE": [
"yyyymmdd", { "=": 20170101 },
{ "AND": [ "country", { "IN": ["IT", "US"] } ] },
{ "AND": [
"categoryid", { "BETWEEN": [100, 200] },
{ "OR": [ "productname", { "!=": "'icecream'" } ] }
] }
]
}
]
}
`sql``
SELECT COUNT(*) AS num
FROM (
SELECT *
FROM mytable
WHERE yyyymmdd = 20170101
AND country IN ( 'IT', 'US' )
AND (
categoryid BETWEEN 100 AND 200
OR productname != 'icecream'
)
)
sql1992.txt was downloaded from here.
[examples]: https://github.com/fibo/SQL92-JSON/tree/master/examples
[exampleSQL]: https://github.com/fibo/SQL92-JSON/blob/master/examples/_readme.select.sql
[exampleJSON]: https://github.com/fibo/SQL92-JSON/blob/master/examples/_readme.select.json