Support for defaults.connectionString (#910)
This commit is contained in:
parent
90600f2b47
commit
01e5d726da
@ -34,7 +34,13 @@ var useSsl = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var ConnectionParameters = function(config) {
|
var ConnectionParameters = function(config) {
|
||||||
|
//if a string is passed, it is a raw connection string so we parse it into a config
|
||||||
config = typeof config == 'string' ? parse(config) : (config || {});
|
config = typeof config == 'string' ? parse(config) : (config || {});
|
||||||
|
//if the config has a connectionString defined, parse IT into the config we use
|
||||||
|
//this will override other default values with what is stored in connectionString
|
||||||
|
if(config.connectionString) {
|
||||||
|
config = parse(config.connectionString);
|
||||||
|
}
|
||||||
this.user = val('user', config);
|
this.user = val('user', config);
|
||||||
this.database = val('database', config);
|
this.database = val('database', config);
|
||||||
this.port = parseInt(val('port', config), 10);
|
this.port = parseInt(val('port', config), 10);
|
||||||
|
@ -11,6 +11,11 @@ var defaults = module.exports = {
|
|||||||
//database user's password
|
//database user's password
|
||||||
password: null,
|
password: null,
|
||||||
|
|
||||||
|
// a Postgres connection string to be used instead of setting individual connection items
|
||||||
|
// NOTE: Setting this value will cause it to override any other value (such as database or user) defined
|
||||||
|
// in the defaults object.
|
||||||
|
connectionString : undefined,
|
||||||
|
|
||||||
//database port
|
//database port
|
||||||
port: 5432,
|
port: 5432,
|
||||||
|
|
||||||
|
@ -29,6 +29,25 @@ test('ConnectionParameters initializing from defaults', function() {
|
|||||||
assert.ok(subject.isDomainSocket === false);
|
assert.ok(subject.isDomainSocket === false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ConnectionParameters initializing from defaults with connectionString set', function() {
|
||||||
|
var config = {
|
||||||
|
user : 'brians-are-the-best',
|
||||||
|
database : 'scoobysnacks',
|
||||||
|
port : 7777,
|
||||||
|
password : 'mypassword',
|
||||||
|
host : 'foo.bar.net',
|
||||||
|
binary : defaults.binary
|
||||||
|
};
|
||||||
|
|
||||||
|
var original_value = defaults.connectionString;
|
||||||
|
// Just changing this here doesn't actually work because it's no longer in scope when viewed inside of
|
||||||
|
// of ConnectionParameters() so we have to pass in the defaults explicitly to test it
|
||||||
|
defaults.connectionString = 'postgres://brians-are-the-best:mypassword@foo.bar.net:7777/scoobysnacks';
|
||||||
|
var subject = new ConnectionParameters(defaults);
|
||||||
|
defaults.connectionString = original_value;
|
||||||
|
compare(subject, config, 'defaults-connectionString');
|
||||||
|
});
|
||||||
|
|
||||||
test('ConnectionParameters initializing from config', function() {
|
test('ConnectionParameters initializing from config', function() {
|
||||||
var config = {
|
var config = {
|
||||||
user: 'brian',
|
user: 'brian',
|
||||||
|
Loading…
Reference in New Issue
Block a user