move parseConnectionString utility function into utils

This commit is contained in:
brianc 2011-02-04 20:06:52 -06:00
parent 5496f3199e
commit 4724444e3d
2 changed files with 12 additions and 13 deletions

View File

@ -1,27 +1,16 @@
var sys = require('sys'); var sys = require('sys');
var crypto = require('crypto'); var crypto = require('crypto');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var url = require('url');
var Query = require(__dirname + '/query'); var Query = require(__dirname + '/query');
var utils = require(__dirname + '/utils'); var utils = require(__dirname + '/utils');
var defaults = require(__dirname + '/defaults'); var defaults = require(__dirname + '/defaults');
var Connection = require(__dirname + '/connection'); 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) { var Client = function(config) {
EventEmitter.call(this); EventEmitter.call(this);
if(typeof config === 'string') { if(typeof config === 'string') {
config = parseConnectionString(config) config = utils.parseConnectionString(config)
} }
config = config || {}; config = config || {};
this.user = config.user || defaults.user; this.user = config.user || defaults.user;

View File

@ -1,3 +1,4 @@
var url = require('url');
var events = require('events'); var events = require('events');
var sys = require('sys'); var sys = require('sys');
@ -75,5 +76,14 @@ p._pulse = function(item, cb) {
} }
module.exports = { 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;
}
} }