Skip to content

Commit d525528

Browse files
committed
Merge pull request brianc#370 from badave/master
Makes client_encoding configurable and optional
2 parents bbf9459 + 6fea797 commit d525528

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/connection-parameters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var ConnectionParameters = function(config) {
3838
this.password = val('password', config);
3939
this.binary = val('binary', config);
4040
this.ssl = config.ssl || defaults.ssl;
41+
this.client_encoding = val("client_encoding", config);
4142
//a domain socket begins with '/'
4243
this.isDomainSocket = (!(this.host||'').indexOf('/'));
4344
};
@@ -61,7 +62,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
6162
params.push("host=" + this.host);
6263
return cb(null, params.join(' '));
6364
}
64-
params.push("client_encoding='utf-8'");
65+
if(this.client_encoding) {
66+
params.push("client_encoding='" + this.client_encoding + "'");
67+
}
6568
dns.lookup(this.host, function(err, address) {
6669
if(err) return cb(err, null);
6770
params.push("hostaddr=" + address);

lib/defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ module.exports = {
3131
reapIntervalMillis: 1000,
3232

3333
//pool log function / boolean
34-
poolLog: false
34+
poolLog: false,
35+
36+
client_encoding: ""
3537
};

test/unit/connection-parameters/creation-tests.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ test('libpq connection string building', function() {
124124
}));
125125
});
126126

127+
test("encoding can be specified by config", function() {
128+
var config = {
129+
client_encoding: "utf-8"
130+
}
131+
var subject = new ConnectionParameters(config);
132+
subject.getLibpqConnectionString(assert.calls(function(err, constring) {
133+
assert.isNull(err);
134+
var parts = constring.split(" ");
135+
checkForPart(parts, "client_encoding='utf-8'");
136+
}));
137+
})
138+
127139
test('password contains < and/or > characters', function () {
128140
return false;
129141
var sourceConfig = {

0 commit comments

Comments
 (0)