forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.js
More file actions
25 lines (22 loc) · 613 Bytes
/
Copy pathfunc.js
File metadata and controls
25 lines (22 loc) · 613 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
import { exprToSQL } from './expr'
function castToSQL(expr) {
const str = expr.target.length ? `(${expr.target.length})` : ''
let prefix = exprToSQL(expr.expr)
let symbol = '::'
let suffix = ''
if (expr.symbol === 'as') {
prefix = `CAST(${prefix}`
suffix = ')'
symbol = ` ${expr.symbol.toUpperCase()} `
}
return `${prefix}${symbol}${expr.target.dataType}${str}${suffix}`
}
function funcToSQL(expr) {
if (!expr.args) return expr.name
const str = `${expr.name}(${exprToSQL(expr.args).join(', ')})`
return expr.parentheses ? `(${str})` : str
}
export {
castToSQL,
funcToSQL,
}