Socket
Socket
Sign inDemoInstall

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.5 to 2.0.6

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 2.0.6
- Fix issue with json2sql conversion of DOT tokens on SELECT clauses
# 2.0.5

@@ -2,0 +5,0 @@ - Fix issue with arguments with column and table name

@@ -91,3 +91,7 @@ function json2sql() {

case 'literal':
responses.push(`${node.value}${node.alias ? ` AS ${node.alias}` : ''}`);
if (select[i - 1] && select[i - 1].type === 'dot') {
responses.push(`${responses.pop()}${node.value}${node.alias ? ` AS ${node.alias}` : ''}`);
} else {
responses.push(`${node.value}${node.alias ? ` AS ${node.alias}` : ''}`);
}
break;

@@ -94,0 +98,0 @@ case 'string':

2

package.json
{
"name": "sql2json",
"version": "2.0.5",
"version": "2.0.6",
"description": "PostgreSQL to/from JSON conversion lib",

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

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

it('SQL with string with alias, functions, column and table name with alias, etc', () => {
const data = {
select: [
{ value: 'bound1', alias: null, type: 'literal' },
{ value: 'polyname', alias: null, type: 'literal' },
{ value: 'year_data', alias: null, type: 'literal' },
{ type: 'dot' },
{ value: 'year', alias: 'year', type: 'literal' },
{
type: 'function',
alias: 'area',
value: 'SUM',
arguments: [
{ value: 'year_data', type: 'literal' },
{ type: 'dot' },
{ value: 'area_loss', type: 'literal' }
]
},
{
type: 'function',
alias: 'emissions',
value: 'SUM',
arguments: [
{ value: 'year_data', type: 'literal' },
{ type: 'dot' },
{ value: 'emissions', type: 'literal' }
]
}
],
from: 'tablename'
};
const response = 'SELECT bound1, polyname, year_data.year AS year, SUM(year_data.area_loss) AS area, SUM(year_data.emissions) AS emissions FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

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

type: 'dot',
},{
}, {
type: 'literal',

@@ -630,2 +630,39 @@ alias: null,

it('SQL with string with alias, functions, column and table name with alias, etc', () => {
const response = {
select: [
{ value: 'bound1', alias: null, type: 'literal' },
{ value: 'polyname', alias: null, type: 'literal' },
{ value: 'year_data', alias: null, type: 'literal' },
{ type: 'dot' },
{ value: 'year', alias: 'year', type: 'literal' },
{
type: 'function',
alias: 'area',
value: 'SUM',
arguments: [
{ value: 'year_data', type: 'literal' },
{ type: 'dot' },
{ value: 'area_loss', type: 'literal' }
]
},
{
type: 'function',
alias: 'emissions',
value: 'SUM',
arguments: [
{ value: 'year_data', type: 'literal' },
{ type: 'dot' },
{ value: 'emissions', type: 'literal' }
]
}
],
from: 'tablename'
};
const obj = new Sql2json('SELECT bound1, polyname, year_data.year AS year, SUM(year_data.area_loss) AS area, SUM(year_data.emissions) AS emissions FROM tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
});

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