@pi-r/mariadb 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 +40 -28
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -7,10 +7,10 @@ const types_1 = require("@e-mc/types");
|
|
|
7
7
|
const Db = require("@e-mc/db");
|
|
8
8
|
const DbPool = require('@e-mc/db/pool');
|
|
9
9
|
class MariaDBPool extends DbPool {
|
|
10
|
-
getConnection() {
|
|
10
|
+
async getConnection() {
|
|
11
11
|
return this.client.getConnection();
|
|
12
12
|
}
|
|
13
|
-
close() {
|
|
13
|
+
async close() {
|
|
14
14
|
return this.client.end();
|
|
15
15
|
}
|
|
16
16
|
isEmpty() {
|
|
@@ -99,33 +99,42 @@ function setCredential(item) {
|
|
|
99
99
|
throw (0, types_1.errorMessage)("mariadb" /* STRINGS.MODULE_NAME */, 'Not defined - ' + errors.join(' | '));
|
|
100
100
|
}
|
|
101
101
|
const usePool = item.usePool;
|
|
102
|
-
if (usePool) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
if (!usePool) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
let username, password, pool;
|
|
106
|
+
if (typeof usePool === 'string' && (username = credential.user)) {
|
|
107
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
108
|
+
if (pool) {
|
|
109
|
+
pool.add(item, password);
|
|
110
|
+
return;
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
}
|
|
113
|
+
const poolKey = getPoolKey(credential);
|
|
114
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
115
|
+
pool.add(item);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const config = this.getPoolConfig("mariadb" /* STRINGS.MODULE_NAME */, password);
|
|
119
|
+
if (config) {
|
|
120
|
+
const { min, max, idle, timeout, socket_timeout } = config;
|
|
121
|
+
if (min >= 0) {
|
|
122
|
+
credential.minimumIdle ?? (credential.minimumIdle = min);
|
|
123
|
+
}
|
|
124
|
+
if (max > 0) {
|
|
125
|
+
credential.connectionLimit ?? (credential.connectionLimit = max);
|
|
124
126
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
if (idle >= 0) {
|
|
128
|
+
credential.idleTimeout ?? (credential.idleTimeout = idle);
|
|
129
|
+
}
|
|
130
|
+
if (timeout > 0) {
|
|
131
|
+
credential.connectTimeout ?? (credential.connectTimeout = timeout);
|
|
132
|
+
}
|
|
133
|
+
if (socket_timeout > 0) {
|
|
134
|
+
credential.socketTimeout ?? (credential.socketTimeout = socket_timeout);
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
new MariaDBPool(mariadb.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
129
138
|
}
|
|
130
139
|
exports.setCredential = setCredential;
|
|
131
140
|
async function executeQuery(item, options) {
|
|
@@ -213,6 +222,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
213
222
|
item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
|
|
214
223
|
return client;
|
|
215
224
|
};
|
|
225
|
+
if (this.host?.username) {
|
|
226
|
+
this.applyCommand(...batch);
|
|
227
|
+
}
|
|
216
228
|
for (let i = 0; i < length; ++i) {
|
|
217
229
|
const item = batch[i];
|
|
218
230
|
const { source, query, params, ignoreCache } = item;
|
|
@@ -342,14 +354,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
342
354
|
}
|
|
343
355
|
return this.processRows(batch, tasks, {
|
|
344
356
|
disconnect: () => {
|
|
345
|
-
clients.forEach(item => item.end());
|
|
346
|
-
pools.forEach(item => item.release());
|
|
357
|
+
clients.forEach(async (item) => item.end());
|
|
358
|
+
pools.forEach(async (item) => item.release());
|
|
347
359
|
},
|
|
348
360
|
parallel
|
|
349
361
|
}, outResult);
|
|
350
362
|
}
|
|
351
363
|
exports.executeBatchQuery = executeBatchQuery;
|
|
352
|
-
function checkTimeout(value, limit = 0) {
|
|
364
|
+
async function checkTimeout(value, limit = 0) {
|
|
353
365
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
354
366
|
}
|
|
355
367
|
exports.checkTimeout = checkTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mariadb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "MariaDB 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
|
-
"mariadb": "^3.2.
|
|
24
|
+
"@e-mc/db": "^0.8.0",
|
|
25
|
+
"@e-mc/types": "^0.8.0",
|
|
26
|
+
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|