Merge pull request #281 from adunstan/unix-domain-socket

Fix Unix domain socket setting. closes #277
This commit is contained in:
Brian C 2013-02-23 14:46:27 -08:00
commit 8ce808d0da
2 changed files with 2 additions and 23 deletions

View File

@ -58,7 +58,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
params.push("dbname='" + this.database + "'");
}
if(this.isDomainSocket) {
params.push("host=" + this.getDomainSocketName());
params.push("host=" + this.host);
return cb(null, params.join(' '));
}
params.push("options=--client_encoding='utf-8'");
@ -69,14 +69,4 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
});
};
ConnectionParameters.prototype.getDomainSocketName = function() {
var filename = '.s.PGSQL.' + this.port;
//if host is full path to socket fd with port number, just return it
if(this.host.indexOf(filename) > -1) return this.host;
//otherwise, build it from host + standard filename + port
return path.join(this.host, filename);
};
module.exports = ConnectionParameters;

View File

@ -53,17 +53,6 @@ test('initializing with unix domain socket', function() {
assert.equal(subject.host, '/var/run/');
});
test('builds domain socket', function() {
var subject = new ConnectionParameters({
host: '/var/run/',
port: 1234
});
assert.equal(subject.getDomainSocketName(), '/var/run/.s.PGSQL.1234');
subject.host = '/tmp';
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
assert.equal(subject.getDomainSocketName(), '/tmp/.s.PGSQL.1234');
});
test('libpq connection string building', function() {
var checkForPart = function(array, part) {
assert.ok(array.indexOf(part) > -1, array.join(" ") + " did not contain " + part);
@ -131,7 +120,7 @@ test('libpq connection string building', function() {
assert.isNull(err);
var parts = constring.split(" ");
checkForPart(parts, "user='brian'");
checkForPart(parts, "host=/tmp/.s.PGSQL.5432");
checkForPart(parts, "host=/tmp/");
}));
});