@pi-r/mariadb 0.6.3 → 0.6.5
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/LICENSE +1 -1
- package/README.md +6 -3
- package/client/index.d.ts +7 -0
- package/client/index.js +16 -13
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# @pi-r/mariadb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/db/mariadb.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
6
9
|
|
|
7
10
|
MIT
|
package/client/index.js
CHANGED
|
@@ -23,8 +23,9 @@ class MariaDBPool extends DbPool {
|
|
|
23
23
|
}
|
|
24
24
|
const POOL_STATE = {};
|
|
25
25
|
const POOL_UNUSED = ['ssl', 'connectTimeout', 'socketTimeout', 'compress', 'keepAliveDelay', 'acquireTimeout', 'connectionLimit', 'idleTimeout', 'initializationTimeout', 'minDelayValidation', 'minimumIdle', 'resetAfterUse', 'noControlAfterUse', 'leakDetectionTimeout'];
|
|
26
|
+
const POOL_ACTIVE = new WeakSet();
|
|
26
27
|
function removePoolProperties(credential) {
|
|
27
|
-
if (!credential.uuidKey) {
|
|
28
|
+
if (!credential.uuidKey && POOL_ACTIVE.has(credential)) {
|
|
28
29
|
let result;
|
|
29
30
|
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
30
31
|
const attr = POOL_UNUSED[i];
|
|
@@ -100,7 +101,7 @@ function setCredential(item) {
|
|
|
100
101
|
errors.push('user');
|
|
101
102
|
}
|
|
102
103
|
if (errors.length) {
|
|
103
|
-
throw (0, types_1.errorMessage)("mariadb"
|
|
104
|
+
throw (0, types_1.errorMessage)("mariadb", 'Not defined - ' + errors.join(' | '));
|
|
104
105
|
}
|
|
105
106
|
const usePool = item.usePool;
|
|
106
107
|
if (!usePool) {
|
|
@@ -120,7 +121,7 @@ function setCredential(item) {
|
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
|
-
const config = this.getPoolConfig("mariadb"
|
|
124
|
+
const config = this.getPoolConfig("mariadb", password);
|
|
124
125
|
if (config) {
|
|
125
126
|
const { min, max, idle, queue_idle, timeout, socket_timeout } = config;
|
|
126
127
|
if (min >= 0) {
|
|
@@ -179,17 +180,18 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
179
180
|
if (!parallel) {
|
|
180
181
|
outResult || (outResult = new Array(length));
|
|
181
182
|
}
|
|
182
|
-
const caching = this.hasCache("mariadb"
|
|
183
|
+
const caching = this.hasCache("mariadb", sessionKey);
|
|
183
184
|
const tasks = new Array(length);
|
|
184
185
|
const clients = [];
|
|
185
186
|
const pools = [];
|
|
186
187
|
let mariaDBPool, mariaDBClient, mariaDBCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
187
188
|
const getConnection = async (item, credential) => {
|
|
188
|
-
item.transactionState = 64
|
|
189
|
+
item.transactionState = 64;
|
|
189
190
|
let client;
|
|
190
191
|
if (mariaDBPool) {
|
|
191
192
|
pools.push(client = await mariaDBPool.getConnection());
|
|
192
|
-
item.transactionState &= ~64
|
|
193
|
+
item.transactionState &= ~64;
|
|
194
|
+
POOL_ACTIVE.add(credential);
|
|
193
195
|
return client;
|
|
194
196
|
}
|
|
195
197
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -200,6 +202,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
200
202
|
mariaDBPool = pool;
|
|
201
203
|
}
|
|
202
204
|
pool.connected = true;
|
|
205
|
+
POOL_ACTIVE.add(credential);
|
|
203
206
|
}
|
|
204
207
|
catch (err) {
|
|
205
208
|
let close;
|
|
@@ -232,7 +235,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
232
235
|
}
|
|
233
236
|
mariaDBCredential = credential;
|
|
234
237
|
}
|
|
235
|
-
item.transactionState &= ~64
|
|
238
|
+
item.transactionState &= ~64;
|
|
236
239
|
return client;
|
|
237
240
|
};
|
|
238
241
|
if (this.host?.username) {
|
|
@@ -242,8 +245,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
242
245
|
const item = batch[i];
|
|
243
246
|
const { source, query, params, ignoreCache } = item;
|
|
244
247
|
let credential = mariaDBCredential || onceCredential, error;
|
|
245
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb"
|
|
246
|
-
if (!(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
248
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mariadb", 'options', null, item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
249
|
+
if (!(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
|
|
247
250
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
248
251
|
if (!parallel) {
|
|
249
252
|
tasks.length = 0;
|
|
@@ -259,7 +262,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
259
262
|
}
|
|
260
263
|
continue;
|
|
261
264
|
}
|
|
262
|
-
item.transactionState = 1
|
|
265
|
+
item.transactionState = 1;
|
|
263
266
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
264
267
|
let queryString = '';
|
|
265
268
|
if (caching && ignoreCache !== true && !streamRow) {
|
|
@@ -273,7 +276,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
273
276
|
else {
|
|
274
277
|
outResult[i] = result;
|
|
275
278
|
}
|
|
276
|
-
this.add(item, 4
|
|
279
|
+
this.add(item, 4 | 128);
|
|
277
280
|
continue;
|
|
278
281
|
}
|
|
279
282
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -324,13 +327,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
324
327
|
reject(error);
|
|
325
328
|
}
|
|
326
329
|
else {
|
|
327
|
-
this.add(item, 4
|
|
330
|
+
this.add(item, 4);
|
|
328
331
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
|
|
329
332
|
}
|
|
330
333
|
}
|
|
331
334
|
else {
|
|
332
335
|
const rows = await client.query(query, params);
|
|
333
|
-
this.add(item, 4
|
|
336
|
+
this.add(item, 4);
|
|
334
337
|
if ((0, types_1.isArray)(rows)) {
|
|
335
338
|
const [row1, row2] = rows;
|
|
336
339
|
if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isOkPacket(row2)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mariadb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
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.6",
|
|
25
|
+
"@e-mc/types": "^0.8.6",
|
|
26
26
|
"mariadb": "^3.2.3"
|
|
27
27
|
}
|
|
28
28
|
}
|