Merge pull request #370 from badave/master

Makes client_encoding configurable and optional
This commit is contained in:
Brian C 2013-06-06 17:31:39 -07:00
commit d525528f4f
3 changed files with 19 additions and 2 deletions

View File

@ -38,6 +38,7 @@ var ConnectionParameters = function(config) {
this.password = val('password', config); this.password = val('password', config);
this.binary = val('binary', config); this.binary = val('binary', config);
this.ssl = config.ssl || defaults.ssl; this.ssl = config.ssl || defaults.ssl;
this.client_encoding = val("client_encoding", config);
//a domain socket begins with '/' //a domain socket begins with '/'
this.isDomainSocket = (!(this.host||'').indexOf('/')); this.isDomainSocket = (!(this.host||'').indexOf('/'));
}; };
@ -61,7 +62,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
params.push("host=" + this.host); params.push("host=" + this.host);
return cb(null, params.join(' ')); return cb(null, params.join(' '));
} }
params.push("client_encoding='utf-8'"); if(this.client_encoding) {
params.push("client_encoding='" + this.client_encoding + "'");
}
dns.lookup(this.host, function(err, address) { dns.lookup(this.host, function(err, address) {
if(err) return cb(err, null); if(err) return cb(err, null);
params.push("hostaddr=" + address); params.push("hostaddr=" + address);

View File

@ -31,5 +31,7 @@ module.exports = {
reapIntervalMillis: 1000, reapIntervalMillis: 1000,
//pool log function / boolean //pool log function / boolean
poolLog: false poolLog: false,
client_encoding: ""
}; };

View File

@ -124,6 +124,18 @@ test('libpq connection string building', function() {
})); }));
}); });
test("encoding can be specified by config", function() {
var config = {
client_encoding: "utf-8"
}
var subject = new ConnectionParameters(config);
subject.getLibpqConnectionString(assert.calls(function(err, constring) {
assert.isNull(err);
var parts = constring.split(" ");
checkForPart(parts, "client_encoding='utf-8'");
}));
})
test('password contains < and/or > characters', function () { test('password contains < and/or > characters', function () {
return false; return false;
var sourceConfig = { var sourceConfig = {