forked from brianc/node-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
63 lines (54 loc) · 1.59 KB
/
functions.js
File metadata and controls
63 lines (54 loc) · 1.59 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
var _ = require('lodash');
var sliced = require('sliced');
var FunctionCall = require(__dirname + '/node/functionCall');
// create a function that creates a function call of the specific name, using the specified sql instance
var getFunctionCallCreator = function(name) {
return function() {
// turn array-like arguments object into a true array
return new FunctionCall(name, sliced(arguments));
};
};
// creates a hash of functions for a sql instance
var getFunctions = function(functionNames) {
var functions = _.reduce(functionNames, function(reducer, name) {
reducer[name] = getFunctionCallCreator(name);
return reducer;
}, {});
return functions;
};
// aggregate functions available to all databases
var aggregateFunctions = [
'AVG',
'COUNT',
'DISTINCT',
'MAX',
'MIN',
'SUM'
];
// common scalar functions available to most databases
var scalarFunctions = [
'ABS',
'COALESCE',
'LEFT',
'LENGTH',
'LOWER',
'LTRIM',
'RANDOM',
'RIGHT',
'ROUND',
'RTRIM',
'SUBSTR',
'TRIM',
'UPPER'
];
// hstore function available to Postgres
var hstoreFunction = 'HSTORE';
//text search functions available to Postgres
var textsearchFunctions = ['TS_RANK','TS_RANK_CD', 'PLAINTO_TSQUERY', 'TO_TSQUERY', 'TO_TSVECTOR', 'SETWEIGHT'];
var standardFunctionNames = aggregateFunctions.concat(scalarFunctions).concat(hstoreFunction).concat(textsearchFunctions);
// creates a hash of standard functions for a sql instance
var getStandardFunctions = function() {
return getFunctions(standardFunctionNames);
};
module.exports.getStandardFunctions = getStandardFunctions;