@pi-r/mysql 0.6.5 → 0.7.0

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/README.md CHANGED
@@ -1,10 +1,7 @@
1
- # @pi-r/mysql
1
+ ### @pi-r/mysql
2
2
 
3
- ## Documentation
3
+ https://e-mc.readthedocs.io/en/latest/db/mysql.html
4
4
 
5
- - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mysql.html)
6
- - [squared](https://squared.readthedocs.io)
7
-
8
- ## LICENSE
5
+ ### LICENSE
9
6
 
10
7
  MIT
package/client/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
4
3
  const main = require("mysql2");
5
4
  const mysql = require("mysql2/promise");
@@ -31,7 +30,7 @@ function removePoolProperties(credential) {
31
30
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
32
31
  const attr = POOL_UNUSED[i];
33
32
  if (attr in credential) {
34
- result || (result = { ...credential });
33
+ result ||= { ...credential };
35
34
  if (attr !== 'ssl') {
36
35
  delete result[attr];
37
36
  }
@@ -71,8 +70,8 @@ function getPoolKey(credential) {
71
70
  }
72
71
  function setAuthentication(credential) {
73
72
  const auth = (0, util_1.parseServerAuth)(credential);
74
- credential.host || (credential.host = auth.hostname);
75
- credential.user || (credential.user = auth.username);
73
+ credential.host ||= auth.hostname;
74
+ credential.user ||= auth.username;
76
75
  if ((0, types_1.isPlainObject)(credential.ssl)) {
77
76
  this.readTLSConfig(credential.ssl);
78
77
  }
@@ -121,16 +120,16 @@ function setCredential(item) {
121
120
  if (config) {
122
121
  const { max, idle, queue_max, timeout } = config;
123
122
  if (max > 0) {
124
- credential.connectionLimit ?? (credential.connectionLimit = max);
123
+ credential.connectionLimit ??= max;
125
124
  }
126
125
  if (idle >= 0) {
127
- credential.idleTimeout ?? (credential.idleTimeout = idle);
126
+ credential.idleTimeout ??= idle;
128
127
  }
129
128
  if (queue_max >= 0) {
130
- credential.queueLimit ?? (credential.queueLimit = queue_max);
129
+ credential.queueLimit ??= queue_max;
131
130
  }
132
131
  if (timeout > 0) {
133
- credential.connectTimeout ?? (credential.connectTimeout = timeout);
132
+ credential.connectTimeout ??= timeout;
134
133
  }
135
134
  }
136
135
  const poolKey = getPoolKey(credential);
@@ -168,7 +167,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
168
167
  parallel = !batch.some(item => item.parallel === false);
169
168
  }
170
169
  if (!parallel) {
171
- outResult || (outResult = new Array(length));
170
+ outResult ||= new Array(length);
172
171
  }
173
172
  const caching = this.hasCache("mysql", sessionKey);
174
173
  const tasks = new Array(length);
@@ -234,7 +233,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
234
233
  for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
235
234
  const item = batch[i];
236
235
  const { source, query, params, ignoreCache } = item;
237
- const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
236
+ const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
238
237
  let credential, error;
239
238
  if (streamRow) {
240
239
  if (mysql2Credential) {
@@ -266,8 +265,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
266
265
  let queryString = '';
267
266
  if (caching && ignoreCache !== true && !streamRow) {
268
267
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
269
- const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
270
268
  if (ignoreCache !== 1) {
269
+ const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
271
270
  if (result) {
272
271
  if (parallel) {
273
272
  tasks[i] = Promise.resolve(result);
@@ -323,7 +322,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
323
322
  }
324
323
  rows.push(row);
325
324
  })
326
- .on('error', err => error || (error = err))
325
+ .on('error', err => error ||= err)
327
326
  .on('end', () => {
328
327
  if (error && this.handleFail(error, item, { errorQuery, commandType })) {
329
328
  reject(error);
@@ -377,8 +376,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
377
376
  }
378
377
  return this.processRows(batch, tasks, {
379
378
  disconnect: () => {
380
- clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
381
- pools.forEach(item => item.release());
379
+ clients.forEach(item => {
380
+ item.end(err => {
381
+ if (err) {
382
+ this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false });
383
+ }
384
+ });
385
+ });
386
+ pools.forEach(item => {
387
+ item.release();
388
+ });
382
389
  },
383
390
  parallel
384
391
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "MySQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.6",
25
- "@e-mc/types": "^0.8.6",
26
- "mysql2": "^3.9.2"
24
+ "@e-mc/db": "^0.9.0",
25
+ "@e-mc/types": "^0.9.0",
26
+ "mysql2": "^3.9.7"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { SecureContextOptions } from 'tls';
6
6
 
7
7
  import type { PoolOptions, QueryOptions } from 'mysql2/promise';
8
8
 
9
- export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown, string | MySQLCredential, string>, ExecuteAction<T> {
9
+ export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown, MySQLCredential, string>, ExecuteAction<T> {
10
10
  source: "mysql";
11
11
  }
12
12