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 - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

4

CHANGELOG.md

@@ -1,3 +0,5 @@

# 2.0
# 2.0.1
- JSON2SQL - Revert changes to query output format, matching it to ES SQL instead of PostrgreSQL spec
# 2.0.0
- SQL2JSON - functions with no arguments are now parsed as functions, not literals

@@ -4,0 +6,0 @@ - SQL2JSON - `string` types are now stored without quotes/double quotes

@@ -12,3 +12,7 @@ function json2sql() {}

case 'literal':
args.push(`${node.name ? ` '${node.name}'=` : ''}"${node.value}"`);
if (node.name) {
args.push(`${node.name ? ` '${node.name}'=` : ''}"${node.value}"`);
} else {
args.push(`${node.name ? ` '${node.name}'=` : ''}${node.value}`);
}
break;

@@ -46,3 +50,3 @@ case 'string':

case 'literal':
args.push(`"${node.value}"`);
args.push(`${node.value}`);
break;

@@ -77,3 +81,3 @@ case 'string':

case 'literal':
responses.push(`"${node.value}"${node.alias ? ` AS ${node.alias}` : ''}`);
responses.push(`${node.value}${node.alias ? ` AS ${node.alias}` : ''}`);
break;

@@ -168,3 +172,3 @@ case 'string':

case 'literal':
responses.push(`"${orderBy[i].value}"${orderBy[i].direction ? ` ${orderBy[i].direction}` : ''}`);
responses.push(`${orderBy[i].value}${orderBy[i].direction ? ` ${orderBy[i].direction}` : ''}`);
break;

@@ -189,3 +193,3 @@ default:

case 'literal':
result.push(`"${node.value}"`);
result.push(`${node.value}`);
break;

@@ -192,0 +196,0 @@ case 'number':

{
"name": "sql2json",
"version": "2.0.0",
"version": "2.0.1",
"description": "PostgreSQL to/from JSON conversion lib",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,3 +6,5 @@ # SQL2JSON

Library that converts PostgreSQL queries to/from JSON representation of the query.
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](https://github.com/NLPchina/elasticsearch-sql)

@@ -9,0 +11,0 @@ Example:

@@ -41,5 +41,5 @@ const assert = require('assert');

const response = 'SELECT * FROM tablename WHERE data BETWEEN 1 AND 3 GROUP BY "name", "surname" ORDER BY "name" LIMIT 1';
const response = 'SELECT * FROM tablename WHERE data BETWEEN 1 AND 3 GROUP BY name, surname ORDER BY name LIMIT 1';
CompleyQueries.toSQL(data).should.deepEqual(response);
});
});

@@ -32,3 +32,3 @@ const assert = require('assert');

const response = 'SELECT "data + 1000" FROM tablename';
const response = 'SELECT data + 1000 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -54,3 +54,3 @@ });

const response = 'SELECT "data" + 1000 FROM tablename';
const response = 'SELECT data + 1000 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -69,3 +69,3 @@ });

const response = 'SELECT "col1, col2" FROM tablename';
const response = 'SELECT col1, col2 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -88,3 +88,3 @@ });

const response = 'SELECT "col1", "col2" FROM tablename';
const response = 'SELECT col1, col2 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -103,3 +103,3 @@ });

const response = 'SELECT "Shape.STLength(), x" FROM tablename';
const response = 'SELECT Shape.STLength(), x FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -123,3 +123,3 @@ });

const response = 'SELECT Shape.STLength(), "x" FROM tablename';
const response = 'SELECT Shape.STLength(), x FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -164,3 +164,3 @@ });

const response = 'SELECT ST_Intersects("the_geom",\'{}\') FROM tablename';
const response = 'SELECT ST_Intersects(the_geom,\'{}\') FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -200,3 +200,3 @@ });

const response = 'SELECT "col1", "col2" FROM tablename WHERE ST_Intersects(the_geom, \'{}\')';
const response = 'SELECT col1, col2 FROM tablename WHERE ST_Intersects(the_geom, \'{}\')';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -220,3 +220,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY "avg( name)"';
const response = 'SELECT * FROM tablename ORDER BY avg( name)';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -247,3 +247,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY avg("name")';
const response = 'SELECT * FROM tablename ORDER BY avg(name)';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -279,3 +279,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY avg("name"), "name" asc';
const response = 'SELECT * FROM tablename ORDER BY avg(name), name asc';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -310,5 +310,5 @@ });

