Comparing version 1.1.0 to 1.1.1
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; |
{ | ||
"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 @@ |
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
65818
1850