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
24 lines (22 loc) · 638 Bytes
/
over.js
File metadata and controls
24 lines (22 loc) · 638 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
import { hasVal, toUpper } from './util'
import { orderOrPartitionByToSQL } from './expr'
import { asWindowSpecToSQL } from './window'
function overToSQL(over) {
if (!over) return
const {
as_window_specification: asWindowSpec,
orderby,
partitionby,
type,
} = over
if (toUpper(type) === 'WINDOW') {
const windowSQL = asWindowSpecToSQL(asWindowSpec)
return `OVER ${windowSQL}`
}
const partition = orderOrPartitionByToSQL(partitionby, 'partition by')
const order = orderOrPartitionByToSQL(orderby, 'order by')
return `OVER (${[partition, order].filter(hasVal).join(' ')})`
}
export {
overToSQL,
}