Changing to client_encoding, adding test for creating a connection

This commit is contained in:
Dave 2013-06-06 12:16:36 -07:00
parent d69070529c
commit f658b31aed
2 changed files with 14 additions and 2 deletions

View File

@ -38,7 +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 = config.encoding || defaults.encoding;
this.client_encoding = config.client_encoding || defaults.client_encoding;
//a domain socket begins with '/'
this.isDomainSocket = (!(this.host||'').indexOf('/'));
};
@ -63,7 +63,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
return cb(null, params.join(' '));
}
if(this.client_encoding) {
params.push(this.client_encoding);
params.push("client_encoding='" + this.client_encoding + "'");
}
dns.lookup(this.host, function(err, address) {
if(err) return cb(err, null);

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 () {
return false;
var sourceConfig = {