Comparing version 2.0.5 to 2.0.6
@@ -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': |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
244943
5780