@pi-r/mysql 0.6.4 → 0.6.5
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 -13
- 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
|
@@ -96,7 +96,7 @@ function setCredential(item) {
|
|
|
96
96
|
errors.push('user');
|
|
97
97
|
}
|
|
98
98
|
if (errors.length) {
|
|
99
|
-
throw (0, types_1.errorMessage)("mysql"
|
|
99
|
+
throw (0, types_1.errorMessage)("mysql", 'Not defined - ' + errors.join(' | '));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
const usePool = item.usePool;
|
|
@@ -117,7 +117,7 @@ function setCredential(item) {
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
const config = this.getPoolConfig("mysql"
|
|
120
|
+
const config = this.getPoolConfig("mysql", password);
|
|
121
121
|
if (config) {
|
|
122
122
|
const { max, idle, queue_max, timeout } = config;
|
|
123
123
|
if (max > 0) {
|
|
@@ -170,17 +170,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
170
170
|
if (!parallel) {
|
|
171
171
|
outResult || (outResult = new Array(length));
|
|
172
172
|
}
|
|
173
|
-
const caching = this.hasCache("mysql"
|
|
173
|
+
const caching = this.hasCache("mysql", sessionKey);
|
|
174
174
|
const tasks = new Array(length);
|
|
175
175
|
const clients = [];
|
|
176
176
|
const pools = [];
|
|
177
177
|
let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
178
178
|
const getConnection = async (item, credential) => {
|
|
179
|
-
item.transactionState = 64
|
|
179
|
+
item.transactionState = 64;
|
|
180
180
|
let client;
|
|
181
181
|
if (mysqlPool) {
|
|
182
182
|
pools.push(client = await mysqlPool.getConnection());
|
|
183
|
-
item.transactionState &= ~64
|
|
183
|
+
item.transactionState &= ~64;
|
|
184
184
|
POOL_ACTIVE.add(credential);
|
|
185
185
|
return client;
|
|
186
186
|
}
|
|
@@ -225,7 +225,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
225
225
|
}
|
|
226
226
|
mysqlCredential = credential;
|
|
227
227
|
}
|
|
228
|
-
item.transactionState &= ~64
|
|
228
|
+
item.transactionState &= ~64;
|
|
229
229
|
return client;
|
|
230
230
|
};
|
|
231
231
|
if (this.host?.username) {
|
|
@@ -234,7 +234,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
234
234
|
for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
|
|
235
235
|
const item = batch[i];
|
|
236
236
|
const { source, query, params, ignoreCache } = item;
|
|
237
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql"
|
|
237
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
238
238
|
let credential, error;
|
|
239
239
|
if (streamRow) {
|
|
240
240
|
if (mysql2Credential) {
|
|
@@ -245,7 +245,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
245
245
|
else if (credential = mysqlCredential || onceCredential) {
|
|
246
246
|
error = null;
|
|
247
247
|
}
|
|
248
|
-
if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
248
|
+
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
249
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
250
250
|
if (!parallel) {
|
|
251
251
|
tasks.length = 0;
|
|
@@ -261,7 +261,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
261
261
|
}
|
|
262
262
|
continue;
|
|
263
263
|
}
|
|
264
|
-
item.transactionState = 1
|
|
264
|
+
item.transactionState = 1;
|
|
265
265
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
266
266
|
let queryString = '';
|
|
267
267
|
if (caching && ignoreCache !== true && !streamRow) {
|
|
@@ -275,7 +275,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
275
275
|
else {
|
|
276
276
|
outResult[i] = result;
|
|
277
277
|
}
|
|
278
|
-
this.add(item, 4
|
|
278
|
+
this.add(item, 4 | 128);
|
|
279
279
|
continue;
|
|
280
280
|
}
|
|
281
281
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -329,7 +329,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
329
329
|
reject(error);
|
|
330
330
|
}
|
|
331
331
|
else {
|
|
332
|
-
this.add(item, 4
|
|
332
|
+
this.add(item, 4);
|
|
333
333
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
|
|
334
334
|
}
|
|
335
335
|
});
|
|
@@ -341,7 +341,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
341
341
|
}
|
|
342
342
|
commandType = this.commandType.SELECT;
|
|
343
343
|
const [rows] = await client.query(query, params);
|
|
344
|
-
this.add(item, 4
|
|
344
|
+
this.add(item, 4);
|
|
345
345
|
if ((0, types_1.isArray)(rows)) {
|
|
346
346
|
const [row1, row2] = rows;
|
|
347
347
|
if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
|
|
@@ -377,7 +377,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
377
377
|
}
|
|
378
378
|
return this.processRows(batch, tasks, {
|
|
379
379
|
disconnect: () => {
|
|
380
|
-
clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection"
|
|
380
|
+
clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
|
|
381
381
|
pools.forEach(item => item.release());
|
|
382
382
|
},
|
|
383
383
|
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.5",
|
|
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.6",
|
|
25
|
+
"@e-mc/types": "^0.8.6",
|
|
26
|
+
"mysql2": "^3.9.2"
|
|
27
27
|
}
|
|
28
28
|
}
|