@pi-r/mysql 0.6.7 → 0.7.1

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
@@ -30,7 +30,7 @@ function removePoolProperties(credential) {
30
30
  for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
31
31
  const attr = POOL_UNUSED[i];
32
32
  if (attr in credential) {
33
- result || (result = { ...credential });
33
+ result ||= { ...credential };
34
34
  if (attr !== 'ssl') {
35
35
  delete result[attr];
36
36
  }
@@ -70,15 +70,14 @@ function getPoolKey(credential) {
70
70
  }
71
71
  function setAuthentication(credential) {
72
72
  const auth = (0, util_1.parseServerAuth)(credential);
73
- credential.host || (credential.host = auth.hostname);
74
- credential.user || (credential.user = auth.username);
73
+ credential.host ||= auth.hostname;
74
+ credential.user ||= auth.username;
75
75
  if ((0, types_1.isPlainObject)(credential.ssl)) {
76
76
  this.readTLSConfig(credential.ssl);
77
77
  }
78
78
  }
79
79
  exports.setAuthentication = setAuthentication;
80
80
  function setCredential(item) {
81
- var _a, _b, _c, _d, _e;
82
81
  let credential = this.getCredential(item);
83
82
  if (credential) {
84
83
  setAuthentication.call(this, credential);
@@ -105,7 +104,7 @@ function setCredential(item) {
105
104
  }
106
105
  let username, password, pool;
107
106
  if ((0, types_1.isString)(usePool)) {
108
- if (username = credential.user || credential.uri && ((_a = (0, util_1.parseConnectionString)(credential.uri)) === null || _a === void 0 ? void 0 : _a.username)) {
107
+ if (username = credential.user || credential.uri && (0, util_1.parseConnectionString)(credential.uri)?.username) {
109
108
  [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
110
109
  if (pool) {
111
110
  pool.add(item, password);
@@ -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
- (_b = credential.connectionLimit) !== null && _b !== void 0 ? _b : (credential.connectionLimit = max);
123
+ credential.connectionLimit ??= max;
125
124
  }
126
125
  if (idle >= 0) {
127
- (_c = credential.idleTimeout) !== null && _c !== void 0 ? _c : (credential.idleTimeout = idle);
126
+ credential.idleTimeout ??= idle;
128
127
  }
129
128
  if (queue_max >= 0) {
130
- (_d = credential.queueLimit) !== null && _d !== void 0 ? _d : (credential.queueLimit = queue_max);
129
+ credential.queueLimit ??= queue_max;
131
130
  }
132
131
  if (timeout > 0) {
133
- (_e = credential.connectTimeout) !== null && _e !== void 0 ? _e : (credential.connectTimeout = timeout);
132
+ credential.connectTimeout ??= timeout;
134
133
  }
135
134
  }
136
135
  const poolKey = getPoolKey(credential);
@@ -146,7 +145,6 @@ async function executeQuery(item, options) {
146
145
  }
147
146
  exports.executeQuery = executeQuery;
148
147
  async function executeBatchQuery(batch, options = '', outResult) {
149
- var _a;
150
148
  const length = batch.length;
151
149
  if (length === 0) {
152
150
  return [];
@@ -169,7 +167,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
169
167
  parallel = !batch.some(item => item.parallel === false);
170
168
  }
171
169
  if (!parallel) {
172
- outResult || (outResult = new Array(length));
170
+ outResult ||= new Array(length);
173
171
  }
174
172
  const caching = this.hasCache("mysql", sessionKey);
175
173
  const tasks = new Array(length);
@@ -229,13 +227,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
229
227
  item.transactionState &= ~64;
230
228
  return client;
231
229
  };
232
- if ((_a = this.host) === null || _a === void 0 ? void 0 : _a.username) {
230
+ if (this.host?.username) {
233
231
  this.applyCommand(...batch);
234
232
  }
235
233
  for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
236
234
  const item = batch[i];
237
235
  const { source, query, params, ignoreCache } = item;
238
- 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;
239
237
  let credential, error;
240
238
  if (streamRow) {
241
239
  if (mysql2Credential) {
@@ -267,8 +265,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
267
265
  let queryString = '';
268
266
  if (caching && ignoreCache !== true && !streamRow) {
269
267
  queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
270
- const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
271
268
  if (ignoreCache !== 1) {
269
+ const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
272
270
  if (result) {
273
271
  if (parallel) {
274
272
  tasks[i] = Promise.resolve(result);
@@ -324,7 +322,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
324
322
  }
325
323
  rows.push(row);
326
324
  })
327
- .on('error', err => error || (error = err))
325
+ .on('error', err => error ||= err)
328
326
  .on('end', () => {
329
327
  if (error && this.handleFail(error, item, { errorQuery, commandType })) {
330
328
  reject(error);
@@ -378,8 +376,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
378
376
  }
379
377
  return this.processRows(batch, tasks, {
380
378
  disconnect: () => {
381
- clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
382
- 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
+ });
383
389
  },
384
390
  parallel
385
391
  }, outResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.6.7",
3
+ "version": "0.7.1",
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.8",
25
- "@e-mc/types": "^0.8.8",
26
- "mysql2": "^3.9.3"
24
+ "@e-mc/db": "^0.9.2",
25
+ "@e-mc/types": "^0.9.2",
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