@pi-r/mariadb 0.6.0 → 0.6.2
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 +2 -0
- package/client/index.js +31 -19
- package/package.json +3 -3
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -30,12 +30,12 @@ function removePoolProperties(credential) {
|
|
|
30
30
|
const attr = POOL_UNUSED[i];
|
|
31
31
|
if (attr in credential) {
|
|
32
32
|
result || (result = { ...credential });
|
|
33
|
-
if (attr
|
|
34
|
-
result[attr] = true;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
33
|
+
if (attr !== 'ssl') {
|
|
37
34
|
delete result[attr];
|
|
38
35
|
}
|
|
36
|
+
else if ((0, types_1.isObject)(result.ssl)) {
|
|
37
|
+
result[attr] = true;
|
|
38
|
+
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
if (result) {
|
|
@@ -55,7 +55,11 @@ function isOkPacket(value) {
|
|
|
55
55
|
const result = Array.isArray(value) ? value[0] : value;
|
|
56
56
|
return !!result && !Array.isArray(result) && result.constructor.name === 'OkPacket';
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
function getPoolKey(credential) {
|
|
59
|
+
if ((credential.host || credential.socketPath) && credential.user) {
|
|
60
|
+
return JSON.stringify(removeUUIDKey(credential));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
59
63
|
function setAuthentication(credential) {
|
|
60
64
|
const auth = (0, util_1.parseServerAuth)(credential);
|
|
61
65
|
credential.host || (credential.host = auth.hostname);
|
|
@@ -89,7 +93,7 @@ function setCredential(item) {
|
|
|
89
93
|
item.credential = credential;
|
|
90
94
|
}
|
|
91
95
|
const errors = [];
|
|
92
|
-
if (!credential.host) {
|
|
96
|
+
if (!credential.host && !credential.socketPath) {
|
|
93
97
|
errors.push('host');
|
|
94
98
|
}
|
|
95
99
|
if (!credential.user) {
|
|
@@ -103,21 +107,22 @@ function setCredential(item) {
|
|
|
103
107
|
return;
|
|
104
108
|
}
|
|
105
109
|
let username, password, pool;
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
pool
|
|
110
|
+
if ((0, types_1.isString)(usePool)) {
|
|
111
|
+
if (username = credential.user) {
|
|
112
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
113
|
+
if (pool) {
|
|
114
|
+
pool.add(item, password);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!password) {
|
|
119
|
+
item.usePool = '';
|
|
110
120
|
return;
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
|
-
const poolKey = getPoolKey(credential);
|
|
114
|
-
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
115
|
-
pool.add(item);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
123
|
const config = this.getPoolConfig("mariadb" /* STRINGS.MODULE_NAME */, password);
|
|
119
124
|
if (config) {
|
|
120
|
-
const { min, max, idle, timeout, socket_timeout } = config;
|
|
125
|
+
const { min, max, idle, queue_idle, timeout, socket_timeout } = config;
|
|
121
126
|
if (min >= 0) {
|
|
122
127
|
credential.minimumIdle ?? (credential.minimumIdle = min);
|
|
123
128
|
}
|
|
@@ -127,6 +132,9 @@ function setCredential(item) {
|
|
|
127
132
|
if (idle >= 0) {
|
|
128
133
|
credential.idleTimeout ?? (credential.idleTimeout = idle);
|
|
129
134
|
}
|
|
135
|
+
if (queue_idle > 0) {
|
|
136
|
+
credential.acquireTimeout ?? (credential.acquireTimeout = queue_idle);
|
|
137
|
+
}
|
|
130
138
|
if (timeout > 0) {
|
|
131
139
|
credential.connectTimeout ?? (credential.connectTimeout = timeout);
|
|
132
140
|
}
|
|
@@ -134,6 +142,11 @@ function setCredential(item) {
|
|
|
134
142
|
credential.socketTimeout ?? (credential.socketTimeout = socket_timeout);
|
|
135
143
|
}
|
|
136
144
|
}
|
|
145
|
+
const poolKey = getPoolKey(credential);
|
|
146
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
147
|
+
pool.add(item);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
137
150
|
new MariaDBPool(mariadb.createPool(removeUUIDKey(credential)), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
138
151
|
}
|
|
139
152
|
exports.setCredential = setCredential;
|
|
@@ -247,10 +260,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
247
260
|
continue;
|
|
248
261
|
}
|
|
249
262
|
item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
|
|
250
|
-
const
|
|
251
|
-
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
263
|
+
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
252
264
|
let queryString = '';
|
|
253
|
-
if (
|
|
265
|
+
if (caching && ignoreCache !== true && !streamRow) {
|
|
254
266
|
queryString = Db.asString(query, true) + '_' + Db.asString(params, true);
|
|
255
267
|
const result = this.getQueryResult(source, removePoolProperties(credential), queryString, cacheValue);
|
|
256
268
|
if (ignoreCache !== 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mariadb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.2",
|
|
25
|
+
"@e-mc/types": "^0.8.2",
|
|
26
26
|
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|