Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.0.3
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.0
Choose a head ref
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Aug 4, 2017

  1. Create SPONSORS.md

    brianc authored Aug 4, 2017
    Copy the full SHA
    6517207 View commit details
  2. Copy the full SHA
    3a6b841 View commit details
  3. Update changelog

    brianc committed Aug 4, 2017
    Copy the full SHA
    03e8f71 View commit details
  4. Bump version

    brianc committed Aug 4, 2017
    Copy the full SHA
    56d262f View commit details
Showing with 39 additions and 10 deletions.
  1. +6 −0 CHANGELOG.md
  2. +3 −0 SPONSORS.md
  3. +6 −5 lib/connection-parameters.js
  4. +1 −4 lib/index.js
  5. +1 −1 package.json
  6. +22 −0 test/unit/connection-parameters/creation-tests.js
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ For richer information consult the commit log on github with referenced pull req

We do not include break-fix version release in this file.

### 7.1.0

#### Enhancements

- [You can now supply both a connection string and additional config options to clients.](https://github.com/brianc/node-postgres/pull/1363)

### 7.0.0

#### Breaking Changes
3 changes: 3 additions & 0 deletions SPONSORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Leaders

# Supporters
11 changes: 6 additions & 5 deletions lib/connection-parameters.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ var dns = require('dns')

var defaults = require('./defaults')

var parse = require('pg-connection-string').parse // parses a connection string

var val = function (key, config, envVar) {
if (envVar === undefined) {
envVar = process.env[ 'PG' + key.toUpperCase() ]
@@ -25,9 +27,6 @@ var val = function (key, config, envVar) {
defaults[key]
}

// parses a connection string
var parse = require('pg-connection-string').parse

var useSsl = function () {
switch (process.env.PGSSLMODE) {
case 'disable':
@@ -43,12 +42,14 @@ var useSsl = function () {

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)
config = Object.assign({}, config, parse(config.connectionString))
}

this.user = val('user', config)
this.database = val('database', config)
this.port = parseInt(val('port', config), 10)
5 changes: 1 addition & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -15,10 +15,7 @@ var Pool = require('pg-pool')

const poolFactory = (Client) => {
var BoundPool = function (options) {
var config = { Client: Client }
for (var key in options) {
config[key] = options[key]
}
var config = Object.assign({ Client: Client }, options)
return new Pool(config)
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "7.0.2",
"version": "7.1.0",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"postgres",
22 changes: 22 additions & 0 deletions test/unit/connection-parameters/creation-tests.js
Original file line number Diff line number Diff line change
@@ -67,6 +67,28 @@ test('ConnectionParameters initializing from config', function () {
assert.ok(subject.isDomainSocket === false)
})

test('ConnectionParameters initializing from config and config.connectionString', function() {
var subject1 = new ConnectionParameters({
connectionString: 'postgres://test@host/db'
})
var subject2 = new ConnectionParameters({
connectionString: 'postgres://test@host/db?ssl=1'
})
var subject3 = new ConnectionParameters({
connectionString: 'postgres://test@host/db',
ssl: true
})
var subject4 = new ConnectionParameters({
connectionString: 'postgres://test@host/db?ssl=1',
ssl: false
})

assert.equal(subject1.ssl, false)
assert.equal(subject2.ssl, true)
assert.equal(subject3.ssl, true)
assert.equal(subject4.ssl, true)
});

test('escape spaces if present', function () {
var subject = new ConnectionParameters('postgres://localhost/post gres')
assert.equal(subject.database, 'post gres')