@pi-r/mysql 0.2.5 → 0.2.7

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 +20 -7
  2. package/package.json +1 -1
package/client/index.js CHANGED
@@ -50,6 +50,17 @@ function removeUUIDKey(credential) {
50
50
  }
51
51
  return credential;
52
52
  }
53
+ function isResultSetHeader(value) {
54
+ const result = Array.isArray(value) ? value[0] : value;
55
+ if (result && !Array.isArray(result)) {
56
+ switch (result.constructor.name) {
57
+ case 'ResultSetHeader':
58
+ case 'OkPacket':
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
53
64
  const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '3306') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.uri || '') + '_' + (credential.rowsAsArray ? '1' : '0');
54
65
  function setAuthentication(credential) {
55
66
  const auth = (0, util_1.parseServerAuth)(credential);
@@ -271,7 +282,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
271
282
  const rows = [];
272
283
  const processRow = typeof streamRow === 'function' && streamRow;
273
284
  const { createConnection } = require("mysql2" /* STRINGS.PACKAGE_STREAM */);
274
- const client = mysql2Client || createConnection((mysql2Credential || credential));
285
+ const client = mysql2Client || createConnection(removeUUIDKey(mysql2Credential || credential));
275
286
  clients.push(client);
276
287
  if (connectOnce) {
277
288
  if (!parallel) {
@@ -312,14 +323,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
312
323
  mysqlClient = undefined;
313
324
  }
314
325
  commandType = this.commandType.SELECT;
315
- let [rows] = await client.query(query, params);
326
+ const [rows] = await client.query(query, params);
316
327
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
317
- if (Array.isArray(rows)) {
318
- if (rows.length === 2 && Array.isArray(rows[0]) && !Array.isArray(rows[0])) {
319
- rows = rows[0];
328
+ if ((0, types_1.isArray)(rows)) {
329
+ const [row1, row2] = rows;
330
+ if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
331
+ resolve(row1);
332
+ }
333
+ else {
334
+ resolve(!isResultSetHeader(row1) ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
320
335
  }
321
- rows = rows.filter(row => Array.isArray(row) || !('affectedRows' in row && 'fieldCount' in row && 'serverStatus' in row));
322
- resolve((0, types_1.isArray)(rows) ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
323
336
  }
324
337
  else {
325
338
  resolve(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mysql",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "MySQL client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",