Extract query config normalization into utils
This commit is contained in:
parent
102a069bd2
commit
5dae2b267f
11
lib/query.js
11
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;
|
||||
|
19
lib/utils.js
19
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user