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.1 to 1.1.2

12

lib/sql2json.js

@@ -201,2 +201,14 @@ const lexer = require('sql-parser').lexer;

break;
case 'DBLSTRING':
stack.push({
value: `${token[1]}`,
type: 'string'
});
break;
case 'STRING':
stack.push({
value: token[1],
type: 'string'
});
break;
case 'OPERATOR':

@@ -203,0 +215,0 @@ operator = token[1];

2

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

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

@@ -669,2 +669,54 @@ const assert = require('assert');

it('With equality', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
where: {
type: 'operator',
left: {
value: 'country_iso',
type: 'literal'
},
value: '=',
right: {
value: 'BRA',
type: 'string'
}
}
};
const response = 'SELECT * FROM tablename WHERE country_iso = \'BRA\'';
Json2sql.toSQL(data).should.deepEqual(response);
});
it('With equality with single quotes', () => {
const data = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
where: {
type: 'operator',
left: {
value: 'country_iso',
type: 'literal'
},
value: '=',
right: {
value: 'BRA',
type: 'string'
}
}
};
const response = 'SELECT * FROM tablename WHERE country_iso = \'BRA\'';
Json2sql.toSQL(data).should.deepEqual(response);
});
});

@@ -671,0 +723,0 @@

@@ -559,6 +559,3 @@ const assert = require('assert');

});
describe('GroupBy', () => {
it('Group by one field', () => {
it('With equality', () => {
const response = {

@@ -571,6 +568,17 @@ select: [{

from: 'tablename',
group: ['name']
where: {
type: 'operator',
left: {
value: 'country_iso',
type: 'literal'
},
value: '=',
right: {
value: 'BRA',
type: 'string'
}
}
};
const obj = new Sql2json('select * from tablename group by name');
const obj = new Sql2json('select * from tablename where country_iso = "BRA"');
const json = obj.toJSON();

@@ -580,3 +588,3 @@ json.should.deepEqual(response);

it('Group by several fields', () => {
it('With equality', () => {
const response = {

@@ -589,191 +597,237 @@ select: [{

from: 'tablename',
group: ['name', 'surname']
};
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'
}]
type: 'operator',
left: {
value: 'country_iso',
type: 'literal'
},
value: '=',
right: {
value: 'BRA',
type: 'string'
}
}
};
const obj = new Sql2json('select * from tablename where data between 1 and 3 group by name, surname');
const obj = new Sql2json('select * from tablename where country_iso = \'BRA\'');
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('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 order 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('SQL with orderby and direction', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
orderBy: [{
value: 'name',
direction: 'asc'
}]
};
// 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 order by name asc');
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('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('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 order by name asc, createdAt desc');
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);
// });
// });
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
}]
};
// 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 asc, createdAt');
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);
// });
describe('Limit and offset', () => {
it('Limit', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
limit: 5
};
// 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 limit 5');
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('Offset', () => {
const response = {
select: [{
value: '*',
alias: null,
type: 'wildcard'
}],
from: 'tablename',
limit: 5,
offset: 10
};
// 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 limit 5 offset 10');
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);
// });
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
}]
};
// 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 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 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
// };
// 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
// };
// 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
// }]
// };
// 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