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.4.3 to 1.4.4

10

lib/sql2json.js
const lexer = require('sql-parser').lexer;
const postgisFunctions = /ST_Intersects|ST_AsGeoJson|ST_SetSRID|ST_GeomFromGeoJSON|ST_METADATA|ST_SUMMARYSTATS|ST_HISTOGRAM|TO_NUMBER|TO_CHAR|ST_GeoHash|st_centroid/gi;
const postgisFunctions = /ST_Intersects|ST_AsGeoJson|ST_SetSRID|ST_GeomFromGeoJSON|ST_METADATA|ST_SUMMARYSTATS|ST_HISTOGRAM|TO_NUMBER|TO_CHAR|ST_GeoHash|first|last|ST_BANDMETADATA|st_centroid/gi;
const between = /between/gi;

@@ -142,2 +142,4 @@ const sqlStatements = /delete/gi;

case 'FUNCTION':
case 'FIRST':
case 'LAST':
if (containAs) {

@@ -314,2 +316,4 @@ this.parsed.select[this.parsed.select.length - 1].alias = token[1];

case 'FUNCTION':
case 'LAST':
case 'FIRST':
stack.push(this.parseFunction(token[1]));

@@ -339,3 +343,3 @@ break;

conditional = null;
}

@@ -366,3 +370,3 @@ conditional = token[1];

conditional = null;
}

@@ -369,0 +373,0 @@ this.parsed.where = stack.pop();

{
"name": "sql2json",
"version": "1.4.3",
"version": "1.4.4",
"description": "",

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

@@ -335,2 +335,64 @@ const assert = require('assert');

it('SQL with FIRST function', () => {
const response = {
select: [{
alias: null,
type: 'function',
value: 'first',
arguments: [{
value: 'column1',
type: 'literal'
}]
}],
from: 'tablename'
};
const obj = new Sql2json('select first(column1) from tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
it('SQL with LAST function', () => {
const response = {
select: [{
alias: null,
type: 'function',
value: 'last',
arguments: [{
value: 'column1',
type: 'literal'
}]
}],
from: 'tablename'
};
const obj = new Sql2json('select last(column1) from tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
it('SQL with ST_BANDMETADATA function', () => {
const response = {
select: [{
alias: null,
type: 'function',
value: 'ST_BANDMETADATA',
arguments: [{
value: 'rast',
type: 'literal'
},
{
value: 1,
type: 'number'
}
]
}],
from: 'tablename'
};
const obj = new Sql2json('select ST_BANDMETADATA(rast, 1) from tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
});

@@ -337,0 +399,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