-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
createPoolConfiguration.js
60 lines (46 loc) · 2.28 KB
/
createPoolConfiguration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// @flow
/* eslint-disable id-match */
import {
parse as parseConnectionString,
} from 'pg-connection-string';
import type {
ClientConfigurationType,
} from '../types';
import log from '../Logger';
export default (connectionUri: string, clientConfiguration: ClientConfigurationType) => {
const poolConfiguration = parseConnectionString(connectionUri);
// @see https://node-postgres.com/api/pool
poolConfiguration.connectionTimeoutMillis = clientConfiguration.connectionTimeout;
poolConfiguration.idleTimeoutMillis = clientConfiguration.idleTimeout;
poolConfiguration.max = clientConfiguration.maximumPoolSize;
if (clientConfiguration.connectionTimeout === 'DISABLE_TIMEOUT') {
poolConfiguration.connectionTimeoutMillis = undefined;
} else if (clientConfiguration.connectionTimeout === 0) {
log.warn('connectionTimeout=0 sets timeout to 0 milliseconds; use connectionTimeout=DISABLE_TIMEOUT to disable timeout');
poolConfiguration.connectionTimeoutMillis = 1;
}
if (poolConfiguration.ssl) {
poolConfiguration.ssl = {
rejectUnauthorized: false,
...poolConfiguration.ssl,
};
}
// Temporary disabled.
// There appears to be a bug in node-postgres.
// https://github.com/brianc/node-postgres/issues/2103
// poolConfiguration.idle_in_transaction_session_timeout = clientConfiguration.idleInTransactionSessionTimeout;
// poolConfiguration.statement_timeout = clientConfiguration.statementTimeout;
// if (clientConfiguration.idleInTransactionSessionTimeout === 'DISABLE_TIMEOUT') {
// poolConfiguration.idle_in_transaction_session_timeout = undefined;
// } else if (clientConfiguration.idleInTransactionSessionTimeout === 0) {
// log.warn('idleInTransactionSessionTimeout=0 sets timeout to 0 milliseconds; use idleInTransactionSessionTimeout=DISABLE_TIMEOUT to disable timeout');
// poolConfiguration.idle_in_transaction_session_timeout = 1;
// }
// if (clientConfiguration.statementTimeout === 'DISABLE_TIMEOUT') {
// poolConfiguration.statement_timeout = undefined;
// } else if (clientConfiguration.statementTimeout === 0) {
// log.warn('statementTimeout=0 sets timeout to 0 milliseconds; use statementTimeout=DISABLE_TIMEOUT to disable timeout');
// poolConfiguration.statement_timeout = 1;
// }
return poolConfiguration;
};