Fix Unix domain socket setting.

This code was misconceived in that the host parameter for a Unix
domain socket connection must point to the directory containing
the socket, and not to the socket itself. Libpq will look for
the socket based on the host and port settings. See
<http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS>
This commit is contained in:
Andrew Dunstan 2013-02-23 11:11:44 -05:00
parent 69b417171b
commit ed015f9b58
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/");
}));
});