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.5.0
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.6.0
Choose a head ref
  • 6 commits
  • 8 files changed
  • 3 contributors

Commits on Oct 23, 2018

  1. Copy the full SHA
    ff6fe1e View commit details

Commits on Oct 24, 2018

  1. Allow a custom type to be used for Client promises (#1518)

    Matches the Pool API.
    charmander authored and brianc committed Oct 24, 2018
    Copy the full SHA
    1cf1e05 View commit details

Commits on Oct 26, 2018

  1. Update ESLint (#1753)

    * Update ESLint
    
    * Downgrade ESLint version to restore Node 4 support
    
    * Downgrade more dependencies
    
    * Keep downgrading
    kibertoad authored and brianc committed Oct 26, 2018
    Copy the full SHA
    badf0a1 View commit details
  2. Update SPONSORS.md

    brianc authored Oct 26, 2018
    Copy the full SHA
    d468b6a View commit details
  3. Update changelog

    brianc committed Oct 26, 2018
    Copy the full SHA
    034eb34 View commit details
  4. Bump version

    brianc committed Oct 26, 2018
    Copy the full SHA
    a3295b4 View commit details
Showing with 52 additions and 25 deletions.
  1. +2 −2 .travis.yml
  2. +3 −0 CHANGELOG.md
  3. +5 −0 SPONSORS.md
  4. +5 −7 lib/client.js
  5. +1 −1 lib/connection-parameters.js
  6. +5 −7 lib/native/client.js
  7. +8 −7 package.json
  8. +23 −1 test/integration/client/query-as-promise-tests.js
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -14,10 +14,10 @@ matrix:
- node_js: "lts/argon"
addons:
postgresql: "9.6"
- node_js: "9"
- node_js: "10"
addons:
postgresql: "9.6"
- node_js: "10"
- node_js: "11"
addons:
postgresql: "9.6"
- node_js: "lts/carbon"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ 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.6.0
- Add support for ["bring your own promise"](https://github.com/brianc/node-postgres/pull/1518)

### 7.5.0

- Better [error message](https://github.com/brianc/node-postgres/commit/11a4793452d618c53e019416cc886ad38deb1aa7) when passing `null` or `undefined` to `client.query`.
5 changes: 5 additions & 0 deletions SPONSORS.md
Original file line number Diff line number Diff line change
@@ -11,4 +11,9 @@ node-postgres is made possible by the helpful contributors from the community we
- Arnaud Benhamdine [@abenhamdine](https://twitter.com/abenhamdine)
- Matthew Welke
- Matthew Weber
- Andrea De Simon
- Todd Kennedy
- Alexander Robson
- Benjie Gillam
- David Hanson
- Franklin Davenport
12 changes: 5 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ var Client = function (config) {

var c = config || {}

this._Promise = c.Promise || global.Promise
this._types = new TypeOverrides(c.types)
this._ending = false
this._connecting = false
@@ -232,7 +233,7 @@ Client.prototype.connect = function (callback) {
return
}

return new Promise((resolve, reject) => {
return new this._Promise((resolve, reject) => {
this._connect((error) => {
if (error) {
reject(error)
@@ -409,12 +410,9 @@ Client.prototype.query = function (config, values, callback) {
} else {
query = new Query(config, values, callback)
if (!query.callback) {
let resolveOut, rejectOut
result = new Promise((resolve, reject) => {
resolveOut = resolve
rejectOut = reject
result = new this._Promise((resolve, reject) => {
query.callback = (err, res) => err ? reject(err) : resolve(res)
})
query.callback = (err, res) => err ? rejectOut(err) : resolveOut(res)
}
}

@@ -458,7 +456,7 @@ Client.prototype.end = function (cb) {
if (cb) {
this.connection.once('end', cb)
} else {
return new Promise((resolve) => {
return new this._Promise((resolve) => {
this.connection.once('end', resolve)
})
}
2 changes: 1 addition & 1 deletion lib/connection-parameters.js
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function (cb) {
add(params, this, 'application_name')
add(params, this, 'fallback_application_name')

var ssl = typeof this.ssl === 'object' ? this.ssl : {sslmode: this.ssl}
var ssl = typeof this.ssl === 'object' ? this.ssl : { sslmode: this.ssl }
add(params, ssl, 'sslmode')
add(params, ssl, 'sslca')
add(params, ssl, 'sslkey')
12 changes: 5 additions & 7 deletions lib/native/client.js
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ var Client = module.exports = function (config) {
EventEmitter.call(this)
config = config || {}

this._Promise = config.Promise || global.Promise
this._types = new TypeOverrides(config.types)

this.native = new Native({
@@ -121,7 +122,7 @@ Client.prototype.connect = function (callback) {
return
}

return new Promise((resolve, reject) => {
return new this._Promise((resolve, reject) => {
this._connect((error) => {
if (error) {
reject(error)
@@ -156,7 +157,7 @@ Client.prototype.query = function (config, values, callback) {
query = new NativeQuery(config, values, callback)
if (!query.callback) {
let resolveOut, rejectOut
result = new Promise((resolve, reject) => {
result = new this._Promise((resolve, reject) => {
resolveOut = resolve
rejectOut = reject
})
@@ -196,11 +197,8 @@ Client.prototype.end = function (cb) {
}
var result
if (!cb) {
var resolve, reject
cb = (err) => err ? reject(err) : resolve()
result = new global.Promise(function (res, rej) {
resolve = res
reject = rej
result = new this._Promise(function (resolve, reject) {
cb = (err) => err ? reject(err) : resolve()
})
}
this.native.end(function () {
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "7.5.0",
"version": "7.6.0",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"database",
@@ -29,13 +29,14 @@
},
"devDependencies": {
"async": "0.9.0",
"bluebird": "3.5.2",
"co": "4.6.0",
"eslint": "4.2.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-node": "5.1.0",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-standard": "3.0.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^3.1.0",
"pg-copy-streams": "0.3.0"
},
"minNativeVersion": "2.0.0",
24 changes: 23 additions & 1 deletion test/integration/client/query-as-promise-tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
var bluebird = require('bluebird')
var helper = require(__dirname + '/../test-helper')
var pg = helper.pg

@@ -7,10 +8,10 @@ process.on('unhandledRejection', function (e) {
process.exit(1)
})

const pool = new pg.Pool()
const suite = new helper.Suite()

suite.test('promise API', (cb) => {
const pool = new pg.Pool()
pool.connect().then((client) => {
client.query('SELECT $1::text as name', ['foo'])
.then(function (result) {
@@ -31,3 +32,24 @@ suite.test('promise API', (cb) => {
})
})
})

suite.test('promise API with configurable promise type', (cb) => {
const client = new pg.Client({ Promise: bluebird })
const connectPromise = client.connect()
assert(connectPromise instanceof bluebird, 'Client connect() returns configured promise')

connectPromise
.then(() => {
const queryPromise = client.query('SELECT 1')
assert(queryPromise instanceof bluebird, 'Client query() returns configured promise')

return queryPromise.then(() => {
client.end(cb)
})
})
.catch((error) => {
process.nextTick(() => {
throw error
})
})
});