Skip to content

Commit 63a8f99

Browse files
committed
Function calls don't need the sql instance.
1 parent 761ebd4 commit 63a8f99

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

lib/functions.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ var sliced = require('sliced');
44
var FunctionCall = require(__dirname + '/node/functionCall');
55

66
// create a function that creates a function call of the specific name, using the specified sql instance
7-
var getFunctionCallCreator = function(name, sql) {
7+
var getFunctionCallCreator = function(name) {
88
return function() {
99
// turn array-like arguments object into a true array
10-
var functionCall = new FunctionCall(name, sliced(arguments));
11-
functionCall.sql = sql;
12-
return functionCall;
10+
return new FunctionCall(name, sliced(arguments));
1311
};
1412
};
1513

1614
// creates a hash of functions for a sql instance
17-
var getFunctions = function(functionNames, sql) {
15+
var getFunctions = function(functionNames) {
1816
var functions = _.reduce(functionNames, function(reducer, name) {
19-
reducer[name] = getFunctionCallCreator(name, sql);
17+
reducer[name] = getFunctionCallCreator(name);
2018
return reducer;
2119
}, {});
2220
return functions;
@@ -56,8 +54,8 @@ var textsearchFunctions = ['TS_RANK','TS_RANK_CD', 'PLAINTO_TSQUERY', 'TO_TSQUER
5654
var standardFunctionNames = aggregateFunctions.concat(scalarFunctions).concat(hstoreFunction).concat(textsearchFunctions);
5755

5856
// creates a hash of standard functions for a sql instance
59-
var getStandardFunctions = function(sql) {
60-
return getFunctions(standardFunctionNames, sql);
57+
var getStandardFunctions = function() {
58+
return getFunctions(standardFunctionNames);
6159
};
6260

6361
module.exports.getStandardFunctions = getStandardFunctions;

lib/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var Sql = function(dialect) {
1616
this.setDialect(dialect || DEFAULT_DIALECT);
1717

1818
// attach the standard SQL functions to this instance
19-
this.functions = functions.getStandardFunctions(this);
19+
this.functions = functions.getStandardFunctions();
2020
};
2121

2222
// Define a table
@@ -30,11 +30,8 @@ Sql.prototype.define = function(def) {
3030

3131
// Returns a function call creator
3232
Sql.prototype.functionCallCreator = function(name) {
33-
var sql = this;
3433
return function() {
35-
var functionCall = new FunctionCall(name, sliced(arguments));
36-
functionCall.sql = sql;
37-
return functionCall;
34+
return new FunctionCall(name, sliced(arguments));
3835
};
3936
};
4037

0 commit comments

Comments
 (0)