@hesed/mysql 0.2.1 → 0.2.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 +10 -10
- package/dist/mysql/mysql-utils.d.ts +1 -1
- package/dist/mysql/mysql-utils.js +24 -10
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ $ npm install -g @hesed/mysql
|
|
|
26
26
|
$ mq COMMAND
|
|
27
27
|
running command...
|
|
28
28
|
$ mq (--version)
|
|
29
|
-
@hesed/mysql/0.2.
|
|
29
|
+
@hesed/mysql/0.2.2 linux-x64 node-v22.22.1
|
|
30
30
|
$ mq --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ mq COMMAND
|
|
@@ -76,7 +76,7 @@ EXAMPLES
|
|
|
76
76
|
$ mq mysql auth add --no-ssl
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
79
|
+
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/auth/add.ts)_
|
|
80
80
|
|
|
81
81
|
## `mq mysql auth test`
|
|
82
82
|
|
|
@@ -101,7 +101,7 @@ EXAMPLES
|
|
|
101
101
|
$ mq mysql auth test --profile staging
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
104
|
+
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/auth/test.ts)_
|
|
105
105
|
|
|
106
106
|
## `mq mysql auth update`
|
|
107
107
|
|
|
@@ -132,7 +132,7 @@ EXAMPLES
|
|
|
132
132
|
$ mq mysql auth update --profile staging
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
135
|
+
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/auth/update.ts)_
|
|
136
136
|
|
|
137
137
|
## `mq mysql databases`
|
|
138
138
|
|
|
@@ -154,7 +154,7 @@ EXAMPLES
|
|
|
154
154
|
$ mq mysql databases --profile staging
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
157
|
+
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/databases.ts)_
|
|
158
158
|
|
|
159
159
|
## `mq mysql describe-table TABLE`
|
|
160
160
|
|
|
@@ -181,7 +181,7 @@ EXAMPLES
|
|
|
181
181
|
$ mq mysql describe-table orders --format json --profile prod
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
184
|
+
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/describe-table.ts)_
|
|
185
185
|
|
|
186
186
|
## `mq mysql explain-query QUERY`
|
|
187
187
|
|
|
@@ -208,7 +208,7 @@ EXAMPLES
|
|
|
208
208
|
$ mq mysql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
211
|
+
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/explain-query.ts)_
|
|
212
212
|
|
|
213
213
|
## `mq mysql indexes TABLE`
|
|
214
214
|
|
|
@@ -235,7 +235,7 @@ EXAMPLES
|
|
|
235
235
|
$ mq mysql indexes orders --format json --profile prod
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
238
|
+
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/indexes.ts)_
|
|
239
239
|
|
|
240
240
|
## `mq mysql query QUERY`
|
|
241
241
|
|
|
@@ -265,7 +265,7 @@ EXAMPLES
|
|
|
265
265
|
$ mq mysql query "DELETE FROM sessions" --profile prod --skip-confirmation
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
268
|
+
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/query.ts)_
|
|
269
269
|
|
|
270
270
|
## `mq mysql tables`
|
|
271
271
|
|
|
@@ -287,5 +287,5 @@ EXAMPLES
|
|
|
287
287
|
$ mq mysql tables --profile local
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.2.
|
|
290
|
+
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.2.2/src/commands/mysql/tables.ts)_
|
|
291
291
|
<!-- commandsstop -->
|
|
@@ -7,7 +7,7 @@ import type { ConnectionTestResult, DatabaseListResult, DatabaseUtil, ExplainRes
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class MySQLUtil implements DatabaseUtil {
|
|
9
9
|
private config;
|
|
10
|
-
private
|
|
10
|
+
private connections;
|
|
11
11
|
constructor(config: MySQLConfig);
|
|
12
12
|
/**
|
|
13
13
|
* Close all connections
|
|
@@ -8,17 +8,18 @@ import { analyzeQuery, applyDefaultLimit, checkBlacklist, getQueryType, requires
|
|
|
8
8
|
*/
|
|
9
9
|
export class MySQLUtil {
|
|
10
10
|
config;
|
|
11
|
-
|
|
11
|
+
connections;
|
|
12
12
|
constructor(config) {
|
|
13
13
|
this.config = config;
|
|
14
|
-
this.
|
|
14
|
+
this.connections = new Map();
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Close all connections
|
|
18
18
|
*/
|
|
19
19
|
async closeAll() {
|
|
20
|
-
|
|
21
|
-
this.
|
|
20
|
+
const entries = [...this.connections.values()];
|
|
21
|
+
this.connections.clear();
|
|
22
|
+
await Promise.allSettled(entries.map(async (connPromise) => (await connPromise).end()));
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Describe table structure
|
|
@@ -359,12 +360,25 @@ export class MySQLUtil {
|
|
|
359
360
|
* Get or create MySQL connection for a profile
|
|
360
361
|
*/
|
|
361
362
|
async getConnection(profileName) {
|
|
362
|
-
|
|
363
|
-
|
|
363
|
+
const existing = this.connections.get(profileName);
|
|
364
|
+
if (existing) {
|
|
365
|
+
try {
|
|
366
|
+
const conn = await existing;
|
|
367
|
+
await conn.ping();
|
|
368
|
+
return conn;
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
this.connections.delete(profileName);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const connPromise = mysql.createConnection(getMySQLConnectionOptions(this.config, profileName));
|
|
375
|
+
this.connections.set(profileName, connPromise);
|
|
376
|
+
try {
|
|
377
|
+
return await connPromise;
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
this.connections.delete(profileName);
|
|
381
|
+
throw error;
|
|
364
382
|
}
|
|
365
|
-
const options = getMySQLConnectionOptions(this.config, profileName);
|
|
366
|
-
const connection = await mysql.createConnection(options);
|
|
367
|
-
this.connectionPool.set(profileName, connection);
|
|
368
|
-
return connection;
|
|
369
383
|
}
|
|
370
384
|
}
|
package/oclif.manifest.json
CHANGED