forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathover.js
More file actions
21 lines (19 loc) · 653 Bytes
/
over.js
File metadata and controls
21 lines (19 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { toUpper } from './util'
import { exprToSQL } from './expr'
import { asWindowSpecToSQL } from './window'
function overToSQL(over) {
if (!over) return
const { as_window_specification: asWindowSpec, expr, keyword, type, parentheses } = over
const upperType = toUpper(type)
if (upperType === 'WINDOW') return `OVER ${asWindowSpecToSQL(asWindowSpec)}`
if (upperType === 'ON UPDATE') {
let onUpdate = `${toUpper(type)} ${toUpper(keyword)}`
const args = exprToSQL(expr) || []
if (parentheses) onUpdate = `${onUpdate}(${args.join(', ')})`
return onUpdate
}
throw new Error('unknown over type')
}
export {
overToSQL,
}