From 54edb6df68930644b7afa755a652fbead775d639 Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Mon, 31 Oct 2016 23:40:39 -0400 Subject: [PATCH 1/6] Update README with correct doc links, etc --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2d5a6c13..aad99d92 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ If you create a PostgreSQL data source using the data source generator as descri ## Creating a data source -Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application. +Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application. The generator will prompt for the database server hostname, port, and other settings required to connect to a PostgreSQL database. It will also run the `npm install` command above for you. @@ -55,7 +55,7 @@ Edit `datasources.json` to add other properties that enable you to connect the Description - + connector String @@ -139,7 +139,7 @@ The model definition consists of the following properties. Description - + name Camel-case of the database table name From e159ba0c3d5cd4a2d7a6d4d0ee469b03919e8455 Mon Sep 17 00:00:00 2001 From: Greg Dingle Date: Fri, 28 Oct 2016 17:43:23 +0200 Subject: [PATCH 2/6] Fix bug where settings for pg-pool were dropped --- lib/postgresql.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/postgresql.js b/lib/postgresql.js index 13d78f0a..a947a0ee 100644 --- a/lib/postgresql.js +++ b/lib/postgresql.js @@ -72,13 +72,10 @@ function PostgreSQL(postgresql, settings) { // this._models = {}; // this.settings = settings; this.constructor.super_.call(this, 'postgresql', settings); + this.clientConfig = settings; if (settings.url) { // pg-pool doesn't handle string config correctly - this.clientConfig = { - connectionString: settings.url, - }; - } else { - this.clientConfig = settings; + this.clientConfig.connectionString = settings.url; } this.clientConfig.Promise = Promise; this.pg = new postgresql.Pool(this.clientConfig); From 0fd1ff22386095ee115424f0ff81f13aaa645d74 Mon Sep 17 00:00:00 2001 From: gregdingle Date: Tue, 15 Nov 2016 22:55:28 +0100 Subject: [PATCH 3/6] Added test. Ran run-tests. --- test/postgresql.initialization.test.js | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/postgresql.initialization.test.js diff --git a/test/postgresql.initialization.test.js b/test/postgresql.initialization.test.js new file mode 100644 index 00000000..8c1db598 --- /dev/null +++ b/test/postgresql.initialization.test.js @@ -0,0 +1,52 @@ +// Copyright IBM Corp. 2015. All Rights Reserved. +// Node module: loopback-connector-postgresql +// This file is licensed under the Artistic License 2.0. +// License text available at https://opensource.org/licenses/Artistic-2.0 + +'use strict'; + +var connector = require('..'); +var DataSource = require('loopback-datasource-juggler').DataSource; +var should = require('should'); + +describe('initialization', function() { + it('honours user-defined pg-pool settings', function(done) { + var dataSource = new DataSource(connector, {}); + var pool = dataSource.connector.pg.pool; + pool._factory.max.should.not.equal(999); + + var settings = {max: 999}; // non-default value + var dataSource = new DataSource(connector, settings); + var pool = dataSource.connector.pg.pool; + pool._factory.max.should.equal(999); + + done(); + }); + + it('honours user-defined url settings', function(done) { + var settings = {url: 'postgres://'}; + + var dataSource = new DataSource(connector, {}); + var clientConfig = dataSource.connector.clientConfig; + should.not.exist(clientConfig.connectionString); + + var dataSource = new DataSource(connector, settings); + var clientConfig = dataSource.connector.clientConfig; + clientConfig.connectionString.should.equal(settings.url); + + done(); + }); + + it('honours multiple user-defined settings', function(done) { + var settings = {url: 'postgres://', max: 999}; + + var dataSource = new DataSource(connector, settings); + var pool = dataSource.connector.pg.pool; + pool._factory.max.should.equal(999); + + var clientConfig = dataSource.connector.clientConfig; + clientConfig.connectionString.should.equal(settings.url); + + done(); + }); +}); \ No newline at end of file From 5dbc9ec7f0b2c8071df14502788794412a6d2293 Mon Sep 17 00:00:00 2001 From: gregdingle Date: Wed, 14 Dec 2016 13:12:06 +0100 Subject: [PATCH 4/6] remove done() calls in test --- test/postgresql.initialization.test.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/postgresql.initialization.test.js b/test/postgresql.initialization.test.js index 8c1db598..8e4b9f7f 100644 --- a/test/postgresql.initialization.test.js +++ b/test/postgresql.initialization.test.js @@ -10,7 +10,7 @@ var DataSource = require('loopback-datasource-juggler').DataSource; var should = require('should'); describe('initialization', function() { - it('honours user-defined pg-pool settings', function(done) { + it('honours user-defined pg-pool settings', function() { var dataSource = new DataSource(connector, {}); var pool = dataSource.connector.pg.pool; pool._factory.max.should.not.equal(999); @@ -19,11 +19,9 @@ describe('initialization', function() { var dataSource = new DataSource(connector, settings); var pool = dataSource.connector.pg.pool; pool._factory.max.should.equal(999); - - done(); }); - it('honours user-defined url settings', function(done) { + it('honours user-defined url settings', function() { var settings = {url: 'postgres://'}; var dataSource = new DataSource(connector, {}); @@ -33,11 +31,9 @@ describe('initialization', function() { var dataSource = new DataSource(connector, settings); var clientConfig = dataSource.connector.clientConfig; clientConfig.connectionString.should.equal(settings.url); - - done(); }); - it('honours multiple user-defined settings', function(done) { + it('honours multiple user-defined settings', function() { var settings = {url: 'postgres://', max: 999}; var dataSource = new DataSource(connector, settings); @@ -46,7 +42,5 @@ describe('initialization', function() { var clientConfig = dataSource.connector.clientConfig; clientConfig.connectionString.should.equal(settings.url); - - done(); }); }); \ No newline at end of file From c3f3e96ff983f5e6288c6244cd8330c8f010be90 Mon Sep 17 00:00:00 2001 From: Diana Lau Date: Tue, 14 Feb 2017 12:20:45 -0500 Subject: [PATCH 5/6] Fix linting errors and unnesssary changes. --- README.md | 6 +++--- test/postgresql.initialization.test.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aad99d92..2d5a6c13 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ If you create a PostgreSQL data source using the data source generator as descri ## Creating a data source -Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application. +Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application. The generator will prompt for the database server hostname, port, and other settings required to connect to a PostgreSQL database. It will also run the `npm install` command above for you. @@ -55,7 +55,7 @@ Edit `datasources.json` to add other properties that enable you to connect the Description - + connector String @@ -139,7 +139,7 @@ The model definition consists of the following properties. Description - + name Camel-case of the database table name diff --git a/test/postgresql.initialization.test.js b/test/postgresql.initialization.test.js index 8e4b9f7f..5795b395 100644 --- a/test/postgresql.initialization.test.js +++ b/test/postgresql.initialization.test.js @@ -43,4 +43,4 @@ describe('initialization', function() { var clientConfig = dataSource.connector.clientConfig; clientConfig.connectionString.should.equal(settings.url); }); -}); \ No newline at end of file +}); From e2f04f7af6ff121397629bf65f8de9e5728e7630 Mon Sep 17 00:00:00 2001 From: ssh24 Date: Thu, 16 Feb 2017 13:08:40 -0500 Subject: [PATCH 6/6] fix pgpool tests to not clobber other tests The tests are all run in the same process against the same instances of the module so care must be taken to not clobber things like the shared config that the tests all use. When the username is removed from the shared config then the pg attempts to use the OS username as the DB username. This is not guaranteed and is actually not true in the Windows environments these tests run under in CI. --- test/postgresql.initialization.test.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/postgresql.initialization.test.js b/test/postgresql.initialization.test.js index 5795b395..d16a750d 100644 --- a/test/postgresql.initialization.test.js +++ b/test/postgresql.initialization.test.js @@ -4,43 +4,51 @@ // License text available at https://opensource.org/licenses/Artistic-2.0 'use strict'; +require('./init'); var connector = require('..'); var DataSource = require('loopback-datasource-juggler').DataSource; var should = require('should'); +// simple wrapper that uses JSON.parse(JSON.stringify()) as cheap clone +function newConfig(withURL) { + return JSON.parse(JSON.stringify(getDBConfig(withURL))); +} + describe('initialization', function() { it('honours user-defined pg-pool settings', function() { - var dataSource = new DataSource(connector, {}); + var dataSource = new DataSource(connector, newConfig()); var pool = dataSource.connector.pg.pool; pool._factory.max.should.not.equal(999); - var settings = {max: 999}; // non-default value + var settings = newConfig(); + settings.max = 999; // non-default value var dataSource = new DataSource(connector, settings); var pool = dataSource.connector.pg.pool; pool._factory.max.should.equal(999); }); it('honours user-defined url settings', function() { - var settings = {url: 'postgres://'}; + var settings = newConfig(); - var dataSource = new DataSource(connector, {}); + var dataSource = new DataSource(connector, settings); var clientConfig = dataSource.connector.clientConfig; should.not.exist(clientConfig.connectionString); + settings = newConfig(true); var dataSource = new DataSource(connector, settings); var clientConfig = dataSource.connector.clientConfig; clientConfig.connectionString.should.equal(settings.url); }); it('honours multiple user-defined settings', function() { - var settings = {url: 'postgres://', max: 999}; + var urlOnly = {url: newConfig(true).url, max: 999}; - var dataSource = new DataSource(connector, settings); + var dataSource = new DataSource(connector, urlOnly); var pool = dataSource.connector.pg.pool; pool._factory.max.should.equal(999); var clientConfig = dataSource.connector.clientConfig; - clientConfig.connectionString.should.equal(settings.url); + clientConfig.connectionString.should.equal(urlOnly.url); }); });