const response = 'SELECT * FROM tablename GROUP BY ST_GeoHash("the_geom_point",8)';
const response = 'SELECT * FROM tablename GROUP BY ST_GeoHash(the_geom_point,8)';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

@@ -21,3 +21,3 @@ const assert = require('assert');

const response = 'SELECT * FROM tablename GROUP BY "name"';
const response = 'SELECT * FROM tablename GROUP BY name';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -61,3 +61,3 @@ });

const response = 'SELECT * FROM tablename GROUP BY "name", "surname"';
const response = 'SELECT * FROM tablename GROUP BY name, surname';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -94,3 +94,3 @@ });

const response = 'SELECT * FROM tablename WHERE data BETWEEN 1 AND 3 GROUP BY "name", "surname"';
const response = 'SELECT * FROM tablename WHERE data BETWEEN 1 AND 3 GROUP BY name, surname';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -122,3 +122,3 @@ });

const response = 'SELECT * FROM tablename GROUP BY ST_GeoHash("the_geom_point",8)';
const response = 'SELECT * FROM tablename GROUP BY ST_GeoHash(the_geom_point,8)';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -149,3 +149,3 @@ });

const response = 'SELECT * FROM tablename GROUP BY date_histogram("createdAt",\'1d\')';
const response = 'SELECT * FROM tablename GROUP BY date_histogram(createdAt,\'1d\')';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -152,0 +152,0 @@

@@ -22,3 +22,3 @@ const assert = require('assert');

const response = 'SELECT * FROM tablename ORDER BY "name"';
const response = 'SELECT * FROM tablename ORDER BY name';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -63,3 +63,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY "name"';
const response = 'SELECT * FROM tablename ORDER BY name';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -85,3 +85,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY "name"';
const response = 'SELECT * FROM tablename ORDER BY name';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -170,3 +170,3 @@ });

const response = 'SELECT * FROM tablename ORDER BY avg("name")';
const response = 'SELECT * FROM tablename ORDER BY avg(name)';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -204,5 +204,5 @@ });

const response = 'SELECT * FROM tablename ORDER BY avg("name") asc, sum("num")';
const response = 'SELECT * FROM tablename ORDER BY avg(name) asc, sum(num)';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

@@ -65,3 +65,3 @@ const assert = require('assert');

const response = 'SELECT Shape.STLength(), "x" FROM tablename';
const response = 'SELECT Shape.STLength(), x FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -94,3 +94,3 @@ });

const response = 'SELECT "column1" FROM tablename';
const response = 'SELECT column1 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -113,3 +113,3 @@ });

const response = 'SELECT "column1", "column2" FROM tablename';
const response = 'SELECT column1, column2 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -128,3 +128,3 @@ });

const response = 'SELECT "column1" AS aliascolumn FROM tablename';
const response = 'SELECT column1 AS aliascolumn FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -143,3 +143,3 @@ });

const response = 'SELECT "column1" AS count FROM tablename';
const response = 'SELECT column1 AS count FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -166,3 +166,3 @@ });

const response = 'SELECT "column1" AS aliascolumn, "column2", "column3" FROM tablename';
const response = 'SELECT column1 AS aliascolumn, column2, column3 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -185,3 +185,3 @@ });

const response = 'SELECT sum("column1") FROM tablename';
const response = 'SELECT sum(column1) FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -204,3 +204,3 @@ });

const response = 'SELECT sum("column1") AS total FROM tablename';
const response = 'SELECT sum(column1) AS total FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -237,3 +237,3 @@ });

const response = 'SELECT DISTINCT "countries" FROM tablename';
const response = 'SELECT DISTINCT countries FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -259,3 +259,3 @@ });

const response = 'SELECT DISTINCT "countries", "cities" FROM tablename';
const response = 'SELECT DISTINCT countries, cities FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -297,3 +297,3 @@ });

const response = 'SELECT "false", "name" FROM tablename';
const response = 'SELECT false, name FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -316,3 +316,3 @@ });

const response = 'SELECT false, "name" FROM tablename';
const response = 'SELECT false, name FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -338,3 +338,3 @@ });

const response = 'SELECT "data" + 1000 FROM tablename';
const response = 'SELECT data + 1000 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -364,3 +364,3 @@ });

const response = 'SELECT round("data") + 1000 FROM tablename';
const response = 'SELECT round(data) + 1000 FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -395,3 +395,3 @@ });

const response = 'SELECT sum(round("data") / 1000) FROM tablename';
const response = 'SELECT sum(round(data) / 1000) FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);

@@ -398,0 +398,0 @@ });

Sorry, the diff of this file is not supported yet

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