@flutry/sequelize 0.1.2 → 0.1.3
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/dist/utils/connect.d.ts +2 -0
- package/dist/utils/connect.js +40 -4
- package/package.json +2 -1
package/dist/utils/connect.d.ts
CHANGED
package/dist/utils/connect.js
CHANGED
|
@@ -21,7 +21,17 @@ class Flutry_Connect {
|
|
|
21
21
|
host: `${process.env.DB_HOST}`,
|
|
22
22
|
dialect: `${process.env.DB_TYPE}`,
|
|
23
23
|
logging: false,
|
|
24
|
-
timezone: await
|
|
24
|
+
timezone: await this.functions.getTimeZone(),
|
|
25
|
+
pool: {
|
|
26
|
+
max: 5,
|
|
27
|
+
min: 0,
|
|
28
|
+
acquire: 30000, // 30 seconds timeout for acquiring connection
|
|
29
|
+
idle: 10000, // 10 seconds idle timeout
|
|
30
|
+
},
|
|
31
|
+
retry: {
|
|
32
|
+
match: [/ETIMEDOUT/, /EHOSTUNREACH/, /ECONNRESET/, /ECONNREFUSED/, /TIMEOUT/],
|
|
33
|
+
max: 3,
|
|
34
|
+
},
|
|
25
35
|
define: {
|
|
26
36
|
charset: 'utf8mb4',
|
|
27
37
|
collate: 'utf8mb4_bin',
|
|
@@ -34,21 +44,47 @@ class Flutry_Connect {
|
|
|
34
44
|
this.retryCount = 0; // Reset retry count on successful connection
|
|
35
45
|
}
|
|
36
46
|
catch (error) {
|
|
37
|
-
|
|
47
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
48
|
+
const isTimeoutError = /timeout|ETIMEDOUT|ECONNRESET|EHOSTUNREACH|ECONNREFUSED/i.test(errorMessage);
|
|
49
|
+
if (isTimeoutError) {
|
|
50
|
+
main_1.Flutry_Sequelize.logger.error(`Database connection timeout. Attempt ${this.retryCount + 1}/${this.maxRetries}. Error: ${errorMessage}`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
main_1.Flutry_Sequelize.logger.error(`Database connection error. Attempt ${this.retryCount + 1}/${this.maxRetries}. Error: ${errorMessage}`);
|
|
54
|
+
}
|
|
38
55
|
if (this.retryCount < this.maxRetries) {
|
|
39
56
|
this.retryCount++;
|
|
40
|
-
|
|
57
|
+
const waitTime = isTimeoutError ? this.retryDelay * 2 : this.retryDelay; // Longer wait for timeout errors
|
|
58
|
+
main_1.Flutry_Sequelize.logger.info(`Retrying connection in ${waitTime / 1000} seconds...`);
|
|
41
59
|
setTimeout(() => {
|
|
42
60
|
this.connect();
|
|
43
|
-
},
|
|
61
|
+
}, waitTime);
|
|
44
62
|
}
|
|
45
63
|
else {
|
|
46
64
|
main_1.Flutry_Sequelize.logger.error('Maximum retry attempts reached. Unable to connect to database.');
|
|
65
|
+
main_1.Flutry_Sequelize.logger.error(`Final error: ${errorMessage}`);
|
|
47
66
|
this.retryCount = 0; // Reset for potential future attempts
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
};
|
|
51
70
|
this.init();
|
|
52
71
|
}
|
|
72
|
+
// Getter to check if connection is established
|
|
73
|
+
static get isConnected() {
|
|
74
|
+
return this.sequelize && this.sequelize.authenticate !== undefined;
|
|
75
|
+
}
|
|
76
|
+
// Manual reconnect method
|
|
77
|
+
async reconnect() {
|
|
78
|
+
if (Flutry_Connect.sequelize) {
|
|
79
|
+
try {
|
|
80
|
+
await Flutry_Connect.sequelize.close();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
main_1.Flutry_Sequelize.logger.warn('Error closing existing connection:', error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
this.retryCount = 0;
|
|
87
|
+
await this.connect();
|
|
88
|
+
}
|
|
53
89
|
}
|
|
54
90
|
exports.Flutry_Connect = Flutry_Connect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flutry/sequelize",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"sequelize": "^6.37.7"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/node": "^25.3.1",
|
|
20
21
|
"typescript": "^5.9.3"
|
|
21
22
|
}
|
|
22
23
|
}
|