Merge pull request #615 from iceddev/master

switch to pg-connection-string module for parsing
This commit is contained in:
Brian C 2014-07-06 19:42:32 -04:00
commit ec81ff1d12
2 changed files with 2 additions and 41 deletions

View File

@ -18,47 +18,7 @@ var val = function(key, config, envVar) {
};
//parses a connection string
var parse = function(str) {
var config;
//unix socket
if(str.charAt(0) === '/') {
config = str.split(' ');
return { host: config[0], database: config[1] };
}
// url parse expects spaces encoded as %20
if(/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
str = encodeURI(str).replace(/\%25(\d\d)/g, "%$1");
}
var result = url.parse(str, true);
config = {};
if (result.query.application_name) {
config.application_name = result.query.application_name;
}
if (result.query.fallback_application_name) {
config.fallback_application_name = result.query.fallback_application_name;
}
config.port = result.port;
if(result.protocol == 'socket:') {
config.host = decodeURI(result.pathname);
config.database = result.query.db;
config.client_encoding = result.query.encoding;
return config;
}
config.host = result.hostname;
config.database = result.pathname ? decodeURI(result.pathname.slice(1)) : null;
var auth = (result.auth || ':').split(':');
config.user = auth[0];
config.password = auth[1];
var ssl = result.query.ssl;
if (ssl === 'true' || ssl === '1') {
config.ssl = true;
}
return config;
};
var parse = require('pg-connection-string').parse;
var useSsl = function() {
switch(process.env.PGSSLMODE) {

View File

@ -23,6 +23,7 @@
"pgpass": "0.0.3",
"nan": "~0.6.0",
"packet-reader": "0.2.0",
"pg-connection-string": "0.1.1",
"pg-types": "1.3.0"
},
"devDependencies": {