@pi-r/mariadb 0.2.1 → 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.
Files changed (2) hide show
  1. package/client/index.js +36 -6
  2. package/package.json +2 -2
package/client/index.js CHANGED
@@ -21,9 +21,25 @@ class MariaDBPool extends DbPool {
21
21
  }
22
22
  }
23
23
  const POOL_STATE = {};
24
+ const POOL_UNUSED = ['ssl', 'connectTimeout', 'socketTimeout', 'compress', 'keepAliveDelay', 'acquireTimeout', 'connectionLimit', 'idleTimeout', 'initializationTimeout', 'minDelayValidation', 'minimumIdle', 'resetAfterUse', 'noControlAfterUse', 'leakDetectionTimeout'];
24
25
  function removePoolProperties(credential) {
25
- if (!credential.uuidKey && ('ssl' in credential || 'connectionLimit' in credential || 'connectTimeout' in credential || 'idleTimeout' in credential || 'minimumIdle' in credential || 'resetAfterUse' in credential || 'noControlAfterUse' in credential)) {
26
- return { ...credential, ssl: (0, types_1.isObject)(credential.ssl) ? true : undefined, connectionLimit: undefined, idleTimeout: undefined, connectTimeout: undefined, minimumIdle: undefined, resetAfterUse: undefined, noControlAfterUse: 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,10 +47,13 @@ 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
  }
53
+ function isOkPacket(value) {
54
+ const result = Array.isArray(value) ? value[0] : value;
55
+ return !!result && !Array.isArray(result) && result.constructor.name === 'OkPacket';
56
+ }
38
57
  const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '3306') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.rowsAsArray ? '1' : '0');
39
58
  function setAuthentication(credential) {
40
59
  const auth = (0, util_1.parseServerAuth)(credential);
@@ -252,7 +271,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
252
271
  tasks[i] = new Promise(async (resolve, reject) => {
253
272
  let commandType;
254
273
  try {
255
- const client = mariaDBClient || await getConnection(item, credential);
274
+ const client = mariaDBClient || await getConnection(item, removeUUIDKey(credential));
256
275
  if (mariaDBClient && parallel) {
257
276
  mariaDBClient = undefined;
258
277
  }
@@ -287,9 +306,20 @@ async function executeBatchQuery(batch, options = '', outResult) {
287
306
  }
288
307
  }
289
308
  else {
290
- const rows = await client.query(query, params);
309
+ let rows = await client.query(query, params);
291
310
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
292
- resolve(Array.isArray(rows) ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
311
+ if ((0, types_1.isArray)(rows)) {
312
+ if (rows.length === 2 && Array.isArray(rows[0]) && !Array.isArray(rows[1]) && isOkPacket(rows[1])) {
313
+ rows = rows[0];
314
+ }
315
+ else if (isOkPacket(rows[0])) {
316
+ rows = [];
317
+ }
318
+ resolve(rows.length ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
319
+ }
320
+ else {
321
+ resolve(null);
322
+ }
293
323
  }
294
324
  }
295
325
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "MariaDB 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
- "mariadb": "^3.1.2"
26
+ "mariadb": "^3.2.0"
27
27
  }
28
28
  }