-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsort.js
More file actions
19 lines (16 loc) · 670 Bytes
/
sort.js
File metadata and controls
19 lines (16 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var util = require('./util.js')
var convertField = function (fieldName, field, orderingType, forceNumericSort) {
const dir = (orderingType === 1 ? 'ASC NULLS FIRST' : 'DESC NULLS LAST')
const value = util.pathToText([fieldName].concat(field.split('.')), forceNumericSort)
if (forceNumericSort) {
return `cast(${value} as double precision) ${dir}`
}
return `${value} ${dir}`
}
var convert = function (fieldName, sortParams, forceNumericSort) {
const orderings = Object.keys(sortParams).map(function(key) {
return convertField(fieldName, key, sortParams[key], forceNumericSort || false)
})
return orderings.join(', ')
}
module.exports = convert