Skip to content

Commit 460051b

Browse files
committed
Merge branch 'master' into jrmerz-master
2 parents 3761207 + 60d8df6 commit 460051b

25 files changed

+482
-46
lines changed

.eslintrc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{
2-
"extends": "standard",
2+
"plugins": [
3+
"node"
4+
],
5+
"extends": [
6+
"standard",
7+
"eslint:recommended",
8+
"plugin:node/recommended"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 2017
12+
},
13+
"env": {
14+
"node": true,
15+
"es6": true
16+
},
317
"rules": {
4-
"no-new-func": "off"
518
}
619
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ script/
77
*.swp
88
test/
99
.travis.yml
10+
ci_scripts/

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
language: node_js
2-
sudo: false
2+
sudo: true
33
dist: trusty
4+
45
before_script:
56
- node script/create-test-tables.js pg://postgres@127.0.0.1:5432/postgres
7+
8+
before_install:
9+
- if [ $TRAVIS_OS_NAME == "linux" ]; then
10+
if [[ $(node -v) =~ v[1-9][0-9] ]]; then
11+
source ./ci_scripts/build.sh;
12+
fi
13+
fi
14+
615
env:
716
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres
817

@@ -17,6 +26,9 @@ matrix:
1726
- node_js: "10"
1827
addons:
1928
postgresql: "9.6"
29+
- node_js: "12"
30+
addons:
31+
postgresql: "9.6"
2032
- node_js: "lts/carbon"
2133
addons:
2234
postgresql: "9.1"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ For richer information consult the commit log on github with referenced pull req
44

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

7+
### 7.12.0
8+
9+
- Add support for [async password lookup](https://github.com/brianc/node-postgres/pull/1926).
10+
11+
### 7.11.0
12+
13+
- Add support for [connection_timeout](https://github.com/brianc/node-postgres/pull/1847/files#diff-5391bde944956870128be1136e7bc176R63) and [keepalives_idle](https://github.com/brianc/node-postgres/pull/1847).
14+
715
### 7.10.0
16+
817
- Add support for [per-query types](https://github.com/brianc/node-postgres/pull/1825).
918

1019
### 7.9.0

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,6 @@ test-pool:
6262

6363
lint:
6464
@echo "***Starting lint***"
65-
node_modules/.bin/eslint lib
65+
node -e "process.exit(Number(process.versions.node.split('.')[0]) < 8 ? 0 : 1)" \
66+
&& echo "***Skipping lint (node version too old)***" \
67+
|| node_modules/.bin/eslint lib

SPONSORS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
node-postgres is made possible by the helpful contributors from the community well as the following generous supporters on [Patreon](https://www.patreon.com/node_postgres).
22

33
# Leaders
4+
45
- [MadKudu](https://www.madkudu.com) - [@madkudu](https://twitter.com/madkudu)
56
- [Third Iron](https://thirdiron.com/)
7+
- [Timescale](https://timescale.com)
68

79
# Supporters
10+
811
- John Fawcett
912
- Lalit Kapoor [@lalitkapoor](https://twitter.com/lalitkapoor)
1013
- Paul Frazee [@pfrazee](https://twitter.com/pfrazee)

ci_scripts/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
BUILD_DIR="$(pwd)"
4+
source ./ci_scripts/install_openssl.sh 1.1.1b
5+
sudo updatedb
6+
source ./ci_scripts/install_libpq.sh
7+
sudo updatedb
8+
sudo ldconfig
9+
cd $BUILD_DIR

ci_scripts/install_libpq.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
OPENSSL_DIR="$(pwd)/openssl-1.1.1b"
6+
POSTGRES_VERSION="11.3"
7+
POSTGRES_DIR="$(pwd)/postgres-${POSTGRES_VERSION}"
8+
TMP_DIR="/tmp/postgres"
9+
JOBS="-j$(nproc || echo 1)"
10+
11+
if [ -d "${TMP_DIR}" ]; then
12+
rm -rf "${TMP_DIR}"
13+
fi
14+
15+
mkdir -p "${TMP_DIR}"
16+
17+
curl https://ftp.postgresql.org/pub/source/v${POSTGRES_VERSION}/postgresql-${POSTGRES_VERSION}.tar.gz | \
18+
tar -C "${TMP_DIR}" -xzf -
19+
20+
cd "${TMP_DIR}/postgresql-${POSTGRES_VERSION}"
21+
22+
if [ -d "${POSTGRES_DIR}" ]; then
23+
rm -rf "${POSTGRES_DIR}"
24+
fi
25+
mkdir -p $POSTGRES_DIR
26+
27+
./configure --prefix=$POSTGRES_DIR --with-openssl --with-includes=${OPENSSL_DIR}/include --with-libraries=${OPENSSL_DIR}/lib --without-readline
28+
29+
cd src/interfaces/libpq; make; make install; cd -
30+
cd src/bin/pg_config; make install; cd -
31+
cd src/backend; make generated-headers; cd -
32+
cd src/include; make install; cd -
33+
34+
export PATH="${POSTGRES_DIR}/bin:${PATH}"
35+
export CFLAGS="-I${POSTGRES_DIR}/include"
36+
export LDFLAGS="-L${POSTGRES_DIR}/lib"
37+
export LD_LIBRARY_PATH="${POSTGRES_DIR}/lib:$LD_LIBRARY_PATH"
38+
export PKG_CONFIG_PATH="${POSTGRES_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH"

ci_scripts/install_openssl.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
if [ ${#} -lt 1 ]; then
4+
echo "OpenSSL version required." 1>&2
5+
exit 1
6+
fi
7+
8+
OPENSSL_VERSION="${1}"
9+
OPENSSL_DIR="$(pwd)/openssl-${OPENSSL_VERSION}"
10+
TMP_DIR="/tmp/openssl"
11+
JOBS="-j$(nproc)"
12+
13+
if [ -d "${TMP_DIR}" ]; then
14+
rm -rf "${TMP_DIR}"
15+
fi
16+
mkdir -p "${TMP_DIR}"
17+
curl -s https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz | \
18+
tar -C "${TMP_DIR}" -xzf -
19+
pushd "${TMP_DIR}/openssl-${OPENSSL_VERSION}"
20+
if [ -d "${OPENSSL_DIR}" ]; then
21+
rm -rf "${OPENSSL_DIR}"
22+
fi
23+
./Configure \
24+
--prefix=${OPENSSL_DIR} \
25+
enable-crypto-mdebug enable-crypto-mdebug-backtrace \
26+
linux-x86_64
27+
make -s $JOBS
28+
make install_sw
29+
popd
30+
31+
export PATH="${OPENSSL_DIR}/bin:${PATH}"
32+
export CFLAGS="-I${OPENSSL_DIR}/include"
33+
export LDFLAGS="-L${OPENSSL_DIR}/lib"
34+
export LD_LIBRARY_PATH="${OPENSSL_DIR}/lib:$LD_LIBRARY_PATH"
35+
export PKG_CONFIG_PATH="${OPENSSL_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH"

lib/client.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ var Client = function (config) {
4444
stream: c.stream,
4545
ssl: this.connectionParameters.ssl,
4646
keepAlive: c.keepAlive || false,
47+
keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
4748
encoding: this.connectionParameters.client_encoding || 'utf8'
4849
})
4950
this.queryQueue = []
5051
this.binary = c.binary || defaults.binary
5152
this.processID = null
5253
this.secretKey = null
5354
this.ssl = this.connectionParameters.ssl || false
55+
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
5456
}
5557

5658
util.inherits(Client, EventEmitter)
@@ -83,6 +85,14 @@ Client.prototype._connect = function (callback) {
8385
}
8486
this._connecting = true
8587

88+
var connectionTimeoutHandle
89+
if (this._connectionTimeoutMillis > 0) {
90+
connectionTimeoutHandle = setTimeout(() => {
91+
con._ending = true
92+
con.stream.destroy(new Error('timeout expired'))
93+
}, this._connectionTimeoutMillis)
94+
}
95+
8696
if (this.host && this.host.indexOf('/') === 0) {
8797
con.connect(this.host + '/.s.PGSQL.' + this.port)
8898
} else {
@@ -104,7 +114,24 @@ Client.prototype._connect = function (callback) {
104114

105115
function checkPgPass (cb) {
106116
return function (msg) {
107-
if (self.password !== null) {
117+
if (typeof self.password === 'function') {
118+
self._Promise.resolve()
119+
.then(() => self.password())
120+
.then(pass => {
121+
if (pass !== undefined) {
122+
if (typeof pass !== 'string') {
123+
con.emit('error', new TypeError('Password must be a string'))
124+
return
125+
}
126+
self.connectionParameters.password = self.password = pass
127+
} else {
128+
self.connectionParameters.password = self.password = null
129+
}
130+
cb(msg)
131+
}).catch(err => {
132+
con.emit('error', err)
133+
})
134+
} else if (self.password !== null) {
108135
cb(msg)
109136
} else {
110137
pgPass(self.connectionParameters, function (pass) {
@@ -159,6 +186,7 @@ Client.prototype._connect = function (callback) {
159186
return
160187
}
161188
this._connectionError = true
189+
clearTimeout(connectionTimeoutHandle)
162190
if (callback) {
163191
return callback(err)
164192
}
@@ -196,6 +224,7 @@ Client.prototype._connect = function (callback) {
196224
con.removeListener('errorMessage', connectingErrorHandler)
197225
con.on('error', connectedErrorHandler)
198226
con.on('errorMessage', connectedErrorMessageHandler)
227+
clearTimeout(connectionTimeoutHandle)
199228

200229
// process possible callback argument to Client#connect
201230
if (callback) {
@@ -280,11 +309,13 @@ Client.prototype._attachListeners = function (con) {
280309
})
281310

282311
// delegate portalSuspended to active query
312+
// eslint-disable-next-line no-unused-vars
283313
con.on('portalSuspended', function (msg) {
284314
self.activeQuery.handlePortalSuspended(con)
285315
})
286316

287-
// deletagate emptyQuery to active query
317+
// delegate emptyQuery to active query
318+
// eslint-disable-next-line no-unused-vars
288319
con.on('emptyQuery', function (msg) {
289320
self.activeQuery.handleEmptyQuery(con)
290321
})
@@ -297,12 +328,14 @@ Client.prototype._attachListeners = function (con) {
297328
// if a prepared statement has a name and properly parses
298329
// we track that its already been executed so we don't parse
299330
// it again on the same client
331+
// eslint-disable-next-line no-unused-vars
300332
con.on('parseComplete', function (msg) {
301333
if (self.activeQuery.name) {
302334
con.parsedStatements[self.activeQuery.name] = self.activeQuery.text
303335
}
304336
})
305337

338+
// eslint-disable-next-line no-unused-vars
306339
con.on('copyInResponse', function (msg) {
307340
self.activeQuery.handleCopyInResponse(self.connection)
308341
})

0 commit comments

Comments
 (0)