@pi-r/mariadb 0.5.0 → 0.6.1
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 +42 -40
- 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,42 +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
|
-
|
|
124
|
-
|
|
125
|
-
if (timeout > 0) {
|
|
126
|
-
credential.connectTimeout ?? (credential.connectTimeout = timeout);
|
|
127
|
-
}
|
|
128
|
-
if (socket_timeout > 0) {
|
|
129
|
-
credential.socketTimeout ?? (credential.socketTimeout = socket_timeout);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
new MariaDBPool(mariadb.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
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);
|
|
133
126
|
}
|
|
134
|
-
|
|
135
|
-
|
|
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);
|
|
136
135
|
}
|
|
137
136
|
}
|
|
137
|
+
new MariaDBPool(mariadb.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
138
138
|
}
|
|
139
139
|
exports.setCredential = setCredential;
|
|
140
140
|
async function executeQuery(item, options) {
|
|
@@ -222,6 +222,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
222
222
|
item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
|
|
223
223
|
return client;
|
|
224
224
|
};
|
|
225
|
+
if (this.host?.username) {
|
|
226
|
+
this.applyCommand(...batch);
|
|
227
|
+
}
|
|
225
228
|
for (let i = 0; i < length; ++i) {
|
|
226
229
|
const item = batch[i];
|
|
227
230
|
const { source, query, params, ignoreCache } = item;
|
|
@@ -244,10 +247,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
244
247
|
continue;
|
|
245
248
|
}
|
|
246
249
|
item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
|
|
247
|
-
const
|
|
248
|
-
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
250
|
+
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
249
251
|
let queryString = '';
|
|
250
|
-
if (
|
|
252
|
+
if (caching && ignoreCache !== true && !streamRow) {
|
|
251
253
|
queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
|
|
252
254
|
const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
|
|
253
255
|
if (ignoreCache !== 1) {
|
|
@@ -351,14 +353,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
351
353
|
}
|
|
352
354
|
return this.processRows(batch, tasks, {
|
|
353
355
|
disconnect: () => {
|
|
354
|
-
clients.forEach(item => item.end());
|
|
355
|
-
pools.forEach(item => item.release());
|
|
356
|
+
clients.forEach(async (item) => item.end());
|
|
357
|
+
pools.forEach(async (item) => item.release());
|
|
356
358
|
},
|
|
357
359
|
parallel
|
|
358
360
|
}, outResult);
|
|
359
361
|
}
|
|
360
362
|
exports.executeBatchQuery = executeBatchQuery;
|
|
361
|
-
function checkTimeout(value, limit = 0) {
|
|
363
|
+
async function checkTimeout(value, limit = 0) {
|
|
362
364
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
363
365
|
}
|
|
364
366
|
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.1",
|
|
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.1",
|
|
25
|
+
"@e-mc/types": "^0.8.1",
|
|
26
|
+
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|