@trenskow/pged 5.1.69 → 5.1.71
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 +26 -1
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import Puqeue from 'puqeue';
|
|
|
10
10
|
import caseit from '@trenskow/caseit';
|
|
11
11
|
import pg from 'pg';
|
|
12
12
|
import EventEmitter from '@trenskow/async-event-emitter';
|
|
13
|
+
import wait from '@trenskow/wait';
|
|
13
14
|
|
|
14
15
|
import QueryBuilder from './query-builder.js';
|
|
15
16
|
|
|
@@ -44,6 +45,11 @@ export default class PGed extends EventEmitter {
|
|
|
44
45
|
options.casing = options.casing || {};
|
|
45
46
|
options.casing.db = options.casing.db || 'snake';
|
|
46
47
|
options.casing.js = options.casing.hs || 'camel';
|
|
48
|
+
|
|
49
|
+
options.connection = options.connection || {};
|
|
50
|
+
options.connection.retry = options.connection.retry || {};
|
|
51
|
+
options.connection.retry.count = options.connection.retry.count || 1;
|
|
52
|
+
options.connection.retry.delay = options.connection.retry.delay || '0s';
|
|
47
53
|
|
|
48
54
|
options.defaultPrimaryKey = options.defaultPrimaryKey || 'id';
|
|
49
55
|
|
|
@@ -113,8 +119,27 @@ export default class PGed extends EventEmitter {
|
|
|
113
119
|
async _retain() {
|
|
114
120
|
this._connectionCount++;
|
|
115
121
|
if (this._connectionCount == 1) {
|
|
116
|
-
|
|
122
|
+
|
|
123
|
+
let connectionCount = 0;
|
|
124
|
+
|
|
125
|
+
while (connectionCount < this._options.connection.retry.count) {
|
|
126
|
+
try {
|
|
127
|
+
connectionCount++;
|
|
128
|
+
this._client = await pool.connect();
|
|
129
|
+
break;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
|
|
132
|
+
if (connectionCount == this._options.connection.retry.count) {
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
await wait(this._options.connectionRetryDelay);
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
117
141
|
await this.emit('connected');
|
|
142
|
+
|
|
118
143
|
}
|
|
119
144
|
}
|
|
120
145
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trenskow/pged",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.71",
|
|
4
4
|
"description": "Just a silly little db management and query builder for PostgreSQL.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@trenskow/caseit": "^1.4.12",
|
|
28
28
|
"@trenskow/custom-promise": "^0.13.9",
|
|
29
29
|
"@trenskow/parse": "^0.1.33",
|
|
30
|
+
"@trenskow/wait": "^1.3.60",
|
|
30
31
|
"pg": "^8.16.0",
|
|
31
32
|
"puqeue": "^1.1.17"
|
|
32
33
|
},
|