@trenskow/pged 5.1.69 → 5.1.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +17 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -44,6 +44,7 @@ export default class PGed extends EventEmitter {
|
|
|
44
44
|
options.casing = options.casing || {};
|
|
45
45
|
options.casing.db = options.casing.db || 'snake';
|
|
46
46
|
options.casing.js = options.casing.hs || 'camel';
|
|
47
|
+
options.connectionRetryCount = options.connectionRetryCount || 1;
|
|
47
48
|
|
|
48
49
|
options.defaultPrimaryKey = options.defaultPrimaryKey || 'id';
|
|
49
50
|
|
|
@@ -113,8 +114,23 @@ export default class PGed extends EventEmitter {
|
|
|
113
114
|
async _retain() {
|
|
114
115
|
this._connectionCount++;
|
|
115
116
|
if (this._connectionCount == 1) {
|
|
116
|
-
|
|
117
|
+
|
|
118
|
+
let connectionCount = 0;
|
|
119
|
+
|
|
120
|
+
while (connectionCount < this._options.connectionRetryCount) {
|
|
121
|
+
try {
|
|
122
|
+
connectionCount++;
|
|
123
|
+
this._client = await pool.connect();
|
|
124
|
+
break;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (connectionCount == this._options.connectionRetryCount) {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
117
132
|
await this.emit('connected');
|
|
133
|
+
|
|
118
134
|
}
|
|
119
135
|
}
|
|
120
136
|
|