@pi-r/mysql 0.2.2 → 0.2.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/client/index.js CHANGED
@@ -21,9 +21,25 @@ class MySQLPool extends DbPool {
21
21
  }
22
22
  }
23
23
  const POOL_STATE = {};
24
+ const POOL_UNUSED = ['ssl', 'connectTimeout', 'queueLimit', 'waitForConnections', 'connectionLimit', 'maxIdle', 'idleTimeout', 'enableKeepAlive', 'keepAliveInitialDelay'];
24
25
  function removePoolProperties(credential) {
25
- if (!credential.uuidKey && ('ssl' in credential || 'connectionLimit' in credential || 'queueLimit' in credential || 'waitForConnections' in credential || 'enableKeepAlive' in credential || 'keepAliveInitialDelay' in credential || 'connectTimeout' in credential)) {
26
- return { ...credential, ssl: (0, types_1.isObject)(credential.ssl) ? true : undefined, connectionLimit: undefined, queueLimit: undefined, waitForConnections: undefined, enableKeepAlive: undefined, keepAliveInitialDelay: undefined, connectTimeout: undefined };
26
+ if (!credential.uuidKey) {
27
+ let result;
28
+ for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
29
+ const attr = POOL_UNUSED[i];
30
+ if (attr in credential) {
31
+ result || (result = { ...credential });
32
+ if (attr === 'ssl' && (0, types_1.isObject)(result[attr])) {
33
+ result[attr] = true;
34
+ }
35
+ else {
36
+ delete result[attr];
37
+ }
38
+ }
39
+ }
40
+ if (result) {
41
+ return result;
42
+ }
27
43
  }
28
44
  return credential;
29
45
  }
@@ -31,7 +47,6 @@ function removeUUIDKey(credential) {
31
47
  if ('uuidKey' in credential) {
32
48
  credential = { ...credential };
33
49
  delete credential.uuidKey;
34
- return credential;
35
50
  }
36
51
  return credential;
37
52
  }
@@ -81,10 +96,13 @@ function setCredential(item) {
81
96
  const { createPool } = require("mysql2/promise" /* STRINGS.PACKAGE_NAME */);
82
97
  const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
83
98
  if (config) {
84
- const { max, queue_max } = config;
99
+ const { max, idle, queue_max } = config;
85
100
  if (max > 0) {
86
101
  credential.connectionLimit ?? (credential.connectionLimit = max);
87
102
  }
103
+ if (idle >= 0) {
104
+ credential.idleTimeout ?? (credential.idleTimeout = idle);
105
+ }
88
106
  if (queue_max >= 0) {
89
107
  credential.queueLimit ?? (credential.queueLimit = queue_max);
90
108
  }
@@ -153,6 +171,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
153
171
  let close;
154
172
  switch (err instanceof Error && err.code) {
155
173
  case 'ER_ACCESS_DENIED_ERROR':
174
+ case 'ER_DBACCESS_DENIED_ERROR':
175
+ case 'ER_SPECIFIC_ACCESS_DENIED_ERROR':
176
+ case 'ER_ACCESS_DENIED_NO_PASSWORD_ERROR':
156
177
  close = 1;
157
178
  break;
158
179
  default:
@@ -261,7 +282,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
261
282
  commandType = this.commandType.SELECT;
262
283
  client
263
284
  .query(query, params)
264
- .on('error', err => error || (error = err))
265
285
  .on('result', row => {
266
286
  if (processRow) {
267
287
  const err = processRow(row);
@@ -275,13 +295,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
275
295
  }
276
296
  rows.push(row);
277
297
  })
298
+ .on('error', err => error || (error = err))
278
299
  .on('end', () => {
279
300
  if (error && this.handleFail(error, item, { errorQuery, commandType })) {
280
301
  reject(error);
281
302
  }
282
303
  else {
283
304
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
284
- resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
305
+ resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
285
306
  }
286
307
  });
287
308
  }
@@ -293,7 +314,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
293
314
  commandType = this.commandType.SELECT;
294
315
  const [rows] = await client.query(query, params);
295
316
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
296
- resolve(Array.isArray(rows) && !rows.some(row => row.constructor.name === 'OkPacket') ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
317
+ resolve(Array.isArray(rows) && !rows.some(row => {
318
+ const name = row.constructor.name;
319
+ return name === 'ResultSetHeader' || name === 'OkPacket';
320
+ }) ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
297
321
  }
298
322
  }
299
323
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "MySQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -23,6 +23,6 @@
23
23
  "dependencies": {
24
24
  "@e-mc/db": "^0.5.3",
25
25
  "@e-mc/types": "^0.5.3",
26
- "mysql2": "^3.3.1"
26
+ "mysql2": "^3.5.2"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -12,4 +12,4 @@ export interface MySQLDataSource<T = unknown> extends DbDataSource<string | Quer
12
12
 
13
13
  export interface MySQLCredential extends ServerAuth, Omit<PoolOptions, "ssl"> {
14
14
  ssl?: boolean | string | SecureContextOptions & { rejectUnauthorized?: boolean };
15
- }
15
+ }