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.1.0 to 1.1.1

8

lib/sql2json.js
const lexer = require('sql-parser').lexer;
const postgisFunctions = /ST_Intersects|ST_AsGeoJson|ST_SetSRID|ST_GeomFromGeoJSON/gi;
const postgisFunctions = /ST_Intersects|ST_AsGeoJson|ST_SetSRID|ST_GeomFromGeoJSON|ST_METADATA|ST_SUMMARYSTATS|ST_HISTOGRAM/gi;
const between = /between/gi;

@@ -134,2 +134,8 @@

return;
case 'STRING':
this.parsed.from = `'${token[1]}'`;
return;
case 'DBLSTRING':
this.parsed.from = `"${token[1]}"`;
return;
default:

@@ -136,0 +142,0 @@ return;

2

package.json
{
"name": "sql2json",
"version": "1.1.0",
"version": "1.1.1",
"description": "",

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

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

describe('From', () => {
it('With table name', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename'
};
const response = 'SELECT * FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);
});
it('With table name inside quotes', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '"tablename"'
};
const response = 'SELECT * FROM "tablename"';
Json2sql.toSQL(data).should.deepEqual(response);
});
it('With table name inside quotes 2', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '"ft:table/name"'
};
const response = 'SELECT * FROM "ft:table/name"';
Json2sql.toSQL(data).should.deepEqual(response);
});
it('With table name inside simple quotes', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '\'ft:tablename\''
};
const response = 'SELECT * FROM \'ft:tablename\'';
Json2sql.toSQL(data).should.deepEqual(response);
});
});
describe('Select', () => {

@@ -141,2 +201,17 @@ it('SQL with wildcard', () => {

});
it('SQL with gee function', () => {
const data = {
select: [{
alias: 'total',
type: 'function',
value: 'ST_HISTOGRAM',
arguments: []
}],
from: 'tablename'
};
const response = 'SELECT ST_HISTOGRAM() AS total FROM tablename';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

@@ -143,0 +218,0 @@ describe('OrderBy', () => {

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

describe('From', () => {
it('With table name', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename'
};
const obj = new Sql2json('select * from tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
it('With table name inside quotes', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '"tablename"'
};
const obj = new Sql2json('select * from "tablename"');
const json = obj.toJSON();
json.should.deepEqual(response);
});
it('With table name inside quotes 2', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '"ft:table/name"'
};
const obj = new Sql2json('select * from "ft:table/name"');
const json = obj.toJSON();
json.should.deepEqual(response);
});
it('With table name inside simple quotes', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: '\'ft:tablename\''
};
const obj = new Sql2json('select * from \'ft:tablename\'');
const json = obj.toJSON();
json.should.deepEqual(response);
});
});
describe('Select', () => {

@@ -150,2 +214,18 @@

it('SQL with gee function', () => {
const response = {
select: [{
alias: 'total',
type: 'function',
value: 'ST_HISTOGRAM',
arguments: []
}],
from: 'tablename'
};
const obj = new Sql2json('select ST_HISTOGRAM() as total from tablename');
const json = obj.toJSON();
json.should.deepEqual(response);
});
});

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

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