move parseConnectionString utility function into utils
This commit is contained in:
parent
5496f3199e
commit
4724444e3d
@ -1,27 +1,16 @@
|
||||
var sys = require('sys');
|
||||
var crypto = require('crypto');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var url = require('url');
|
||||
|
||||
var Query = require(__dirname + '/query');
|
||||
var utils = require(__dirname + '/utils');
|
||||
var defaults = require(__dirname + '/defaults');
|
||||
var Connection = require(__dirname + '/connection');
|
||||
|
||||
var parseConnectionString = function(str) {
|
||||
var result = url.parse(str);
|
||||
result.host = result.hostname;
|
||||
result.database = result.pathname ? result.pathname.slice(1) : null
|
||||
var auth = (result.auth || ':').split(':');
|
||||
result.user = auth[0];
|
||||
result.password = auth[1];
|
||||
return result;
|
||||
};
|
||||
|
||||
var Client = function(config) {
|
||||
EventEmitter.call(this);
|
||||
if(typeof config === 'string') {
|
||||
config = parseConnectionString(config)
|
||||
config = utils.parseConnectionString(config)
|
||||
}
|
||||
config = config || {};
|
||||
this.user = config.user || defaults.user;
|
||||
|
12
lib/utils.js
12
lib/utils.js
@ -1,3 +1,4 @@
|
||||
var url = require('url');
|
||||
var events = require('events');
|
||||
var sys = require('sys');
|
||||
|
||||
@ -75,5 +76,14 @@ p._pulse = function(item, cb) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Pool: Pool
|
||||
Pool: Pool,
|
||||
parseConnectionString: function(str) {
|
||||
var result = url.parse(str);
|
||||
result.host = result.hostname;
|
||||
result.database = result.pathname ? result.pathname.slice(1) : null
|
||||
var auth = (result.auth || ':').split(':');
|
||||
result.user = auth[0];
|
||||
result.password = auth[1];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user