@pi-r/mysql 0.3.0 → 0.3.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/LICENSE +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +2 -1
- package/client/index.js +13 -13
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Studio Trigger
|
|
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
package/client/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { IDb } from '@e-mc/types/lib';
|
|
2
|
-
import type { MySQLCredential, MySQLDataSource } from '@e-mc/types/lib/db';
|
|
3
2
|
|
|
4
3
|
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
5
4
|
|
|
5
|
+
import type { MySQLCredential, MySQLDataSource } from '../types';
|
|
6
|
+
|
|
6
7
|
declare const MySQL: IDbSourceClient<MySQLDataSource> & {
|
|
7
8
|
setAuthentication(this: IDb, credential: MySQLCredential): void;
|
|
8
9
|
};
|
package/client/index.js
CHANGED
|
@@ -91,7 +91,7 @@ function setCredential(item) {
|
|
|
91
91
|
errors.push('user');
|
|
92
92
|
}
|
|
93
93
|
if (errors.length) {
|
|
94
|
-
throw (0, types_1.errorMessage)("mysql"
|
|
94
|
+
throw (0, types_1.errorMessage)("mysql", 'Not defined - ' + errors.join(' | '));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
const usePool = item.usePool;
|
|
@@ -106,7 +106,7 @@ function setCredential(item) {
|
|
|
106
106
|
}
|
|
107
107
|
const poolKey = getPoolKey(credential);
|
|
108
108
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
109
|
-
const config = this.getPoolConfig("mysql"
|
|
109
|
+
const config = this.getPoolConfig("mysql", password);
|
|
110
110
|
if (config) {
|
|
111
111
|
const { max, idle, queue_max } = config;
|
|
112
112
|
if (max > 0) {
|
|
@@ -156,17 +156,17 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
156
156
|
if (!parallel) {
|
|
157
157
|
outResult || (outResult = new Array(length));
|
|
158
158
|
}
|
|
159
|
-
const caching = this.hasCache("mysql"
|
|
159
|
+
const caching = this.hasCache("mysql", sessionKey);
|
|
160
160
|
const tasks = new Array(length);
|
|
161
161
|
const clients = [];
|
|
162
162
|
const pools = [];
|
|
163
163
|
let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
164
164
|
const getConnection = async (item, credential) => {
|
|
165
|
-
item.transactionState = 64
|
|
165
|
+
item.transactionState = 64;
|
|
166
166
|
let client;
|
|
167
167
|
if (mysqlPool) {
|
|
168
168
|
pools.push(client = await mysqlPool.getConnection());
|
|
169
|
-
item.transactionState &= ~64
|
|
169
|
+
item.transactionState &= ~64;
|
|
170
170
|
return client;
|
|
171
171
|
}
|
|
172
172
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -209,13 +209,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
209
209
|
}
|
|
210
210
|
mysqlCredential = credential;
|
|
211
211
|
}
|
|
212
|
-
item.transactionState &= ~64
|
|
212
|
+
item.transactionState &= ~64;
|
|
213
213
|
return client;
|
|
214
214
|
};
|
|
215
215
|
for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
|
|
216
216
|
const item = batch[i];
|
|
217
217
|
const { source, query, params, ignoreCache } = item;
|
|
218
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql"
|
|
218
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mysql", 'options', null, mysql2Credential || item.credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
219
219
|
let credential, error;
|
|
220
220
|
if (streamRow) {
|
|
221
221
|
if (mysql2Credential) {
|
|
@@ -226,7 +226,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
226
226
|
else if (credential = mysqlCredential || onceCredential) {
|
|
227
227
|
error = null;
|
|
228
228
|
}
|
|
229
|
-
if (error !== null && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
229
|
+
if (error !== null && !(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"))) {
|
|
230
230
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
231
231
|
if (!parallel) {
|
|
232
232
|
tasks.length = 0;
|
|
@@ -242,7 +242,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
242
242
|
}
|
|
243
243
|
continue;
|
|
244
244
|
}
|
|
245
|
-
item.transactionState = 1
|
|
245
|
+
item.transactionState = 1;
|
|
246
246
|
const renewCache = ignoreCache === 0;
|
|
247
247
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
248
248
|
let queryString = '';
|
|
@@ -257,7 +257,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
257
257
|
else {
|
|
258
258
|
outResult[i] = result;
|
|
259
259
|
}
|
|
260
|
-
this.add(item, 4
|
|
260
|
+
this.add(item, 4 | 128);
|
|
261
261
|
continue;
|
|
262
262
|
}
|
|
263
263
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -311,7 +311,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
311
311
|
reject(error);
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
314
|
-
this.add(item, 4
|
|
314
|
+
this.add(item, 4);
|
|
315
315
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows.length ? rows : null);
|
|
316
316
|
}
|
|
317
317
|
});
|
|
@@ -323,7 +323,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
323
323
|
}
|
|
324
324
|
commandType = this.commandType.SELECT;
|
|
325
325
|
const [rows] = await client.query(query, params);
|
|
326
|
-
this.add(item, 4
|
|
326
|
+
this.add(item, 4);
|
|
327
327
|
if ((0, types_1.isArray)(rows)) {
|
|
328
328
|
const [row1, row2] = rows;
|
|
329
329
|
if (rows.length === 2 && Array.isArray(row1) && !Array.isArray(row2) && isResultSetHeader(row2)) {
|
|
@@ -359,7 +359,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
359
359
|
}
|
|
360
360
|
return this.processRows(batch, tasks, {
|
|
361
361
|
disconnect: () => {
|
|
362
|
-
clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection"
|
|
362
|
+
clients.forEach(item => item.end(err => err && this.writeFail(["Unable to close connnection", "mysql"], err, { type: 65536, fatal: false })));
|
|
363
363
|
pools.forEach(item => item.release());
|
|
364
364
|
},
|
|
365
365
|
parallel
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mysql",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "MySQL client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/mysql"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"mysql2": "^3.
|
|
24
|
+
"@e-mc/db": "^0.6.1",
|
|
25
|
+
"@e-mc/types": "^0.6.1",
|
|
26
|
+
"mysql2": "^3.9.2"
|
|
27
27
|
}
|
|
28
28
|
}
|