forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-struct.js
More file actions
35 lines (32 loc) · 908 Bytes
/
array-struct.js
File metadata and controls
35 lines (32 loc) · 908 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
32
33
34
35
import { columnsToSQL } from './column'
import { arrayStructTypeToSQL, hasVal, toUpper } from './util'
function arrayStructValueToSQL(expr) {
const {
array_path: arrayPath,
expr_list: exprList,
type,
} = expr
switch (toUpper(type)) {
case 'STRUCT':
return `(${columnsToSQL(exprList)})`
case 'ARRAY':
if (exprList) return `[${exprList.map(col => `(${columnsToSQL(col)})`).filter(hasVal).join(', ')}]`
return `[${columnsToSQL(arrayPath)}]`
default:
return ''
}
}
function arrayStructExprToSQL(expr) {
const { definition, keyword } = expr
const result = [toUpper(keyword)]
if (definition && typeof definition === 'object') {
result.length = 0
result.push(arrayStructTypeToSQL(definition))
}
result.push(arrayStructValueToSQL(expr))
return result.filter(hasVal).join('')
}
export {
arrayStructExprToSQL,
arrayStructValueToSQL,
}