diff --git a/lib/query.js b/lib/query.js index 6bdc1b07..21531190 100644 --- a/lib/query.js +++ b/lib/query.js @@ -9,16 +9,7 @@ var Query = function(config, values, callback) { // use of "new" optional if (!(this instanceof Query)) return new Query(config, values, callback); - //can take in strings or config objects - config = (typeof(config) == 'string') ? { text: config } : config; - if(values) { - if(typeof values === 'function') { - callback = values; - } else { - config.values = values; - } - } - config.callback = callback; + config = utils.normalizeQueryConfig(config, values, callback); this.text = config.text; this.values = config.values; diff --git a/lib/utils.js b/lib/utils.js index 1454af0d..57f9f484 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -105,6 +105,22 @@ var prepareValue = function(val) { return val === null ? null : val.toString(); } +function normalizeQueryConfig (config, values, callback) { + //can take in strings or config objects + config = (typeof(config) == 'string') ? { text: config } : config; + if(values) { + if(typeof values === 'function') { + config.callback = values; + } else { + config.values = values; + } + } + if (callback) { + config.callback = callback; + } + return config; +} + module.exports = { normalizeConnectionInfo: normalizeConnectionInfo, //only exported here to make testing of this method possible @@ -112,5 +128,6 @@ module.exports = { //each connection scenario in an integration test is impractical buildLibpqConnectionString: getLibpgConString, parseConnectionString: parseConnectionString, - prepareValue: prepareValue + prepareValue: prepareValue, + normalizeQueryConfig: normalizeQueryConfig }