Comparing version 1.1.3 to 1.2.0
{ | ||
"name": "sql2json", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"sql-parser": "^0.5.0" | ||
"sql-parser": "git+http://github.com/rrequero/sql-parser.git#master" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": { |
@@ -735,2 +735,28 @@ const assert = require('assert'); | ||
it('With cast', () => { | ||
const data = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
where: { | ||
type: 'operator', | ||
left: { | ||
value: 'day::int', | ||
type: 'literal' | ||
}, | ||
value: '>', | ||
right: { | ||
value: 2, | ||
type: 'number' | ||
} | ||
} | ||
}; | ||
const response = 'SELECT * FROM tablename WHERE day::int > 2'; | ||
Json2sql.toSQL(data).should.deepEqual(response); | ||
}); | ||
}); | ||
@@ -737,0 +763,0 @@ |
@@ -655,218 +655,245 @@ const assert = require('assert'); | ||
it('With cast', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
where: { | ||
type: 'operator', | ||
left: { | ||
value: 'day::int', | ||
type: 'literal' | ||
}, | ||
value: '>', | ||
right: { | ||
value: 2, | ||
type: 'number' | ||
} | ||
} | ||
}; | ||
const obj = new Sql2json('select * from tablename where day::int > 2'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
// describe('GroupBy', () => { | ||
// it('Group by one field', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// group: ['name'] | ||
// }; | ||
describe('GroupBy', () => { | ||
it('Group by one field', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
group: ['name'] | ||
}; | ||
// const obj = new Sql2json('select * from tablename group by name'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename group by name'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('Group by several fields', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// group: ['name', 'surname'] | ||
// }; | ||
it('Group by several fields', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
group: ['name', 'surname'] | ||
}; | ||
// const obj = new Sql2json('select * from tablename group by name, surname'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename group by name, surname'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('Group with where', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// group: ['name', 'surname'], | ||
// where: { | ||
// type: 'between', | ||
// value: 'data', | ||
// arguments: [{ | ||
// value: 1, | ||
// type: 'number' | ||
// }, { | ||
// value: 3, | ||
// type: 'number' | ||
// }] | ||
// } | ||
// }; | ||
it('Group with where', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
group: ['name', 'surname'], | ||
where: { | ||
type: 'between', | ||
value: 'data', | ||
arguments: [{ | ||
value: 1, | ||
type: 'number' | ||
}, { | ||
value: 3, | ||
type: 'number' | ||
}] | ||
} | ||
}; | ||
// const obj = new Sql2json('select * from tablename where data between 1 and 3 group by name, surname'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
// }); | ||
const obj = new Sql2json('select * from tablename where data between 1 and 3 group by name, surname'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
// describe('OrderBy', () => { | ||
// it('SQL with orderby', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// orderBy: [{ | ||
// value: 'name', | ||
// direction: null | ||
// }] | ||
// }; | ||
describe('OrderBy', () => { | ||
it('SQL with orderby', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
orderBy: [{ | ||
value: 'name', | ||
direction: null | ||
}] | ||
}; | ||
// const obj = new Sql2json('select * from tablename order by name'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename order by name'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('SQL with orderby and direction', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// orderBy: [{ | ||
// value: 'name', | ||
// direction: 'asc' | ||
// }] | ||
// }; | ||
it('SQL with orderby and direction', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
orderBy: [{ | ||
value: 'name', | ||
direction: 'asc' | ||
}] | ||
}; | ||
// const obj = new Sql2json('select * from tablename order by name asc'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename order by name asc'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('SQL with several orderby and direction', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// orderBy: [{ | ||
// value: 'name', | ||
// direction: 'asc' | ||
// }, { | ||
// value: 'createdAt', | ||
// direction: 'desc' | ||
// }] | ||
// }; | ||
it('SQL with several orderby and direction', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
orderBy: [{ | ||
value: 'name', | ||
direction: 'asc' | ||
}, { | ||
value: 'createdAt', | ||
direction: 'desc' | ||
}] | ||
}; | ||
// const obj = new Sql2json('select * from tablename order by name asc, createdAt desc'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename order by name asc, createdAt desc'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('SQL with several orderby and direction 2', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// orderBy: [{ | ||
// value: 'name', | ||
// direction: 'asc' | ||
// }, { | ||
// value: 'createdAt', | ||
// direction: null | ||
// }] | ||
// }; | ||
it('SQL with several orderby and direction 2', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
orderBy: [{ | ||
value: 'name', | ||
direction: 'asc' | ||
}, { | ||
value: 'createdAt', | ||
direction: null | ||
}] | ||
}; | ||
// const obj = new Sql2json('select * from tablename order by name asc, createdAt'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
// }); | ||
const obj = new Sql2json('select * from tablename order by name asc, createdAt'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
// describe('Limit and offset', () => { | ||
// it('Limit', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// limit: 5 | ||
// }; | ||
describe('Limit and offset', () => { | ||
it('Limit', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
limit: 5 | ||
}; | ||
// const obj = new Sql2json('select * from tablename limit 5'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
const obj = new Sql2json('select * from tablename limit 5'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
// it('Offset', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// limit: 5, | ||
// offset: 10 | ||
// }; | ||
it('Offset', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
limit: 5, | ||
offset: 10 | ||
}; | ||
// const obj = new Sql2json('select * from tablename limit 5 offset 10'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
// }); | ||
const obj = new Sql2json('select * from tablename limit 5 offset 10'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
// describe('all', () => { | ||
// it('All', () => { | ||
// const response = { | ||
// select: [{ | ||
// value: '*', | ||
// alias: null, | ||
// type: 'wildcard' | ||
// }], | ||
// from: 'tablename', | ||
// group: ['name', 'surname'], | ||
// where: { | ||
// type: 'between', | ||
// value: 'data', | ||
// arguments: [{ | ||
// value: 1, | ||
// type: 'number' | ||
// }, { | ||
// value: 3, | ||
// type: 'number' | ||
// }] | ||
// }, | ||
// limit: 1, | ||
// orderBy: [{ | ||
// value: 'name', | ||
// direction: null | ||
// }] | ||
// }; | ||
describe('all', () => { | ||
it('All', () => { | ||
const response = { | ||
select: [{ | ||
value: '*', | ||
alias: null, | ||
type: 'wildcard' | ||
}], | ||
from: 'tablename', | ||
group: ['name', 'surname'], | ||
where: { | ||
type: 'between', | ||
value: 'data', | ||
arguments: [{ | ||
value: 1, | ||
type: 'number' | ||
}, { | ||
value: 3, | ||
type: 'number' | ||
}] | ||
}, | ||
limit: 1, | ||
orderBy: [{ | ||
value: 'name', | ||
direction: null | ||
}] | ||
}; | ||
// const obj = new Sql2json('select * from tablename where data between 1 and 3 group by name, surname order by name limit 1'); | ||
// const json = obj.toJSON(); | ||
// json.should.deepEqual(response); | ||
// }); | ||
// }); | ||
const obj = new Sql2json('select * from tablename where data between 1 and 3 group by name, surname order by name limit 1'); | ||
const json = obj.toJSON(); | ||
json.should.deepEqual(response); | ||
}); | ||
}); | ||
}); |
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
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
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
72921
2065
1
- Removedsql-parser@0.5.0(transitive)
Updatedsql-parser@git+http://github.com/rrequero/sql-parser.git#master