Comparing version 1.4.2 to 1.4.3
@@ -46,2 +46,5 @@ function json2sql() {} | ||
break; | ||
case 'distinct': | ||
responses.push(`DISTINCT ${parseSelect(node.arguments)}`); | ||
break; | ||
default: | ||
@@ -48,0 +51,0 @@ break; |
@@ -114,2 +114,3 @@ const lexer = require('sql-parser').lexer; | ||
let containAs = false; | ||
let isDistinct = false; | ||
while (this.hasNext()) { | ||
@@ -149,2 +150,5 @@ const token = this.next(); | ||
break; | ||
case 'DISTINCT': | ||
isDistinct = true; | ||
break; | ||
case 'SEPARATOR': | ||
@@ -154,2 +158,8 @@ break; | ||
this.index--; | ||
if (isDistinct) { | ||
this.parsed.select = [{ | ||
type: 'distinct', | ||
arguments: this.parsed.select | ||
}]; | ||
} | ||
return; | ||
@@ -156,0 +166,0 @@ |
{ | ||
"name": "sql2json", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -277,2 +277,40 @@ const assert = require('assert'); | ||
}); | ||
it('SQL with distinct', () => { | ||
const data = { | ||
select: [{ | ||
type: 'distinct', | ||
arguments: [{ | ||
value: 'countries', | ||
type: 'literal', | ||
alias: null | ||
}] | ||
}], | ||
from: 'tablename' | ||
}; | ||
const response = 'SELECT DISTINCT countries FROM tablename'; | ||
Json2sql.toSQL(data).should.deepEqual(response); | ||
}); | ||
it('SQL with distinct with several files', () => { | ||
const data = { | ||
select: [{ | ||
type: 'distinct', | ||
arguments: [{ | ||
value: 'countries', | ||
type: 'literal', | ||
alias: null | ||
}, { | ||
value: 'cities', | ||
type: 'literal', | ||
alias: null | ||
}] | ||
}], | ||
from: 'tablename' | ||
}; | ||
const response = 'SELECT DISTINCT countries, cities FROM tablename'; | ||
Json2sql.toSQL(data).should.deepEqual(response); | ||
}); | ||
}); | ||
@@ -279,0 +317,0 @@ describe('OrderBy', () => { |
@@ -295,2 +295,42 @@ const assert = require('assert'); | ||
it('SQL with distinct', () => { | ||
const response = { | ||
select: [{ | ||
type: 'distinct', | ||
arguments: [{ | ||
value: 'countries', | ||
type: 'literal', | ||
alias: null | ||
}] | ||
}], | ||
from: 'tablename' | ||
}; | ||
const obj = new Sql2json('select distinct countries from tablename'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
it('SQL with distinct with several files', () => { | ||
const response = { | ||
select: [{ | ||
type: 'distinct', | ||
arguments: [{ | ||
value: 'countries', | ||
type: 'literal', | ||
alias: null | ||
}, { | ||
value: 'cities', | ||
type: 'literal', | ||
alias: null | ||
}] | ||
}], | ||
from: 'tablename' | ||
}; | ||
const obj = new Sql2json('select distinct countries, cities from tablename'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
@@ -297,0 +337,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
87025
2480