Completed
Push — master ( 3b3ae1...61dd3f )
by greg
01:50
created

src/cli/cms/data/abe-sql.js   A

Size

Lines of Code 537

Duplication

Duplicated Lines 30
Ratio 5.59 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 30
loc 537
rs 10
noi 28

1 Function

Rating   Name   Duplication   Size   Complexity  
A abe-sql.js ➔ ??? 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import {parse} from 'node-sqlparser'
2
import {Promise} from 'es6-promise'
3
import path from 'path'
4
import {
5
  config,
6
  Manager,
7
  FileParser,
8
  getAttr
9
} from '../../'
10
11
export default class Sql {
12
13
  constructor() {
14
15
  }
16
17
  static cleanRequest(str, jsonPage) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonPage is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
18
    var matchFrom = /from .(.*?) /
19
    var matchVariable = /{{([a-zA-Z]*)}}/
20
21
    var matchFromExec = matchFrom.exec(str)
22
    if(typeof matchFromExec !== 'undefined' && matchFromExec !== null
23
      && typeof matchFromExec[1] !== 'undefined' && matchFromExec[1] !== null) {
24
25
      var fromMatch
26
      var toReplace = matchFromExec[1]
27
      while (fromMatch = matchVariable.exec(toReplace)) {
28
        try {
29
          var value = eval('jsonPage.' + fromMatch[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
30
          if(typeof value !== 'undefined' && value !== null) {
31
            toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', value)
32
          }else {
33
            toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', '')
34
          }
35
        }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
36
        }
37
      }
38
39
      str = str.replace(matchFromExec[1], toReplace)
40
    }
41
42
    var from = /from ([\S\s]+)/.exec(str)
43
44
    var matches = from
45
    if(matches[1]) {
46
      var res = matches[1]
47
      var splitAttr = [' where ', ' order by ', ' limit ', ' WHERE ', ' ORDER BY ', ' LIMIT ']
48
      for(var i = 0; i < splitAttr.length; i++) {
49
        if(res.indexOf(splitAttr[i]) > -1) {
50
          res = res.substring(0, res.indexOf(splitAttr[i]))
51
        }
52
      }
53
      var escapedFrom = res.replace(/\//g, '___abe___')
54
      escapedFrom = escapedFrom.replace(/\./g, '___abe_dot___')
55
      escapedFrom = escapedFrom.replace(/-/g, '___abe_dash___')
56
      str = str.replace(res, escapedFrom)
57
    }
58
59
    str = str.replace(/``/g, '\'\'')
60
61
    return str
62
  }
63
64
  static handleSqlRequest(str, jsonPage) {
65
    var cleanRequest = Sql.cleanRequest(str, jsonPage)
66
    var request = parse(cleanRequest)
67
    var reconstructSql = ''
68
69
    // SQL TYPE
70
    var type = ''
71
    if(typeof request.type !== 'undefined' && request.type !== null) {
72
      type = request.type
73
    }
74
    reconstructSql += `${type} `
75
76
    // SQL COLUMNS
77
    var columns = []
78
    if(typeof request.columns !== 'undefined' && request.columns !== null) {
79
      if(request.columns === '*') {
80
        columns.push('*')
81
      }else {
82
        Array.prototype.forEach.call(request.columns, (item) => {
83
          columns.push(item.expr.column)
84
        })
85
      }
86
    }
87
    reconstructSql += `${JSON.stringify(columns)} `
88
89
    // SQL FROM
90
    var from = []
91
    if(typeof request.from !== 'undefined' && request.from !== null) {
92
93
      Array.prototype.forEach.call(request.from, (item) => {
94
        from.push(item.table)
95
      })
96
    }else {
97
      from.push('*')
98
    }
99
    reconstructSql += `from ${JSON.stringify(from)} `
100
101
    var where
102
    if(typeof request.where !== 'undefined' && request.where !== null) {
103
      where = request.where
104
      // where = Sql.recurseWhere(request.where)
105
      // reconstructSql += 'where '
106
      // Array.prototype.forEach.call(where, (w) => {
107
      //   reconstructSql += `${w.operator} ${w.left} ${w.compare} ${w.right} `
108
      // })
109
    }
110
111
    var limit = -1
112
    if(typeof request.limit !== 'undefined' && request.limit !== null) {
113
      limit = request.limit[request.limit.length - 1].value
114
    }
115
116
    var orderby
117
    if(typeof request.orderby !== 'undefined' && request.orderby !== null && request.orderby.length > 0) {
118
      orderby = {
119
        column: request.orderby[0].expr.column,
120
        type: request.orderby[0].type
121
      }
122
      reconstructSql += `ORDER BY ${orderby.column} ${orderby.type} `
123
    }
124
125
    return {
126
      type: type,
127
      columns: columns,
128
      from: from,
129
      where: where,
0 ignored issues
show
Bug introduced by
The variable where does not seem to be initialized in case typeof request.where !=... request.where !== null on line 102 is false. Are you sure this can never be the case?
Loading history...
130
      string: reconstructSql,
131
      limit: limit,
132
      orderby: orderby
0 ignored issues
show
Bug introduced by
The variable orderby does not seem to be initialized in case typeof request.orderby ...uest.orderby.length > 0 on line 117 is false. Are you sure this can never be the case?
Loading history...
133
    }
134
  }
135
136
  static sortByDateDesc(a, b) {
137
    var dateA = new Date(a.date)
138
    var dateB = new Date(b.date)
139
    if(dateA < dateB) {
140
      return 1
141
    }else if(dateA > dateB) {
142
      return -1
143
    }
144
    return 0
145
  }
146
147
  static shuffle(array) {
148
    var currentIndex = array.length, temporaryValue, randomIndex
149
150
    // While there remain elements to shuffle...
151
    while (0 !== currentIndex) {
152
153
      // Pick a remaining element...
154
      randomIndex = Math.floor(Math.random() * currentIndex)
155
      currentIndex -= 1
156
157
      // And swap it with the current element.
158
      temporaryValue = array[currentIndex]
159
      array[currentIndex] = array[randomIndex]
160
      array[randomIndex] = temporaryValue
161
    }
162
163
    return array
164
  }
165
166
  static sortByDateAsc(a, b) {
167
    var dateA = new Date(a.date)
168
    var dateB = new Date(b.date)
169
    if(dateA > dateB) {
170
      return 1
171
    }else if(dateA < dateB) {
172
      return -1
173
    }
174
    return 0
175
  }
176
177
  static getDataSource(str) {
178
    var res = str.substring(str.indexOf('source=') + 8, str.length)
179
180
    var reg = /([^'"]*=[\s\S]*?}})/g
181
    var matches = res.match(reg)
182
    if(typeof matches !== 'undefined' && matches !== null) {
183
      Array.prototype.forEach.call(matches, (match) => {
184
        res = res.replace(match, '')
185
      })
186
    }else {
187
      res = res.replace('}}', '')
188
    }
189
190
    return res.substring(0, res.length-1)
191
  }
192
193
  /**
194
   * replaces escaped characters with the right ones
195
   * @param  {String} statement the from clause
196
   * @return {String}           the from sanitized
197
   */
198
  static sanitizeFromStatement(statement){
199
    var from = ''
200
201
    if(typeof statement !== 'undefined' && statement !== null) {
202
      from = statement[0].replace(/___abe_dot___/g, '.')
203
      from = from.replace(/___abe___/g, '/')
204
      from = from.replace(/___abe_dash___/g, '-')
205
    }
206
207
    return from
208
  }
209
210
  /**
211
   * calculate the directory to analyze from the from clause
212
   * @param  {String} statement the from clause
213
   * @param  {String} tplPath   the path from the template originator
214
   * @return {string}           the directory to analyze
215
   */
216
  static getFromDirectory(statement, tplPath){
217
    var pathFromDir = ''
218
    if(typeof tplPath === 'undefined' || tplPath === null || tplPath === ''){
219
      tplPath = '/'
220
    }
221
222
    if(statement === '' || statement === '*' || statement === '/') {
223
      pathFromDir = path.join(config.root, config.data.url)
224
    }else if(statement === './') {
225
      pathFromDir = path.join(config.root, config.data.url, tplPath)
226
    }else if(statement.indexOf('/') === 0) {
227
      pathFromDir = path.join(config.root, config.data.url, statement)
228
    }else if(statement.indexOf('/') !== 0) {
229
      pathFromDir = path.join(config.root, config.data.url, tplPath, statement)
230
    }
231
232
    return pathFromDir
233
  }
234
235
  static executeOrderByClause(files, orderby){
236
    if(typeof orderby !== 'undefined' && orderby !== null) {
237
      if(orderby.column.toLowerCase() === 'random') {
238
        Sql.shuffle(files)
239
      }else if(orderby.column.toLowerCase() === 'date') {
240
        if(orderby.type === 'ASC') {
241
          files.sort(Sql.sortByDateAsc)
242
        }else if(orderby.type === 'DESC') {
243
          files.sort(Sql.sortByDateDesc)
244
        }
245
      }
246
    }
247
248
    return files
249
  }
250
251
  static executeFromClause(statement, pathFromClause){
252
    var from = Sql.sanitizeFromStatement(statement)
253
254
    // if the from clause ends with a dot, we won't recurse the directory analyze
255
    if(from.slice(-1) === '.'){
256
      from = from.slice(0, -1)
257
    }
258
    
259
    var fromDirectory = Sql.getFromDirectory(from, pathFromClause)
260
261
    var list = Manager.instance.getList()
262
    var files_array = list.filter((element, index) => {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
263
      if(element.publish) {
264
        if (element.path.indexOf(fromDirectory) > -1) {
265
          return true
266
        }
267
      }
268
      return false
269
    })
270
    return files_array
271
  }
272
273
  static execQuery(pathQuery, match, jsonPage) {
274
    var res
275
    var files
276
    var request = Sql.handleSqlRequest(getAttr(match, 'source'), jsonPage)
277
278
    files = Sql.executeFromClause(request.from, pathQuery)
279
    files = Sql.executeOrderByClause(files, request.orderby)
280
    res = Sql.executeWhereClause(files, request.where, request.limit, request.columns, jsonPage)
281
282
    return res
283
  }
284
285
  static executeQuerySync(pathQuerySync, match, jsonPage) {
286
    return Sql.execQuery(pathQuerySync, match, jsonPage)
287
  }
288
289
  static executeQuery(pathexecuteQuery, match, jsonPage) {
290
    var p = new Promise((resolve) => {
291
      var res = Sql.execQuery(pathexecuteQuery, match, jsonPage)
292
      resolve(res)
293
    }).catch(function(e) {
294
      console.error(e)
295
    })
296
297
    return p
298
  }
299
300
  /**
301
   * check if a given string an url, string json, file url, abe sql request
302
   * 
303
   * Sql.get('http://google.com')
304
   * Sql.get('{"test":"test"}')
305
   * Sql.get('select * from ../')
306
   * Sql.get('test')
307
   * 
308
   * @param  {String} str 
309
   * @return {String} url | request | value | file | other
310
   */
311
  static getSourceType(str) {
312
    if(/http:\/\/|https:\/\//.test(str)) {
313
      return 'url'
314
    }
315
316
    if(/select[\S\s]*?from/.test(str)) {
317
      return 'request'
318
    }
319
320
    try {
321
      JSON.parse(str)
322
      return 'value'
323
    }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
324
325
    }
326
327
    if(/\.json/.test(str)) {
328
      return 'file'
329
    }
330
331
    return 'other'
332
  }
333
334
  static executeWhereClause(files, wheres, maxLimit, columns, jsonPage){
335
    var res = []
336
    var limit = 0
337
338
    for(let file of files) {
339
      if(limit < maxLimit || maxLimit === -1) {
340
        if(typeof wheres !== 'undefined' && wheres !== null) {
341
342
          if(Sql.recurseWhere(wheres, file.publish, jsonPage)) {
343
            var json = JSON.parse(JSON.stringify(file.publish))
344
            var jsonValues = {}
345
346
            if(typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {
347
              
348
              Array.prototype.forEach.call(columns, (column) => {
349
                if(typeof json[column] !== 'undefined' && json[column] !== null) {
0 ignored issues
show
Bug introduced by
The variable json is changed as part of the for-each loop for example by JSON.parse(JSON.stringify(file.publish)) on line 343. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
350
                  jsonValues[column] = json[column]
0 ignored issues
show
Bug introduced by
The variable jsonValues is changed as part of the for-each loop for example by {} on line 344. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
351
                }
352
              })
353
              jsonValues['abe_meta'] = json['abe_meta']
354
            }else {
355
              jsonValues = json
356
            }
357
358
            res.push(jsonValues)
359
            limit++
360
          }
361
        }
362
      } else {
363
        break
364
      }
365
    }
366
367
    return res
368
  }
369
370 View Code Duplication
  static whereEquals(where, value, compare) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
371
    var shouldAdd = true
372
    if(where === 'template' || where === 'abe_meta.template') {
373
      if(value && value.indexOf('/') > -1 && value !== compare) {
374
        shouldAdd = false
375
      }else if(value && value.indexOf('/') === -1 && compare && compare.indexOf(value) === -1) {
376
        shouldAdd = false
377
      }
378
    }else {
379
      if(value !== compare) { // only none is Array
380
        shouldAdd = false
381
      }
382
    }
383
    return shouldAdd
384
  }
385
386 View Code Duplication
  static whereNotEquals(where, value, compare, json) {
0 ignored issues
show
Unused Code introduced by
The parameter json is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
387
    var shouldAdd = true
388
    if(where.left === 'template' || where.left === 'abe_meta.template') {
389
      if (value && value.indexOf('/') > -1 && value === compare) { 
390
        shouldAdd = false 
391
      } else if (value && value.indexOf('/') === -1 && compare && compare.indexOf(value) !== -1) { 
392
        shouldAdd = false
393
      }
394
    }else {
395
      if(value === compare) { // only none is Array
396
        shouldAdd = false
397
      }
398
    }
399
    return shouldAdd
400
  }
401
402
  static whereLike(where, value, compare, json) {
0 ignored issues
show
Unused Code introduced by
The parameter json is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
403
    var shouldAdd = true
404
    if(where.left === 'template' || where.left === 'abe_meta.template') {
405
      if(value && value.indexOf(compare) === -1) {
406
        shouldAdd = false
407
      }
408
    }else {
409
      if(value && value.indexOf(compare) === -1) {
410
        shouldAdd = false
411
      }
412
    }
413
    return shouldAdd
414
  }
415
416
  static whereNotLike(where, value, compare, json) {
0 ignored issues
show
Unused Code introduced by
The parameter json is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
417
    var shouldAdd = true
418
    if(where.left === 'template' || where.left === 'abe_meta.template') {
419
      if(value && value.indexOf(compare) >= -1) {
420
        shouldAdd = false
421
      }
422
    }else {
423
      if(value && value.indexOf(compare) > -1) {
424
        shouldAdd = false
425
      }
426
    }
427
    return shouldAdd
428
  }
429
430
  static getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonOriginalDoc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
431
    var value
432
    var compare
433
434
    if((where.left.column === 'template' || where.left.column === 'abe_meta.template')
435
      && typeof jsonDoc['abe_meta'] !== 'undefined' && jsonDoc['abe_meta'] !== null) {
436
      value = FileParser.getTemplate(jsonDoc['abe_meta'].template)
437
    }else {
438
      try {
439
        value = eval('jsonDoc.' + where.left.column)
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
440
      }catch(e) {
441
        // console.log('e', e)
442
      }
443
    }
444
    compare = where.right.column
445
446
    var matchVariable = /^{{(.*)}}$/.exec(compare)
447
    if(typeof matchVariable !== 'undefined' && matchVariable !== null && matchVariable.length > 0) {
448
      try {
449
        var shouldCompare = eval('jsonOriginalDoc.' + matchVariable[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
450
        if(typeof shouldCompare !== 'undefined' && shouldCompare !== null) {
451
          compare = shouldCompare
452
        }else {
453
          compare = null
454
        }
455
      }catch(e) {
456
        compare = null
457
        // console.log('e', e)
458
      }
459
    }
460
461
    return {
462
      left: value,
463
      right: compare
464
    }
465
  }
466
467
  static recurseWhere(where, jsonDoc, jsonOriginalDoc) {
468
    var shouldAdd = true
0 ignored issues
show
Unused Code introduced by
The variable shouldAdd seems to be never used. Consider removing it.
Loading history...
469
    var isLeftCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isLeftCorrect seems to be never used. Consider removing it.
Loading history...
470
    var isRightCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isRightCorrect seems to be never used. Consider removing it.
Loading history...
471
    var isCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isCorrect seems to be never used. Consider removing it.
Loading history...
472
473
    switch(where.operator) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
474
    case '=':
475
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
476
      isCorrect = Sql.whereEquals(where.left.column, values.left, values.right)
477
      break
478
    case '!=':
479
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
480
      isCorrect = Sql.whereNotEquals(where.left.column, values.left, values.right)
481
      break
482
    case '>':
483
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
484
      isCorrect = (values.left > values.right)
485
      break
486
    case '>=':
487
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
488
      isCorrect = (values.left >= values.right)
489
      break
490
    case '<':
491
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
492
      isCorrect = (values.left < values.right)
493
      break
494
    case '<=':
495
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
496
      isCorrect = (values.left <= values.right)
497
      break
498
    case 'LIKE':
499
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
500
      isCorrect = Sql.whereLike(where.left.column, values.left, values.right)
501
      break
502
    case 'NOT LIKE':
503
      var values = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 475. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
504
      isCorrect = Sql.whereNotLike(where.left.column, values.left, values.right)
505
      break
506
    case 'AND':
507
      isLeftCorrect = Sql.recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
508
      isRightCorrect = Sql.recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
509
      isCorrect = isLeftCorrect && isRightCorrect
510
      break
511
    case 'OR':
512
      isLeftCorrect = Sql.recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
513
      isRightCorrect = Sql.recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
514
      isCorrect = isLeftCorrect || isRightCorrect
515
      break
516
    case 'IN':
517
      var valuesLeft = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
518
      Array.prototype.forEach.call(where.right.value, (right) => {
519
        if (Sql.whereEquals(where.left.column, valuesLeft.left, right.column)) {
520
          isCorrect = true
521
        }
522
      })
523
      break
524
    case 'NOT IN':
525
      var valuesLeft = Sql.getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable valuesLeft already seems to be declared on line 517. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
526
      isCorrect = true
527
      Array.prototype.forEach.call(where.right.value, (right) => {
528
        if (Sql.whereEquals(where.left.column, valuesLeft.left, right.column)) {
529
          isCorrect = false
530
        }
531
      })
532
      break
533
    }
534
535
    return isCorrect
536
  }
537
}