-
-
Save hacker/4ffb8808a4b4a0947e9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 344be9be281fb45c850530f6284f8dfdb1043a85 | |
Author: Michael Krelin <[email protected]> | |
Date: Sun Aug 11 13:30:56 2013 +0200 | |
enable the use of postgresql://?service=something connection url | |
diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js | |
index d6c1a23..e4c75ed 100644 | |
--- a/lib/connection-parameters.js | |
+++ b/lib/connection-parameters.js | |
@@ -32,11 +32,14 @@ var parse = function(str) { | |
config.ssl = true; | |
} | |
+ if(result.query.service) config.service=result.query.service; | |
+ | |
return config; | |
}; | |
var ConnectionParameters = function(config) { | |
config = typeof config == 'string' ? parse(config) : (config || {}); | |
+ this.service = val('service', config); | |
this.user = val('user', config); | |
this.database = val('database', config); | |
this.port = parseInt(val('port', config), 10); | |
@@ -61,6 +64,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { | |
add(params, this, 'user'); | |
add(params, this, 'password'); | |
add(params, this, 'port'); | |
+ if(this.service) params.push("service='"+this.service+"'"); | |
if(this.database) { | |
params.push("dbname='" + this.database + "'"); | |
} | |
@@ -71,6 +75,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { | |
if(this.client_encoding) { | |
params.push("client_encoding='" + this.client_encoding + "'"); | |
} | |
+ if(!this.host) return cb(null,params.join(' ')); | |
dns.lookup(this.host, function(err, address) { | |
if(err) return cb(err, null); | |
params.push("hostaddr=" + address); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment