@hesed/mysql 0.5.0 → 0.5.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/README.md +33 -18
- package/dist/base-command.d.ts +12 -0
- package/dist/base-command.js +50 -0
- package/dist/commands/mysql/databases.d.ts +3 -1
- package/dist/commands/mysql/databases.js +6 -4
- package/dist/commands/mysql/describe-table.d.ts +3 -3
- package/dist/commands/mysql/describe-table.js +5 -5
- package/dist/commands/mysql/explain-query.d.ts +3 -3
- package/dist/commands/mysql/explain-query.js +5 -5
- package/dist/commands/mysql/indexes.d.ts +3 -3
- package/dist/commands/mysql/indexes.js +5 -5
- package/dist/commands/mysql/query.d.ts +3 -3
- package/dist/commands/mysql/query.js +9 -6
- package/dist/commands/mysql/tables.d.ts +2 -1
- package/dist/commands/mysql/tables.js +5 -4
- package/oclif.manifest.json +41 -6
- 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.5.
|
|
29
|
+
@hesed/mysql/0.5.1 linux-x64 node-v24.17.0
|
|
30
30
|
$ mq --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ mq COMMAND
|
|
@@ -80,7 +80,7 @@ EXAMPLES
|
|
|
80
80
|
$ mq mysql auth add -p prod
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
83
|
+
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/add.ts)_
|
|
84
84
|
|
|
85
85
|
## `mq mysql auth delete`
|
|
86
86
|
|
|
@@ -105,7 +105,7 @@ EXAMPLES
|
|
|
105
105
|
$ mq mysql auth delete -p prod
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
_See code: [src/commands/mysql/auth/delete.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
108
|
+
_See code: [src/commands/mysql/auth/delete.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/delete.ts)_
|
|
109
109
|
|
|
110
110
|
## `mq mysql auth list`
|
|
111
111
|
|
|
@@ -125,7 +125,7 @@ EXAMPLES
|
|
|
125
125
|
$ mq mysql auth list
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
_See code: [src/commands/mysql/auth/list.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
128
|
+
_See code: [src/commands/mysql/auth/list.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/list.ts)_
|
|
129
129
|
|
|
130
130
|
## `mq mysql auth profile`
|
|
131
131
|
|
|
@@ -150,7 +150,7 @@ EXAMPLES
|
|
|
150
150
|
$ mq mysql auth profile --default test
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
_See code: [src/commands/mysql/auth/profile.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
153
|
+
_See code: [src/commands/mysql/auth/profile.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/profile.ts)_
|
|
154
154
|
|
|
155
155
|
## `mq mysql auth test`
|
|
156
156
|
|
|
@@ -175,7 +175,7 @@ EXAMPLES
|
|
|
175
175
|
$ mq mysql auth test -p prod
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
178
|
+
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/test.ts)_
|
|
179
179
|
|
|
180
180
|
## `mq mysql auth update`
|
|
181
181
|
|
|
@@ -207,7 +207,7 @@ EXAMPLES
|
|
|
207
207
|
$ mq mysql auth update -p test
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
210
|
+
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/auth/update.ts)_
|
|
211
211
|
|
|
212
212
|
## `mq mysql databases`
|
|
213
213
|
|
|
@@ -215,11 +215,14 @@ List all databases accessible on the MySQL server
|
|
|
215
215
|
|
|
216
216
|
```
|
|
217
217
|
USAGE
|
|
218
|
-
$ mq mysql databases [-p <value>]
|
|
218
|
+
$ mq mysql databases [--json] [-p <value>]
|
|
219
219
|
|
|
220
220
|
FLAGS
|
|
221
221
|
-p, --profile=<value> Database profile name from config
|
|
222
222
|
|
|
223
|
+
GLOBAL FLAGS
|
|
224
|
+
--json Format output as json.
|
|
225
|
+
|
|
223
226
|
DESCRIPTION
|
|
224
227
|
List all databases accessible on the MySQL server
|
|
225
228
|
|
|
@@ -229,7 +232,7 @@ EXAMPLES
|
|
|
229
232
|
$ mq mysql databases -p staging
|
|
230
233
|
```
|
|
231
234
|
|
|
232
|
-
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
235
|
+
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/databases.ts)_
|
|
233
236
|
|
|
234
237
|
## `mq mysql describe-table TABLE`
|
|
235
238
|
|
|
@@ -237,7 +240,7 @@ Describe the structure of a MySQL table
|
|
|
237
240
|
|
|
238
241
|
```
|
|
239
242
|
USAGE
|
|
240
|
-
$ mq mysql describe-table TABLE [--format table|json|toon] [-p <value>]
|
|
243
|
+
$ mq mysql describe-table TABLE [--json] [--format table|json|toon] [-p <value>]
|
|
241
244
|
|
|
242
245
|
ARGUMENTS
|
|
243
246
|
TABLE Table name to describe
|
|
@@ -247,6 +250,9 @@ FLAGS
|
|
|
247
250
|
--format=<option> [default: table] Output format
|
|
248
251
|
<options: table|json|toon>
|
|
249
252
|
|
|
253
|
+
GLOBAL FLAGS
|
|
254
|
+
--json Format output as json.
|
|
255
|
+
|
|
250
256
|
DESCRIPTION
|
|
251
257
|
Describe the structure of a MySQL table
|
|
252
258
|
|
|
@@ -256,7 +262,7 @@ EXAMPLES
|
|
|
256
262
|
$ mq mysql describe-table orders --format json -p prod
|
|
257
263
|
```
|
|
258
264
|
|
|
259
|
-
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
265
|
+
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/describe-table.ts)_
|
|
260
266
|
|
|
261
267
|
## `mq mysql explain-query QUERY`
|
|
262
268
|
|
|
@@ -264,7 +270,7 @@ Show the execution plan for a MySQL query
|
|
|
264
270
|
|
|
265
271
|
```
|
|
266
272
|
USAGE
|
|
267
|
-
$ mq mysql explain-query QUERY [--format table|json|toon] [-p <value>]
|
|
273
|
+
$ mq mysql explain-query QUERY [--json] [--format table|json|toon] [-p <value>]
|
|
268
274
|
|
|
269
275
|
ARGUMENTS
|
|
270
276
|
QUERY SQL query to explain
|
|
@@ -274,6 +280,9 @@ FLAGS
|
|
|
274
280
|
--format=<option> [default: table] Output format
|
|
275
281
|
<options: table|json|toon>
|
|
276
282
|
|
|
283
|
+
GLOBAL FLAGS
|
|
284
|
+
--json Format output as json.
|
|
285
|
+
|
|
277
286
|
DESCRIPTION
|
|
278
287
|
Show the execution plan for a MySQL query
|
|
279
288
|
|
|
@@ -283,7 +292,7 @@ EXAMPLES
|
|
|
283
292
|
$ mq mysql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
|
|
284
293
|
```
|
|
285
294
|
|
|
286
|
-
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
295
|
+
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/explain-query.ts)_
|
|
287
296
|
|
|
288
297
|
## `mq mysql indexes TABLE`
|
|
289
298
|
|
|
@@ -291,7 +300,7 @@ Show indexes for a MySQL table
|
|
|
291
300
|
|
|
292
301
|
```
|
|
293
302
|
USAGE
|
|
294
|
-
$ mq mysql indexes TABLE [--format table|json|toon] [-p <value>]
|
|
303
|
+
$ mq mysql indexes TABLE [--json] [--format table|json|toon] [-p <value>]
|
|
295
304
|
|
|
296
305
|
ARGUMENTS
|
|
297
306
|
TABLE Table name to show indexes for
|
|
@@ -301,6 +310,9 @@ FLAGS
|
|
|
301
310
|
--format=<option> [default: table] Output format
|
|
302
311
|
<options: table|json|toon>
|
|
303
312
|
|
|
313
|
+
GLOBAL FLAGS
|
|
314
|
+
--json Format output as json.
|
|
315
|
+
|
|
304
316
|
DESCRIPTION
|
|
305
317
|
Show indexes for a MySQL table
|
|
306
318
|
|
|
@@ -310,7 +322,7 @@ EXAMPLES
|
|
|
310
322
|
$ mq mysql indexes orders --format json -p prod
|
|
311
323
|
```
|
|
312
324
|
|
|
313
|
-
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
325
|
+
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/indexes.ts)_
|
|
314
326
|
|
|
315
327
|
## `mq mysql query QUERY`
|
|
316
328
|
|
|
@@ -318,7 +330,7 @@ Execute a SQL query against a MySQL database
|
|
|
318
330
|
|
|
319
331
|
```
|
|
320
332
|
USAGE
|
|
321
|
-
$ mq mysql query QUERY [--format table|json|csv|toon] [-p <value>] [--skip-confirmation]
|
|
333
|
+
$ mq mysql query QUERY [--json] [--format table|json|csv|toon] [-p <value>] [--skip-confirmation]
|
|
322
334
|
|
|
323
335
|
ARGUMENTS
|
|
324
336
|
QUERY SQL query to execute
|
|
@@ -329,6 +341,9 @@ FLAGS
|
|
|
329
341
|
<options: table|json|csv|toon>
|
|
330
342
|
--skip-confirmation Skip confirmation prompt for destructive operations
|
|
331
343
|
|
|
344
|
+
GLOBAL FLAGS
|
|
345
|
+
--json Format output as json.
|
|
346
|
+
|
|
332
347
|
DESCRIPTION
|
|
333
348
|
Execute a SQL query against a MySQL database
|
|
334
349
|
|
|
@@ -340,7 +355,7 @@ EXAMPLES
|
|
|
340
355
|
$ mq mysql query "DELETE FROM sessions" -p prod --skip-confirmation
|
|
341
356
|
```
|
|
342
357
|
|
|
343
|
-
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
358
|
+
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/query.ts)_
|
|
344
359
|
|
|
345
360
|
## `mq mysql tables`
|
|
346
361
|
|
|
@@ -362,5 +377,5 @@ EXAMPLES
|
|
|
362
377
|
$ mq mysql tables -p local
|
|
363
378
|
```
|
|
364
379
|
|
|
365
|
-
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.5.
|
|
380
|
+
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.5.1/src/commands/mysql/tables.ts)_
|
|
366
381
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export declare abstract class BaseCommand extends Command {
|
|
3
|
+
static enableJsonFlag: boolean;
|
|
4
|
+
jsonEnabled(): boolean;
|
|
5
|
+
protected parse(options?: any, argv?: string[]): Promise<any>;
|
|
6
|
+
protected parseJsonOutput(output?: string): unknown;
|
|
7
|
+
protected toErrorJson(err: unknown): {
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
private formatFlagValue;
|
|
11
|
+
private hasFormatFlag;
|
|
12
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export class BaseCommand extends Command {
|
|
3
|
+
static enableJsonFlag = true;
|
|
4
|
+
jsonEnabled() {
|
|
5
|
+
const separatorIndex = this.argv.indexOf('--');
|
|
6
|
+
const flagArgs = separatorIndex === -1 ? this.argv : this.argv.slice(0, separatorIndex);
|
|
7
|
+
if (this.hasFormatFlag(flagArgs))
|
|
8
|
+
return this.formatFlagValue(flagArgs) === 'json';
|
|
9
|
+
return flagArgs.includes('--json');
|
|
10
|
+
}
|
|
11
|
+
// oclif sets this.parsed=true only after Parser.parse() returns successfully.
|
|
12
|
+
// When parse() throws (e.g. missing required arg), this.parsed stays false and
|
|
13
|
+
// _run() emits an UnparsedCommand warning. The finally block prevents that.
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
async parse(options, argv) {
|
|
16
|
+
try {
|
|
17
|
+
return await super.parse(options, argv);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
this.parsed = true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
parseJsonOutput(output) {
|
|
24
|
+
if (!output)
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(output);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// oclif's default toErrorJson returns the raw error object which for
|
|
34
|
+
// CLIParseError includes context:this (the full config). Strip it down.
|
|
35
|
+
toErrorJson(err) {
|
|
36
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
37
|
+
return { error: message };
|
|
38
|
+
}
|
|
39
|
+
formatFlagValue(flagArgs) {
|
|
40
|
+
for (const [index, arg] of flagArgs.entries()) {
|
|
41
|
+
if (arg === '--format')
|
|
42
|
+
return flagArgs[index + 1];
|
|
43
|
+
if (arg.startsWith('--format='))
|
|
44
|
+
return arg.slice('--format='.length);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
hasFormatFlag(flagArgs) {
|
|
48
|
+
return flagArgs.some((arg) => arg === '--format' || arg.startsWith('--format='));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
export default class MySQLDatabases extends Command {
|
|
3
3
|
static description: string;
|
|
4
|
+
static enableJsonFlag: boolean;
|
|
4
5
|
static examples: string[];
|
|
5
6
|
static flags: {
|
|
6
7
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
+
jsonEnabled(): boolean;
|
|
10
|
+
run(): Promise<string[]>;
|
|
9
11
|
}
|
|
@@ -2,19 +2,21 @@ import { Command, Flags } from '@oclif/core';
|
|
|
2
2
|
import { closeConnections, listDatabases } from '../../mysql/index.js';
|
|
3
3
|
export default class MySQLDatabases extends Command {
|
|
4
4
|
static description = 'List all databases accessible on the MySQL server';
|
|
5
|
+
static enableJsonFlag = true;
|
|
5
6
|
static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> -p staging'];
|
|
6
7
|
static flags = {
|
|
7
8
|
profile: Flags.string({ char: 'p', description: 'Database profile name from config', required: false }),
|
|
8
9
|
};
|
|
10
|
+
jsonEnabled() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
9
13
|
async run() {
|
|
10
14
|
const { flags } = await this.parse(MySQLDatabases);
|
|
11
15
|
const result = await listDatabases(this.config, flags.profile);
|
|
12
16
|
await closeConnections();
|
|
13
17
|
if (result.success) {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
this.error(result.error ?? 'Failed to list databases');
|
|
18
|
+
return result.databases ?? [];
|
|
18
19
|
}
|
|
20
|
+
this.error(result.error ?? 'Failed to list databases');
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class MySQLDescribeTable extends
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class MySQLDescribeTable extends BaseCommand {
|
|
3
3
|
static args: {
|
|
4
4
|
table: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -9,5 +9,5 @@ export default class MySQLDescribeTable extends Command {
|
|
|
9
9
|
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
};
|
|
12
|
-
run(): Promise<
|
|
12
|
+
run(): Promise<unknown>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
3
|
import { closeConnections, describeTable } from '../../mysql/index.js';
|
|
3
|
-
export default class MySQLDescribeTable extends
|
|
4
|
+
export default class MySQLDescribeTable extends BaseCommand {
|
|
4
5
|
static args = {
|
|
5
6
|
table: Args.string({ description: 'Table name to describe', required: true }),
|
|
6
7
|
};
|
|
@@ -23,9 +24,8 @@ export default class MySQLDescribeTable extends Command {
|
|
|
23
24
|
await closeConnections();
|
|
24
25
|
if (result.success) {
|
|
25
26
|
this.log(result.result ?? '');
|
|
27
|
+
return result;
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
this.error(result.error ?? 'Failed to describe table');
|
|
29
|
-
}
|
|
29
|
+
this.error(result.error ?? 'Failed to describe table');
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class MySQLExplain extends
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class MySQLExplain extends BaseCommand {
|
|
3
3
|
static args: {
|
|
4
4
|
query: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -9,5 +9,5 @@ export default class MySQLExplain extends Command {
|
|
|
9
9
|
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
};
|
|
12
|
-
run(): Promise<
|
|
12
|
+
run(): Promise<unknown>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
3
|
import { closeConnections, explainQuery } from '../../mysql/index.js';
|
|
3
|
-
export default class MySQLExplain extends
|
|
4
|
+
export default class MySQLExplain extends BaseCommand {
|
|
4
5
|
static args = {
|
|
5
6
|
query: Args.string({ description: 'SQL query to explain', required: true }),
|
|
6
7
|
};
|
|
@@ -23,9 +24,8 @@ export default class MySQLExplain extends Command {
|
|
|
23
24
|
await closeConnections();
|
|
24
25
|
if (result.success) {
|
|
25
26
|
this.log(result.result ?? '');
|
|
27
|
+
return result;
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
this.error(result.error ?? 'Failed to explain query');
|
|
29
|
-
}
|
|
29
|
+
this.error(result.error ?? 'Failed to explain query');
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class MySQLIndexes extends
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class MySQLIndexes extends BaseCommand {
|
|
3
3
|
static args: {
|
|
4
4
|
table: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -9,5 +9,5 @@ export default class MySQLIndexes extends Command {
|
|
|
9
9
|
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
};
|
|
12
|
-
run(): Promise<
|
|
12
|
+
run(): Promise<unknown>;
|
|
13
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
3
|
import { closeConnections, showIndexes } from '../../mysql/index.js';
|
|
3
|
-
export default class MySQLIndexes extends
|
|
4
|
+
export default class MySQLIndexes extends BaseCommand {
|
|
4
5
|
static args = {
|
|
5
6
|
table: Args.string({ description: 'Table name to show indexes for', required: true }),
|
|
6
7
|
};
|
|
@@ -23,9 +24,8 @@ export default class MySQLIndexes extends Command {
|
|
|
23
24
|
await closeConnections();
|
|
24
25
|
if (result.success) {
|
|
25
26
|
this.log(result.result ?? '');
|
|
27
|
+
return result;
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
this.error(result.error ?? 'Failed to show indexes');
|
|
29
|
-
}
|
|
29
|
+
this.error(result.error ?? 'Failed to show indexes');
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class MySQLQuery extends
|
|
1
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
|
+
export default class MySQLQuery extends BaseCommand {
|
|
3
3
|
static args: {
|
|
4
4
|
query: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
5
|
};
|
|
@@ -10,5 +10,5 @@ export default class MySQLQuery extends Command {
|
|
|
10
10
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
'skip-confirmation': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
12
|
};
|
|
13
|
-
run(): Promise<
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
14
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Args,
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base-command.js';
|
|
2
3
|
import { closeConnections, executeQuery } from '../../mysql/index.js';
|
|
3
|
-
export default class MySQLQuery extends
|
|
4
|
+
export default class MySQLQuery extends BaseCommand {
|
|
4
5
|
static args = {
|
|
5
6
|
query: Args.string({ description: 'SQL query to execute', required: true }),
|
|
6
7
|
};
|
|
@@ -31,13 +32,15 @@ export default class MySQLQuery extends Command {
|
|
|
31
32
|
// leave stdout as clean, parseable data.
|
|
32
33
|
if (result.notices)
|
|
33
34
|
this.logToStderr(result.notices);
|
|
35
|
+
if (this.jsonEnabled())
|
|
36
|
+
return this.parseJsonOutput(result.result);
|
|
34
37
|
this.log(result.result ?? '');
|
|
38
|
+
return result;
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
if (result.requiresConfirmation) {
|
|
37
41
|
this.log(`${result.message ?? 'Destructive operation requires confirmation.'}\nRe-run with --skip-confirmation to proceed.`);
|
|
42
|
+
return result;
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
this.error(result.error ?? 'Query failed');
|
|
41
|
-
}
|
|
44
|
+
this.error(result.error ?? 'Query failed');
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -5,5 +5,6 @@ export default class MySQLTables extends Command {
|
|
|
5
5
|
static flags: {
|
|
6
6
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
jsonEnabled(): boolean;
|
|
9
|
+
run(): Promise<string[]>;
|
|
9
10
|
}
|
|
@@ -6,15 +6,16 @@ export default class MySQLTables extends Command {
|
|
|
6
6
|
static flags = {
|
|
7
7
|
profile: Flags.string({ char: 'p', description: 'Database profile name from config', required: false }),
|
|
8
8
|
};
|
|
9
|
+
jsonEnabled() {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
9
12
|
async run() {
|
|
10
13
|
const { flags } = await this.parse(MySQLTables);
|
|
11
14
|
const result = await listTables(this.config, flags.profile);
|
|
12
15
|
await closeConnections();
|
|
13
16
|
if (result.success) {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
this.error(result.error ?? 'Failed to list tables');
|
|
17
|
+
return result.tables ?? [];
|
|
18
18
|
}
|
|
19
|
+
this.error(result.error ?? 'Failed to list tables');
|
|
19
20
|
}
|
|
20
21
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
"<%= config.bin %> <%= command.id %> -p staging"
|
|
10
10
|
],
|
|
11
11
|
"flags": {
|
|
12
|
+
"json": {
|
|
13
|
+
"description": "Format output as json.",
|
|
14
|
+
"helpGroup": "GLOBAL",
|
|
15
|
+
"name": "json",
|
|
16
|
+
"allowNo": false,
|
|
17
|
+
"type": "boolean"
|
|
18
|
+
},
|
|
12
19
|
"profile": {
|
|
13
20
|
"char": "p",
|
|
14
21
|
"description": "Database profile name from config",
|
|
@@ -26,7 +33,7 @@
|
|
|
26
33
|
"pluginName": "@hesed/mysql",
|
|
27
34
|
"pluginType": "core",
|
|
28
35
|
"strict": true,
|
|
29
|
-
"enableJsonFlag":
|
|
36
|
+
"enableJsonFlag": true,
|
|
30
37
|
"isESM": true,
|
|
31
38
|
"relativePath": [
|
|
32
39
|
"dist",
|
|
@@ -50,6 +57,13 @@
|
|
|
50
57
|
"<%= config.bin %> <%= command.id %> orders --format json -p prod"
|
|
51
58
|
],
|
|
52
59
|
"flags": {
|
|
60
|
+
"json": {
|
|
61
|
+
"description": "Format output as json.",
|
|
62
|
+
"helpGroup": "GLOBAL",
|
|
63
|
+
"name": "json",
|
|
64
|
+
"allowNo": false,
|
|
65
|
+
"type": "boolean"
|
|
66
|
+
},
|
|
53
67
|
"format": {
|
|
54
68
|
"description": "Output format",
|
|
55
69
|
"name": "format",
|
|
@@ -80,7 +94,7 @@
|
|
|
80
94
|
"pluginName": "@hesed/mysql",
|
|
81
95
|
"pluginType": "core",
|
|
82
96
|
"strict": true,
|
|
83
|
-
"enableJsonFlag":
|
|
97
|
+
"enableJsonFlag": true,
|
|
84
98
|
"isESM": true,
|
|
85
99
|
"relativePath": [
|
|
86
100
|
"dist",
|
|
@@ -104,6 +118,13 @@
|
|
|
104
118
|
"<%= config.bin %> <%= command.id %> \"SELECT * FROM orders JOIN users ON orders.user_id = users.id\" --format json"
|
|
105
119
|
],
|
|
106
120
|
"flags": {
|
|
121
|
+
"json": {
|
|
122
|
+
"description": "Format output as json.",
|
|
123
|
+
"helpGroup": "GLOBAL",
|
|
124
|
+
"name": "json",
|
|
125
|
+
"allowNo": false,
|
|
126
|
+
"type": "boolean"
|
|
127
|
+
},
|
|
107
128
|
"format": {
|
|
108
129
|
"description": "Output format",
|
|
109
130
|
"name": "format",
|
|
@@ -134,7 +155,7 @@
|
|
|
134
155
|
"pluginName": "@hesed/mysql",
|
|
135
156
|
"pluginType": "core",
|
|
136
157
|
"strict": true,
|
|
137
|
-
"enableJsonFlag":
|
|
158
|
+
"enableJsonFlag": true,
|
|
138
159
|
"isESM": true,
|
|
139
160
|
"relativePath": [
|
|
140
161
|
"dist",
|
|
@@ -158,6 +179,13 @@
|
|
|
158
179
|
"<%= config.bin %> <%= command.id %> orders --format json -p prod"
|
|
159
180
|
],
|
|
160
181
|
"flags": {
|
|
182
|
+
"json": {
|
|
183
|
+
"description": "Format output as json.",
|
|
184
|
+
"helpGroup": "GLOBAL",
|
|
185
|
+
"name": "json",
|
|
186
|
+
"allowNo": false,
|
|
187
|
+
"type": "boolean"
|
|
188
|
+
},
|
|
161
189
|
"format": {
|
|
162
190
|
"description": "Output format",
|
|
163
191
|
"name": "format",
|
|
@@ -188,7 +216,7 @@
|
|
|
188
216
|
"pluginName": "@hesed/mysql",
|
|
189
217
|
"pluginType": "core",
|
|
190
218
|
"strict": true,
|
|
191
|
-
"enableJsonFlag":
|
|
219
|
+
"enableJsonFlag": true,
|
|
192
220
|
"isESM": true,
|
|
193
221
|
"relativePath": [
|
|
194
222
|
"dist",
|
|
@@ -213,6 +241,13 @@
|
|
|
213
241
|
"<%= config.bin %> <%= command.id %> \"DELETE FROM sessions\" -p prod --skip-confirmation"
|
|
214
242
|
],
|
|
215
243
|
"flags": {
|
|
244
|
+
"json": {
|
|
245
|
+
"description": "Format output as json.",
|
|
246
|
+
"helpGroup": "GLOBAL",
|
|
247
|
+
"name": "json",
|
|
248
|
+
"allowNo": false,
|
|
249
|
+
"type": "boolean"
|
|
250
|
+
},
|
|
216
251
|
"format": {
|
|
217
252
|
"description": "Output format",
|
|
218
253
|
"name": "format",
|
|
@@ -250,7 +285,7 @@
|
|
|
250
285
|
"pluginName": "@hesed/mysql",
|
|
251
286
|
"pluginType": "core",
|
|
252
287
|
"strict": true,
|
|
253
|
-
"enableJsonFlag":
|
|
288
|
+
"enableJsonFlag": true,
|
|
254
289
|
"isESM": true,
|
|
255
290
|
"relativePath": [
|
|
256
291
|
"dist",
|
|
@@ -640,5 +675,5 @@
|
|
|
640
675
|
]
|
|
641
676
|
}
|
|
642
677
|
},
|
|
643
|
-
"version": "0.5.
|
|
678
|
+
"version": "0.5.1"
|
|
644
679
|
}
|