@trenskow/pged 5.1.68 → 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.
Files changed (2) hide show
  1. package/lib/index.js +17 -1
  2. package/package.json +2 -2
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
- this._client = await pool.connect();
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/pged",
3
- "version": "5.1.68",
3
+ "version": "5.1.70",
4
4
  "description": "Just a silly little db management and query builder for PostgreSQL.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "homepage": "https://github.com/trenskow/pged#readme",
25
25
  "dependencies": {
26
- "@trenskow/async-event-emitter": "^0.1.66",
26
+ "@trenskow/async-event-emitter": "^0.1.67",
27
27
  "@trenskow/caseit": "^1.4.12",
28
28
  "@trenskow/custom-promise": "^0.13.9",
29
29
  "@trenskow/parse": "^0.1.33",