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 1.2.4 to 1.3.0

18

lib/json2sql.js

@@ -119,3 +119,19 @@ function json2sql() {}

if (group) {
return `GROUP BY ${group.join(', ')}`;
const result = [];
for (let i = 0, length = group.length; i < length; i++) {
const node = group[i];
switch (node.type) {
case 'literal':
result.push(`${node.value}`);
break;
case 'function':
result.push(parseFunction(node));
break;
default:
break;
}
}
return `GROUP BY ${result.join(', ')}`;
}

@@ -122,0 +138,0 @@ return '';

@@ -420,4 +420,10 @@ const lexer = require('sql-parser').lexer;

case 'LITERAL':
stack.push(token[1]);
stack.push({
type: 'literal',
value: token[1]
});
break;
case 'FUNCTION':
stack.push(this.parseFunction(token[1]));
break;
default:

@@ -424,0 +430,0 @@ this.parsed.group = stack;

2

package.json
{
"name": "sql2json",
"version": "1.2.4",
"version": "1.3.0",
"description": "",

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

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

from: 'tablename',
group: ['name']
group: [{
type: 'literal',
value: 'name'
}]
};

@@ -335,3 +338,9 @@

from: 'tablename',
group: ['name', 'surname']
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}]
};

@@ -351,3 +360,9 @@

from: 'tablename',
group: ['name', 'surname'],
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}],
where: {

@@ -369,2 +384,29 @@ type: 'between',

});
it('Group with function', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
group: [{
type: 'function',
value: 'ST_GeoHash',
alias: null,
arguments: [{
type: 'literal',
value: 'the_geom_point'
}, {
type: 'number',
value: 8
}]
}],
};
const response = 'SELECT * FROM tablename GROUP BY ST_GeoHash(the_geom_point,8)';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

@@ -834,3 +876,9 @@

from: 'tablename',
group: ['name', 'surname'],
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}],
where: {

@@ -837,0 +885,0 @@ type: 'between',

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

});
it('With between and in', () => {

@@ -750,3 +750,6 @@ const response = {

from: 'tablename',
group: ['name']
group: [{
type: 'literal',
value: 'name'
}]
};

@@ -767,3 +770,9 @@

from: 'tablename',
group: ['name', 'surname']
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}]
};

@@ -784,3 +793,9 @@

from: 'tablename',
group: ['name', 'surname'],
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}],
where: {

@@ -803,2 +818,30 @@ type: 'between',

});
it('Group with function', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
group: [{
type: 'function',
value: 'ST_GeoHash',
alias: null,
arguments: [{
type: 'literal',
value: 'the_geom_point'
}, {
type: 'number',
value: 8
}]
}],
};
const obj = new Sql2json('select * from tablename group by ST_GeoHash(the_geom_point, 8)');
const json = obj.toJSON();
json.should.deepEqual(response);
});
});

@@ -934,3 +977,9 @@

from: 'tablename',
group: ['name', 'surname'],
group: [{
type: 'literal',
value: 'name'
}, {
type: 'literal',
value: 'surname'
}],
where: {

@@ -937,0 +986,0 @@ type: 'between',

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