@pi-r/mariadb 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.
Files changed (2) hide show
  1. package/client/index.js +18 -3
  2. package/package.json +1 -1
package/client/index.js CHANGED
@@ -50,6 +50,10 @@ function removeUUIDKey(credential) {
50
50
  }
51
51
  return credential;
52
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
+ }
53
57
  const getPoolKey = (credential) => (credential.host || '') + '_' + (credential.port || '3306') + (credential.user || '') + '_' + (credential.password || '') + '_' + (credential.database || '') + '_' + (credential.rowsAsArray ? '1' : '0');
54
58
  function setAuthentication(credential) {
55
59
  const auth = (0, util_1.parseServerAuth)(credential);
@@ -267,7 +271,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
267
271
  tasks[i] = new Promise(async (resolve, reject) => {
268
272
  let commandType;
269
273
  try {
270
- const client = mariaDBClient || await getConnection(item, credential);
274
+ const client = mariaDBClient || await getConnection(item, removeUUIDKey(credential));
271
275
  if (mariaDBClient && parallel) {
272
276
  mariaDBClient = undefined;
273
277
  }
@@ -302,9 +306,20 @@ async function executeBatchQuery(batch, options = '', outResult) {
302
306
  }
303
307
  }
304
308
  else {
305
- const rows = await client.query(query, params);
309
+ let rows = await client.query(query, params);
306
310
  this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
307
- resolve((0, types_1.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
+ }
308
323
  }
309
324
  }
310
325
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mariadb",
3
- "version": "0.2.2",
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",