@pi-r/mysql 0.2.5 → 0.2.6
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/client/index.js +18 -5
- 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) {
|
|
@@ -314,12 +325,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
314
325
|
commandType = this.commandType.SELECT;
|
|
315
326
|
let [rows] = await client.query(query, params);
|
|
316
327
|
this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
|
|
317
|
-
if (
|
|
318
|
-
if (rows.length === 2 && Array.isArray(rows[0]) && !Array.isArray(rows[
|
|
328
|
+
if ((0, types_1.isArray)(rows)) {
|
|
329
|
+
if (rows.length === 2 && Array.isArray(rows[0]) && !Array.isArray(rows[1]) && isResultSetHeader(rows[1])) {
|
|
319
330
|
rows = rows[0];
|
|
320
331
|
}
|
|
321
|
-
|
|
322
|
-
|
|
332
|
+
else if (isResultSetHeader(rows[0])) {
|
|
333
|
+
rows = [];
|
|
334
|
+
}
|
|
335
|
+
resolve(rows.length ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
|
|
323
336
|
}
|
|
324
337
|
else {
|
|
325
338
|
resolve(null);
|