agrs-sequelize-sdk 1.1.5 → 1.1.6

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/index.js +109 -109
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,87 +1,14 @@
1
- // const Sequelize = require("sequelize");
2
- // const path = require("path");
3
- // const fs = require("fs");
4
-
5
- // // const env = process.env.NODE_ENV || "development";
6
- // class DBModels {
7
- // constructor(config) {
8
- // this.config = config;
9
- // this.db = {};
10
-
11
- // // Initialize Sequelize
12
- // const sequelize = new Sequelize(
13
- // this.config.database,
14
- // this.config.username,
15
- // this.config.password,
16
- // {
17
- // host: this.config.host,
18
- // dialect: this.config.dialect,
19
- // port: this.config.port,
20
- // logging: false, // Enable logging to console
21
- // dialectOptions: {
22
- // ssl: {
23
- // require: true, // Require SSL
24
- // rejectUnauthorized: false, // For self-signed or unverified certificates
25
- // },
26
- // },
27
- // pool: {
28
- // max: 150, // Increase from 50, but stay under max_connections (200)
29
- // min: 5, // Increase minimum connections
30
- // acquire: 60000, // Double acquire timeout
31
- // idle: 30000, // Align with idle_in_transaction_session_timeout
32
- // },
33
-
34
- // retry: {
35
- // max: 5,
36
- // timeout: 60000,
37
- // match: [
38
- // /Connection terminated/,
39
- // /Connection timed out/,
40
- // /Operation timeout/,
41
- // /password authentication failed/,
42
- // /canceling authentication/,
43
- // ],
44
- // },
45
- // }
46
- // );
47
-
48
- // // Load all models
49
- // fs.readdirSync(path.join(__dirname, "models"))
50
- // .filter((file) => {
51
- // return file.indexOf(".") !== 0 && file.slice(-3) === ".js";
52
- // })
53
- // .forEach((file) => {
54
- // const model = require(path.join(__dirname, "models", file))(
55
- // sequelize,
56
- // Sequelize.DataTypes
57
- // );
58
- // this.db[model.name] = model;
59
- // });
60
-
61
- // // Set up associations
62
- // Object.keys(this.db).forEach((modelName) => {
63
- // if (this.db[modelName].associate) {
64
- // this.db[modelName].associate(this.db);
65
- // }
66
- // });
67
-
68
- // // Export the db object with Sequelize and models
69
- // this.db.sequelize = sequelize;
70
- // this.db.Sequelize = Sequelize;
71
- // }
72
- // }
73
-
74
- // module.exports = DBModels;
75
-
76
1
  const Sequelize = require("sequelize");
77
2
  const path = require("path");
78
3
  const fs = require("fs");
79
4
 
