forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.js
More file actions
31 lines (29 loc) · 672 Bytes
/
binary.js
File metadata and controls
31 lines (29 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { exprToSQL } from './expr'
function binaryToSQL(expr) {
let { operator } = expr
let rstr = exprToSQL(expr.right)
let isBetween = false
if (Array.isArray(rstr)) {
switch (operator) {
case '=':
operator = 'IN'
break
case '!=':
operator = 'NOT IN'
break
case 'BETWEEN':
case 'NOT BETWEEN':
isBetween = true
rstr = `${rstr[0]} AND ${rstr[1]}`
break
default:
break
}
if (!isBetween) rstr = `(${rstr.join(', ')})`
}
const str = [exprToSQL(expr.left), operator, rstr].join(' ')
return expr.parentheses ? `(${str})` : str
}
export {
binaryToSQL,
}