diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 91ad663c..9f44c8e9 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -38,6 +38,7 @@ var ConnectionParameters = function(config) { this.password = val('password', config); this.binary = val('binary', config); this.ssl = config.ssl || defaults.ssl; + this.client_encoding = val("client_encoding", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); }; @@ -61,7 +62,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { params.push("host=" + this.host); 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) { if(err) return cb(err, null); params.push("hostaddr=" + address); diff --git a/lib/defaults.js b/lib/defaults.js index 738908ee..d15a5b7b 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -31,5 +31,7 @@ module.exports = { reapIntervalMillis: 1000, //pool log function / boolean - poolLog: false + poolLog: false, + + client_encoding: "" }; diff --git a/test/unit/connection-parameters/creation-tests.js b/test/unit/connection-parameters/creation-tests.js index 6e73f7cd..90ec18a5 100644 --- a/test/unit/connection-parameters/creation-tests.js +++ b/test/unit/connection-parameters/creation-tests.js @@ -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 () { return false; var sourceConfig = {