mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Merge pull request #281 from adunstan/unix-domain-socket
Fix Unix domain socket setting. closes #277
This commit is contained in:
commit
8ce808d0da
@ -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;
|
||||
|
||||
@ -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/");
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user