forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.js
More file actions
36 lines (32 loc) · 954 Bytes
/
comment.js
File metadata and controls
36 lines (32 loc) · 954 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
36
import { columnRefToSQL } from './column'
import { hasVal, identifierToSql, literalToSQL, toUpper } from './util'
function commentOptionToSQL(stmt) {
const { name, type } = stmt
switch (type) {
case 'table':
case 'view':
const fullTableName = [identifierToSql(name.db), identifierToSql(name.table)].filter(hasVal).join('.')
return `${toUpper(type)} ${fullTableName}`
case 'column':
return `COLUMN ${columnRefToSQL(name)}`
default:
return `${toUpper(type)} ${literalToSQL(name)}`
}
}
function commentIsExprToSQL(stmt) {
const { keyword, expr } = stmt
return [toUpper(keyword), literalToSQL(expr)].filter(hasVal).join(' ')
}
function commentOnToSQL(stmt) {
const { expr, keyword, target, type } = stmt
const result = [
toUpper(type),
toUpper(keyword),
commentOptionToSQL(target),
commentIsExprToSQL(expr),
]
return result.filter(hasVal).join(' ')
}
export {
commentOnToSQL,
}