@pi-r/mysql 0.6.4 → 0.6.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/LICENSE +1 -1
- package/README.md +6 -3
- package/client/index.js +13 -14
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# @pi-r/mysql
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/db/mysql.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
6
9
|
|
|
7
10
|
MIT
|
package/client/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = exports.setAuthentication = void 0;
|
|
4
3
|
const main = require("mysql2");
|
|
5
4
|
const mysql = require("mysql2/promise");
|
|
@@ -96,7 +95,7 @@ function setCredential(item) {
|
|
|
96
95
|
errors.push('user');
|
|
97
96
|
}
|
|
98
97
|
if (errors.length) {
|
|
99
|
-
throw (0, types_1.errorMessage)("mysql"
|
|
98
|
+
throw (0, types_1.errorMessage)("mysql", 'Not defined - ' + errors.join(' | '));
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
const usePool = item.usePool;
|
|
@@ -117,7 +116,7 @@ function setCredential(item) {
|
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
118
|
}
|
|
120
|
-
const config = this.getPoolConfig("mysql"
|
|
119
|
+
const config = this.getPoolConfig("mysql", password);
|
|
121
120
|
if (config) {
|
|
122
121
|
const { max, idle, queue_max, timeout } = config;
|
|
123
122
|
if (max > 0) {
|
|
@@ -170,17 +169,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
170
169
|
if (!parallel) {
|
|
171
170
|
outResult || (outResult = new Array(length));
|
|
172
171
|
}
|
|
173
|
-
const caching = this.hasCache("mysql"
|
|
172
|
+
const caching = this.hasCache("mysql", sessionKey);
|
|
174
173
|
const tasks = new Array(length);
|
|
175
174
|
const clients = [];
|
|
176
175
|
const pools = [];
|
|
177
176
|
let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
178
177
|
const getConnection = async (item, credential) => {
|
|
179
|
-
item.transactionState = 64
|
|
178
|
+
item.transactionState = 64;
|
|
180
179
|
let client;
|
|
181
180
|
if (mysqlPool) {
|
|
182
181
|
pools.push(client = await mysqlPool.getConnection());
|
|
183
|
-
item.transactionState &= ~64
|
|
182
|
+
item.transactionState &= ~64;
|
|
184
183
|
POOL_ACTIVE.add(credential);
|
|
185
184
|
return client;
|
|
186
185
|
}
|
|
@@ -225,7 +224,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
225
224
|
}
|
|
226
225
|
mysqlCredential = credential;
|
|
227
226
|
}
|
|
228
|
-
item.transactionState &= ~64
|
|
227
|
+
item.transactionState &= ~64;
|
|
229
228
|
return client;
|
|
230
229
|
};
|
|
231
230
|
if (this.host?.username) {
|
|
@@ -234,7 +233,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
234
233
|
for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
|
|
235
234
|
const item = batch[i];
|
|
236
235
|
const { source, query, params, ignoreCache } = item;
|
|
237
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql"
|
|
236
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
238
237
|
let credential, error;
|
|
239
238
|
if (streamRow) {
|
|
240
239
|
if (mysql2Credential) {
|
|
@@ -245,7 +244,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
245
244
|
else if (credential = mysqlCredential || onceCredential) {
|
|
246
245
|
error = null;
|
|
247
246
|
}
|
|
248
|
-
if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
247
|
+
if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
|
|
249
248
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
250
249
|
if (!parallel) {
|
|
251
250
|
tasks.length = 0;
|
|
@@ -261,7 +260,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
261
260
|
}
|
|
262
261
|
continue;
|
|
263
262
|
}
|
|
264
|
-
item.transactionState = 1
|
|
263
|
+
item.transactionState = 1;
|
|
265
264
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
266
265
|
let queryString = '';
|
|
267
266
|
if (caching && ignoreCache !== true && !streamRow) {
|
|
@@ -275,7 +274,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
275
274
|
else {
|
|
276
275
|
outResult[i] = result;
|
|
277
276
|
}
|
|
278
|
-
this.add(item, 4
|
|
277
|
+
this.add(item, 4 | 128);
|
|
279
278
|
continue;
|
|
280
279
|
}
|
|
281
280
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -329,7 +328,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
329
328
|
reject(error);
|
|
330
329
|
}
|
|
331
330
|
else {
|
|
332
|
-
this.add(item, 4
|
|
331
|
+
this.add(item, 4);
|
|
333
332
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
|
|
334
333
|
}
|
|
335
334
|
});
|
|
@@ -341,7 +340,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
341
340
|
}
|
|
342
341
|
commandType = this.commandType.SELECT;
|
|
343
342
|
const [rows] = await client.query(query, params);
|
|
344
|
-
this.add(item, 4
|
|
343
|
+
this.add(item, 4);
|
|
345
344
|
if ((0, types_1.isArray)(rows)) {
|
|
346
345
|
const [row1, row2] = rows;
|
|
347
346
|
if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
|
|
@@ -377,7 +376,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
377
376
|
}
|
|
378
377
|
return this.processRows(batch, tasks, {
|
|
379
378
|
disconnect: () => {
|
|
380
|
-
clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection"
|
|
379
|
+
clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
|
|
381
380
|
pools.forEach(item => item.release());
|
|
382
381
|
},
|
|
383
382
|
parallel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mysql",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
26
|
-
"mysql2": "^3.9.
|
|
24
|
+
"@e-mc/db": "^0.8.7",
|
|
25
|
+
"@e-mc/types": "^0.8.7",
|
|
26
|
+
"mysql2": "^3.9.3"
|
|
27
27
|
}
|
|
28
28
|
}
|