@pi-r/mysql 0.3.0 → 0.6.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/client/index.js +36 -30
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -8,10 +8,10 @@ const types_1 = require("@e-mc/types");
|
|
|
8
8
|
const Db = require("@e-mc/db");
|
|
9
9
|
const DbPool = require('@e-mc/db/pool');
|
|
10
10
|
class MySQLPool extends DbPool {
|
|
11
|
-
getConnection() {
|
|
11
|
+
async getConnection() {
|
|
12
12
|
return this.client.getConnection();
|
|
13
13
|
}
|
|
14
|
-
close() {
|
|
14
|
+
async close() {
|
|
15
15
|
return this.client.end();
|
|
16
16
|
}
|
|
17
17
|
isEmpty() {
|
|
@@ -95,36 +95,39 @@ function setCredential(item) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
const usePool = item.usePool;
|
|
98
|
-
if (usePool) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
98
|
+
if (!usePool) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
let username, password, pool;
|
|
102
|
+
if (typeof usePool === 'string' && (username = credential.user || credential.uri && (0, util_1.parseConnectionString)(credential.uri)?.username)) {
|
|
103
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
104
|
+
if (pool) {
|
|
105
|
+
pool.add(item, password);
|
|
106
|
+
return;
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (queue_max >= 0) {
|
|
119
|
-
credential.queueLimit ?? (credential.queueLimit = queue_max);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
new MySQLPool(mysql.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
108
|
+
}
|
|
109
|
+
const poolKey = getPoolKey(credential);
|
|
110
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
111
|
+
pool.add(item);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const config = this.getPoolConfig("mysql" /* STRINGS.MODULE_NAME */, password);
|
|
115
|
+
if (config) {
|
|
116
|
+
const { max, idle, queue_max, timeout } = config;
|
|
117
|
+
if (max > 0) {
|
|
118
|
+
credential.connectionLimit ?? (credential.connectionLimit = max);
|
|
123
119
|
}
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
if (idle >= 0) {
|
|
121
|
+
credential.idleTimeout ?? (credential.idleTimeout = idle);
|
|
122
|
+
}
|
|
123
|
+
if (queue_max >= 0) {
|
|
124
|
+
credential.queueLimit ?? (credential.queueLimit = queue_max);
|
|
125
|
+
}
|
|
126
|
+
if (timeout > 0) {
|
|
127
|
+
credential.connectTimeout ?? (credential.connectTimeout = timeout);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
130
|
+
new MySQLPool(mysql.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
128
131
|
}
|
|
129
132
|
exports.setCredential = setCredential;
|
|
130
133
|
async function executeQuery(item, options) {
|
|
@@ -212,6 +215,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
212
215
|
item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
|
|
213
216
|
return client;
|
|
214
217
|
};
|
|
218
|
+
if (this.host?.username) {
|
|
219
|
+
this.applyCommand(...batch);
|
|
220
|
+
}
|
|
215
221
|
for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
|
|
216
222
|
const item = batch[i];
|
|
217
223
|
const { source, query, params, ignoreCache } = item;
|
|
@@ -359,14 +365,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
359
365
|
}
|
|
360
366
|
return this.processRows(batch, tasks, {
|
|
361
367
|
disconnect: () => {
|
|
362
|
-
clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "mysql" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false })));
|
|
368
|
+
clients.forEach(async (item) => item.end(err => err && this.writeFail(["Unable to close connnection" /* ERR_DB.CONNECTION_CLOSE */, "mysql" /* STRINGS.MODULE_NAME */], err, { type: 65536 /* LOG_TYPE.DB */, fatal: false })));
|
|
363
369
|
pools.forEach(item => item.release());
|
|
364
370
|
},
|
|
365
371
|
parallel
|
|
366
372
|
}, outResult);
|
|
367
373
|
}
|
|
368
374
|
exports.executeBatchQuery = executeBatchQuery;
|
|
369
|
-
function checkTimeout(value, limit = 0) {
|
|
375
|
+
async function checkTimeout(value, limit = 0) {
|
|
370
376
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
371
377
|
}
|
|
372
378
|
exports.checkTimeout = checkTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mysql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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.6.
|
|
24
|
+
"@e-mc/db": "^0.8.0",
|
|
25
|
+
"@e-mc/types": "^0.8.0",
|
|
26
|
+
"mysql2": "^3.6.5"
|
|
27
27
|
}
|
|
28
28
|
}
|