5
+ // const env = process.env.NODE_ENV || "development";
80
6
  class DBModels {
81
7
  constructor(config) {
82
8
  this.config = config;
83
9
  this.db = {};
84
10
 
11
+ // Initialize Sequelize
85
12
  const sequelize = new Sequelize(
86
13
  this.config.database,
87
14
  this.config.username,
@@ -90,45 +17,34 @@ class DBModels {
90
17
  host: this.config.host,
91
18
  dialect: this.config.dialect,
92
19
  port: this.config.port,
93
- logging: false,
20
+ logging: false, // Enable logging to console
94
21
  dialectOptions: {
95
22
  ssl: {
96
- require: true,
97
- rejectUnauthorized: false,
23
+ require: true, // Require SSL
24
+ rejectUnauthorized: false, // For self-signed or unverified certificates
98
25
  },
99
- statement_timeout: 30000,
100
- idle_in_transaction_session_timeout: 30000,
101
- connectTimeout: 30000,
102
26
  },
103
27
  pool: {
104
- max: 50, // Quarter of max connections (200)
105
- min: 0, // Start from 0 and scale up as needed
106
- acquire: 30000, // Maximum time to wait for a connection
107
- idle: 10000, // How long a connection can remain idle
28
+ max: 150, // Increase from 50, but stay under max_connections (200)
29
+ min: 5, // Increase minimum connections
30
+ acquire: 60000, // Double acquire timeout
31
+ idle: 30000, // Align with idle_in_transaction_session_timeout
108
32
  },
33
+
109
34
  retry: {
110
- max: 3,
111
- timeout: 20000,
35
+ max: 5,
36
+ timeout: 60000,
112
37
  match: [
113
38
  /Connection terminated/,
114
39
  /Connection timed out/,
115
40
  /Operation timeout/,
116
- /ECONNRESET/,
117
- /PROTOCOL_CONNECTION_LOST/,
41
+ /password authentication failed/,
42
+ /canceling authentication/,
118
43
  ],
119
44
  },
120
45
  }
121
46
  );
122
47
 
123
- // Add connection monitoring listeners
124
- sequelize.connectionManager.on("acquire", function (connection) {
125
- console.log("Connection %d acquired", connection.threadId);
126
- });
127
-
128
- sequelize.connectionManager.on("release", function (connection) {
129
- console.log("Connection %d released", connection.threadId);
130
- });
131
-
132
48
  // Load all models
133
49
  fs.readdirSync(path.join(__dirname, "models"))
134
50
  .filter((file) => {
@@ -153,17 +69,101 @@ class DBModels {
153
69
  this.db.sequelize = sequelize;
154
70
  this.db.Sequelize = Sequelize;
155
71
  }
156
-
157
- // Add method for pool monitoring
158
- async getConnectionPoolStats() {
159
- const pool = this.db.sequelize.connectionManager.pool;
160
- return {
161
- all: pool.size,
162
- available: pool.available,
163
- borrowed: pool.borrowed,
164
- pending: pool.pending,
165
- };
166
- }
167
72
  }
168
73
 
169
74
  module.exports = DBModels;
75
+
76
+ // const Sequelize = require("sequelize");
77
+ // const path = require("path");
78
+ // const fs = require("fs");
79
+
80
+ // class DBModels {
81
+ // constructor(config) {
82
+ // this.config = config;
83
+ // this.db = {};
84
+
85
+ // const sequelize = new Sequelize(
86
+ // this.config.database,
87
+ // this.config.username,
88
+ // this.config.password,
89
+ // {
90
+ // host: this.config.host,
91
+ // dialect: this.config.dialect,
92
+ // port: this.config.port,
93
+ // logging: false,
94
+ // dialectOptions: {
95
+ // ssl: {
96
+ // require: true,
97
+ // rejectUnauthorized: false,
98
+ // },
99
+ // statement_timeout: 30000,
100
+ // idle_in_transaction_session_timeout: 30000,
101
+ // connectTimeout: 30000,
102
+ // },
103
+ // pool: {
104
+ // max: 50, // Quarter of max connections (200)
105
+ // min: 0, // Start from 0 and scale up as needed
106
+ // acquire: 30000, // Maximum time to wait for a connection
107
+ // idle: 10000, // How long a connection can remain idle
108
+ // },
109
+ // retry: {
110
+ // max: 3,
111
+ // timeout: 20000,
112
+ // match: [
113
+ // /Connection terminated/,
114
+ // /Connection timed out/,
115
+ // /Operation timeout/,
116
+ // /ECONNRESET/,
117
+ // /PROTOCOL_CONNECTION_LOST/,
118
+ // ],
119
+ // },
120
+ // }
121
+ // );
122
+
123
+ // // Add connection monitoring listeners
124
+ // sequelize.connectionManager.on("acquire", function (connection) {
125
+ // console.log("Connection %d acquired", connection.threadId);
126
+ // });
127
+
128
+ // sequelize.connectionManager.on("release", function (connection) {
129
+ // console.log("Connection %d released", connection.threadId);
130
+ // });
131
+
132
+ // // Load all models
133
+ // fs.readdirSync(path.join(__dirname, "models"))
134
+ // .filter((file) => {
135
+ // return file.indexOf(".") !== 0 && file.slice(-3) === ".js";
136
+ // })
137
+ // .forEach((file) => {
138
+ // const model = require(path.join(__dirname, "models", file))(
139
+ // sequelize,
140
+ // Sequelize.DataTypes
141
+ // );
142
+ // this.db[model.name] = model;
143
+ // });
144
+
145
+ // // Set up associations
146
+ // Object.keys(this.db).forEach((modelName) => {
147
+ // if (this.db[modelName].associate) {
148
+ // this.db[modelName].associate(this.db);
149
+ // }
150
+ // });
151
+
152
+ // // Export the db object with Sequelize and models
153
+ // this.db.sequelize = sequelize;
154
+ // this.db.Sequelize = Sequelize;
155
+ // }
156
+
157
+ // // Add method for pool monitoring
158
+ // async getConnectionPoolStats() {
159
+ // const pool = this.db.sequelize.connectionManager.pool;
160
+ // return {
161
+ // all: pool.size,
162
+ // available: pool.available,
163
+ // borrowed: pool.borrowed,
164
+ // pending: pool.pending,
165
+ // };
166
+ // }
167
+ // }
168
+
169
+ // module.exports = DBModels;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",