Skip to content

Commit 6e33b93

Browse files
author
Sadman Sakib Hasan
authored
Merge pull request #186 from gregdingle/fix-pg-pool-settings
Fix bug where settings for pg-pool were dropped
2 parents 679fb05 + fbe3edf commit 6e33b93

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

lib/postgresql.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ function PostgreSQL(postgresql, settings) {
7272
// this._models = {};
7373
// this.settings = settings;
7474
this.constructor.super_.call(this, 'postgresql', settings);
75+
this.clientConfig = settings;
7576
if (settings.url) {
7677
// pg-pool doesn't handle string config correctly
77-
this.clientConfig = {
78-
connectionString: settings.url,
79-
};
80-
} else {
81-
this.clientConfig = settings;
78+
this.clientConfig.connectionString = settings.url;
8279
}
8380
this.clientConfig.Promise = Promise;
8481
this.pg = new postgresql.Pool(this.clientConfig);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright IBM Corp. 2015. All Rights Reserved.
2+
// Node module: loopback-connector-postgresql
3+
// This file is licensed under the Artistic License 2.0.
4+
// License text available at https://opensource.org/licenses/Artistic-2.0
5+
6+
'use strict';
7+
require('./init');
8+
9+
var connector = require('..');
10+
var DataSource = require('loopback-datasource-juggler').DataSource;
11+
var should = require('should');
12+
13+
// simple wrapper that uses JSON.parse(JSON.stringify()) as cheap clone
14+
function newConfig(withURL) {
15+
return JSON.parse(JSON.stringify(getDBConfig(withURL)));
16+
}
17+
18+
describe('initialization', function() {
19+
it('honours user-defined pg-pool settings', function() {
20+
var dataSource = new DataSource(connector, newConfig());
21+
var pool = dataSource.connector.pg.pool;
22+
pool._factory.max.should.not.equal(999);
23+
24+
var settings = newConfig();
25+
settings.max = 999; // non-default value
26+
var dataSource = new DataSource(connector, settings);
27+
var pool = dataSource.connector.pg.pool;
28+
pool._factory.max.should.equal(999);
29+
});
30+
31+
it('honours user-defined url settings', function() {
32+
var settings = newConfig();
33+
34+
var dataSource = new DataSource(connector, settings);
35+
var clientConfig = dataSource.connector.clientConfig;
36+
should.not.exist(clientConfig.connectionString);
37+
38+
settings = newConfig(true);
39+
var dataSource = new DataSource(connector, settings);
40+
var clientConfig = dataSource.connector.clientConfig;
41+
clientConfig.connectionString.should.equal(settings.url);
42+
});
43+
44+
it('honours multiple user-defined settings', function() {
45+
var urlOnly = {url: newConfig(true).url, max: 999};
46+
47+
var dataSource = new DataSource(connector, urlOnly);
48+
var pool = dataSource.connector.pg.pool;
49+
pool._factory.max.should.equal(999);
50+
51+
var clientConfig = dataSource.connector.clientConfig;
52+
clientConfig.connectionString.should.equal(urlOnly.url);
53+
});
54+
});

0 commit comments

Comments
 (0)