Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql2json

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql2json

PostgreSQL to/from JSON conversion lib

  • 2.0.2
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

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>)

Keywords

FAQs

Package last updated on 19 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc