Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-parse

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-parse - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

2

lib/parsers/select.js

@@ -262,3 +262,3 @@ var Lexter = require('../lexter.js');

var parts = Tool.pickUp(tokens,"and");
var parts = Tool.pickUp(tokens,["and", "or"]);

@@ -265,0 +265,0 @@ parts[0].shift();

@@ -82,7 +82,8 @@ var Lexter = require('./lexter.js');

* @param {String} tokens
* @param {String} sep
* @param {String | Array} sep
* @return {Array}
*/
function pickUp(tokens, sep){
tokens.push({text:sep});
var separators = (Array.isArray(sep) ? sep : [sep]);
tokens.push({text:separators[0]});
var res = [];

@@ -92,15 +93,7 @@ var pre = 0;

for(var i = 0;i < tokens.length; i++){
if(tokens[i].text === "("){
lev++;
tokens.splice(i, 1)
}
if(tokens[i].text === ")"){
lev--;
tokens.splice(i, 1)
}
if(new RegExp("^"+sep+"$","i").test(tokens[i].text) && lev === 0){
if(tokens[i].text === "("){lev++;}
if(tokens[i].text === ")"){lev--;}
for (var x=0;x<separators.length;x++)
if(new RegExp("^"+separators[x]+"$","i").test(tokens[i].text) && lev === 0){
var part = tokens.slice(pre,i);
//console.log('each part ------')
//console.log(tokens[i].text)
//console.log(part)
if(part.length === 0){

@@ -120,2 +113,71 @@ pre = i + 1;

/**
* PickUp realization for WHERE clause
* @param {Array} tokens
*/
function parseDeepWhere(tokens) {
var result = detectLev(tokens);
// need transformations
// .......................
return result;
}
/**
* Recursive parse WHERE
* @param {Array} tokens
*/
function detectLev(tokens) {
if (!tokens) return;
// brackets
var open = '(';
var close = ')';
// result object
var result = [];
// temp obj
var current = tokens;
// find position of start br
while (current.indexOf(open) != -1) {
var andIndex = current.indexOf('and');
var orIndex = current.indexOf('or');
//console.log('got: ' + current);
var index = current.indexOf(open);
var j = index;
var all = 1;
while ((all != 0) && (j < current.length)) {
j++;
if (current[j] == open) all++;
if (current[j] == close) all--;
}
if (j == current.length) {
//console.log('error');
//console.log(current);
current = [];
break;
}
else {
// get a sub-array except brackets
var send = current.slice(index + 1, j);
//console.log('send: ' + send);
if ((andIndex != -1) && (orIndex))
result.push({
link: detectLev(send)
});
current = current.slice(j + 1);
if (current[0] == 'and' || current[0] == 'or') result.push({
token: current[0]
});
//console.log('current after slice: ' + current);
}
}
// if there are something without brackets
if (current.length > 0) {
result.push({
value: current
});
}
return result;
}
exports.parseDeepWhere = parseDeepWhere;
/**
* Hint

@@ -126,3 +188,3 @@ * @param {Array} part

*/
function getHint(part,pos){
function getHint(part, pos){
var hint = undefined;

@@ -129,0 +191,0 @@ if(part && part[pos] && part[pos].type === Lexter.types.COMMENT){

{
"name": "sql-parse",
"version": "0.1.4",
"version": "0.1.5",
"author": {

@@ -5,0 +5,0 @@ "name": "Andriy Ermolenko",

@@ -22,2 +22,6 @@ # sql-parse

## Updates
### v0.1.5
* implemented OR support for WHERE
## License

@@ -24,0 +28,0 @@ ### MIT

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