Skip to content

Commit

Permalink
Merge pull request #615 from iceddev/master
Browse files Browse the repository at this point in the history
switch to pg-connection-string module for parsing
  • Loading branch information
brianc committed Jul 6, 2014
2 parents 732e720 + 54271a2 commit ec81ff1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
42 changes: 1 addition & 41 deletions lib/connection-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit ec81ff1

Please sign in to comment.