Socket
Socket
Sign inDemoInstall

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.3 to 1.2.0

4

package.json
{
"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);
});
});
});
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