2.0.6 • Published 5 years ago

sql2json v2.0.6

Weekly downloads
87
License
MIT
Repository
-
Last release
5 years ago

SQL2JSON

Build Status Test Coverage

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:

{  
   "select":[  
      {  
         "value":"*",
         "alias":null,
         "type":"wildcard"
      }
   ],
   "from":"tablename",
   "where":{  
      "type":"conditional",
      "value":"or",
      "left":{  
         "type":"conditional",
         "value":"and",
         "left":{  
            "type":"operator",
            "value":">",
            "left":{  
               "value":"a",
               "type":"literal"
            },
            "right":{  
               "value":2,
               "type":"number"
            }
         },
         "right":{  
            "type":"operator",
            "value":"<",
            "left":{  
               "value":"b",
               "type":"literal"
            },
            "right":{  
               "value":3,
               "type":"number"
            }
         }
      },
      "right":{  
         "type":"operator",
         "value":"=",
         "left":{  
            "value":"c",
            "type":"literal"
         },
         "right":{  
            "value":2,
            "type":"number"
         }
      }
   }
}

SQL support

Supported

  • select queries
  • delete queries
  • field alias
  • * in select clause
  • functions with and without arguments
  • basic math operators
  • constants

Unsupported

  • Anything other than select and delete 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 = require('sql2json').sql2json;
new Sql2json(<sql>).toJSON()

The library has a function that it convert json object to sql

To convert json to sql:

const Json2sql = require('sql2json').json2sql;
Json2sql.toSQL(<object>)
2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.6.5

6 years ago

1.6.4

7 years ago

1.6.3

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.24

7 years ago

1.5.23

7 years ago

1.5.22

7 years ago

1.5.21

7 years ago

1.5.20

7 years ago

1.5.19

7 years ago

1.5.18

7 years ago

1.5.17

7 years ago

1.5.16

7 years ago

1.5.15

7 years ago

1.5.14

7 years ago

1.5.13

7 years ago

1.5.12

7 years ago

1.5.11

7 years ago

1.5.10

7 years ago

1.5.9

7 years ago

1.5.8

7 years ago

1.5.7

7 years ago

1.5.6

7 years ago

1.5.5

7 years ago

1.5.4

7 years ago

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.10

7 years ago

1.4.9

7 years ago

1.4.8

7 years ago

1.4.7

7 years ago

1.4.6

7 years ago

1.4.5

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago