@pi-r/mysql 0.6.6 → 0.7.0
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/README.md +3 -6
- package/client/index.js +21 -13
- package/package.json +4 -4
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
### @pi-r/mysql
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/db/mysql.html
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- [squared](https://squared.readthedocs.io)
|
|
7
|
-
|
|
8
|
-
## LICENSE
|
|
5
|
+
### LICENSE
|
|
9
6
|
|
|
10
7
|
MIT
|
package/client/index.js
CHANGED
|
@@ -30,7 +30,7 @@ function removePoolProperties(credential) {
|
|
|
30
30
|
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
31
31
|
const attr = POOL_UNUSED[i];
|
|
32
32
|
if (attr in credential) {
|
|
33
|
-
result
|
|
33
|
+
result ||= { ...credential };
|
|
34
34
|
if (attr !== 'ssl') {
|
|
35
35
|
delete result[attr];
|
|
36
36
|
}
|
|
@@ -70,8 +70,8 @@ function getPoolKey(credential) {
|
|
|
70
70
|
}
|
|
71
71
|
function setAuthentication(credential) {
|
|
72
72
|
const auth = (0, util_1.parseServerAuth)(credential);
|
|
73
|
-
credential.host
|
|
74
|
-
credential.user
|
|
73
|
+
credential.host ||= auth.hostname;
|
|
74
|
+
credential.user ||= auth.username;
|
|
75
75
|
if ((0, types_1.isPlainObject)(credential.ssl)) {
|
|
76
76
|
this.readTLSConfig(credential.ssl);
|
|
77
77
|
}
|
|
@@ -120,16 +120,16 @@ function setCredential(item) {
|
|
|
120
120
|
if (config) {
|
|
121
121
|
const { max, idle, queue_max, timeout } = config;
|
|
122
122
|
if (max > 0) {
|
|
123
|
-
credential.connectionLimit
|
|
123
|
+
credential.connectionLimit ??= max;
|
|
124
124
|
}
|
|
125
125
|
if (idle >= 0) {
|
|
126
|
-
credential.idleTimeout
|
|
126
|
+
credential.idleTimeout ??= idle;
|
|
127
127
|
}
|
|
128
128
|
if (queue_max >= 0) {
|
|
129
|
-
credential.queueLimit
|
|
129
|
+
credential.queueLimit ??= queue_max;
|
|
130
130
|
}
|
|
131
131
|
if (timeout > 0) {
|
|
132
|
-
credential.connectTimeout
|
|
132
|
+
credential.connectTimeout ??= timeout;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
const poolKey = getPoolKey(credential);
|
|
@@ -167,7 +167,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
167
167
|
parallel = !batch.some(item => item.parallel === false);
|
|
168
168
|
}
|
|
169
169
|
if (!parallel) {
|
|
170
|
-
outResult
|
|
170
|
+
outResult ||= new Array(length);
|
|
171
171
|
}
|
|
172
172
|
const caching = this.hasCache("mysql", sessionKey);
|
|
173
173
|
const tasks = new Array(length);
|
|
@@ -233,7 +233,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
233
233
|
for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
|
|
234
234
|
const item = batch[i];
|
|
235
235
|
const { source, query, params, ignoreCache } = item;
|
|
236
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options',
|
|
236
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
237
237
|
let credential, error;
|
|
238
238
|
if (streamRow) {
|
|
239
239
|
if (mysql2Credential) {
|
|
@@ -265,8 +265,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
265
265
|
let queryString = '';
|
|
266
266
|
if (caching && ignoreCache !== true && !streamRow) {
|
|
267
267
|
queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
|
|
268
|
-
const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
|
|
269
268
|
if (ignoreCache !== 1) {
|
|
269
|
+
const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
|
|
270
270
|
if (result) {
|
|
271
271
|
if (parallel) {
|
|
272
272
|
tasks[i] = Promise.resolve(result);
|
|
@@ -322,7 +322,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
322
322
|
}
|
|
323
323
|
rows.push(row);
|
|
324
324
|
})
|
|
325
|
-
.on('error', err => error
|
|
325
|
+
.on('error', err => error ||= err)
|
|
326
326
|
.on('end', () => {
|
|
327
327
|
if (error && this.handleFail(error, item, { errorQuery, commandType })) {
|
|
328
328
|
reject(error);
|
|
@@ -376,8 +376,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
376
376
|
}
|
|
377
377
|
return this.processRows(batch, tasks, {
|
|
378
378
|
disconnect: () => {
|
|
379
|
-
clients.forEach(
|
|
380
|
-
|
|
379
|
+
clients.forEach(item => {
|
|
380
|
+
item.end(err => {
|
|
381
|
+
if (err) {
|
|
382
|
+
this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false });
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
pools.forEach(item => {
|
|
387
|
+
item.release();
|
|
388
|
+
});
|
|
381
389
|
},
|
|
382
390
|
parallel
|
|
383
391
|
}, outResult);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mysql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"mysql2": "^3.9.
|
|
24
|
+
"@e-mc/db": "^0.9.0",
|
|
25
|
+
"@e-mc/types": "^0.9.0",
|
|
26
|
+
"mysql2": "^3.9.7"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { SecureContextOptions } from 'tls';
|
|
|
6
6
|
|
|
7
7
|
import type { PoolOptions, QueryOptions } from 'mysql2/promise';
|
|
8
8
|
|
|
9
|
-
export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown,
|
|
9
|
+
export interface MySQLDataSource<T = unknown> extends DbDataSource<string | QueryOptions, unknown, unknown, MySQLCredential, string>, ExecuteAction<T> {
|
|
10
10
|
source: "mysql";
|
|
11
11
|
}
|
|
12
12
|
|