@hesed/mysql 0.2.2 → 0.3.0
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 +107 -32
- package/dist/commands/mysql/auth/add.d.ts +2 -18
- package/dist/commands/mysql/auth/add.js +16 -57
- package/dist/commands/mysql/auth/delete.d.ts +2 -0
- package/dist/commands/mysql/auth/delete.js +2 -0
- package/dist/commands/mysql/auth/list.d.ts +2 -0
- package/dist/commands/mysql/auth/list.js +2 -0
- package/dist/commands/mysql/auth/profile.d.ts +2 -0
- package/dist/commands/mysql/auth/profile.js +2 -0
- package/dist/commands/mysql/auth/test.d.ts +2 -12
- package/dist/commands/mysql/auth/test.js +16 -41
- package/dist/commands/mysql/auth/update.d.ts +2 -18
- package/dist/commands/mysql/auth/update.js +16 -74
- package/dist/commands/mysql/databases.js +2 -10
- package/dist/commands/mysql/describe-table.js +2 -10
- package/dist/commands/mysql/explain-query.js +2 -10
- package/dist/commands/mysql/indexes.js +2 -10
- package/dist/commands/mysql/query.js +2 -10
- package/dist/commands/mysql/tables.js +2 -10
- package/dist/mysql/config-loader.d.ts +8 -17
- package/dist/mysql/config-loader.js +0 -7
- package/dist/mysql/database.d.ts +0 -31
- package/dist/mysql/database.js +0 -4
- package/dist/mysql/formatters.d.ts +5 -0
- package/dist/mysql/formatters.js +76 -0
- package/dist/mysql/index.d.ts +1 -3
- package/dist/mysql/index.js +1 -1
- package/dist/mysql/mysql-client.d.ts +8 -57
- package/dist/mysql/mysql-client.js +44 -101
- package/dist/mysql/mysql-utils.d.ts +1 -51
- package/dist/mysql/mysql-utils.js +8 -168
- package/dist/mysql/query-validator.d.ts +0 -19
- package/dist/mysql/query-validator.js +0 -19
- package/oclif.manifest.json +176 -59
- package/package.json +3 -2
- package/dist/config.d.ts +0 -13
- package/dist/config.js +0 -18
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.
|
|
29
|
+
@hesed/mysql/0.3.0 linux-x64 node-v24.16.0
|
|
30
30
|
$ mq --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ mq COMMAND
|
|
@@ -38,6 +38,9 @@ USAGE
|
|
|
38
38
|
|
|
39
39
|
<!-- commands -->
|
|
40
40
|
* [`mq mysql auth add`](#mq-mysql-auth-add)
|
|
41
|
+
* [`mq mysql auth delete`](#mq-mysql-auth-delete)
|
|
42
|
+
* [`mq mysql auth list`](#mq-mysql-auth-list)
|
|
43
|
+
* [`mq mysql auth profile`](#mq-mysql-auth-profile)
|
|
41
44
|
* [`mq mysql auth test`](#mq-mysql-auth-test)
|
|
42
45
|
* [`mq mysql auth update`](#mq-mysql-auth-update)
|
|
43
46
|
* [`mq mysql databases`](#mq-mysql-databases)
|
|
@@ -49,90 +52,162 @@ USAGE
|
|
|
49
52
|
|
|
50
53
|
## `mq mysql auth add`
|
|
51
54
|
|
|
52
|
-
Add
|
|
55
|
+
Add MySQL authentication
|
|
53
56
|
|
|
54
57
|
```
|
|
55
58
|
USAGE
|
|
56
|
-
$ mq mysql auth add -
|
|
59
|
+
$ mq mysql auth add -p <value> --host <value> --port <value> -u <value> --password <value> -d <value> --ssl
|
|
60
|
+
[--json]
|
|
57
61
|
|
|
58
62
|
FLAGS
|
|
59
|
-
-P, --port=<value> (required) MySQL port
|
|
60
63
|
-d, --database=<value> (required) Database name
|
|
61
|
-
-p, --
|
|
64
|
+
-p, --profile=<value> (required) Profile name
|
|
62
65
|
-u, --user=<value> (required) Username
|
|
63
66
|
--host=<value> (required) MySQL host
|
|
64
|
-
--
|
|
65
|
-
--
|
|
67
|
+
--password=<value> (required) Password
|
|
68
|
+
--port=<value> (required) MySQL port
|
|
69
|
+
--ssl (required) Use SSL
|
|
66
70
|
|
|
67
71
|
GLOBAL FLAGS
|
|
68
72
|
--json Format output as json.
|
|
69
73
|
|
|
70
74
|
DESCRIPTION
|
|
71
|
-
Add
|
|
75
|
+
Add MySQL authentication
|
|
72
76
|
|
|
73
77
|
EXAMPLES
|
|
74
78
|
$ mq mysql auth add
|
|
75
79
|
|
|
76
|
-
$ mq mysql auth add
|
|
80
|
+
$ mq mysql auth add -p prod
|
|
77
81
|
```
|
|
78
82
|
|
|
79
|
-
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
83
|
+
_See code: [src/commands/mysql/auth/add.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/add.ts)_
|
|
84
|
+
|
|
85
|
+
## `mq mysql auth delete`
|
|
86
|
+
|
|
87
|
+
Delete an authentication profile
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
USAGE
|
|
91
|
+
$ mq mysql auth delete [--json] [-p <value>]
|
|
92
|
+
|
|
93
|
+
FLAGS
|
|
94
|
+
-p, --profile=<value> Profile to delete
|
|
95
|
+
|
|
96
|
+
GLOBAL FLAGS
|
|
97
|
+
--json Format output as json.
|
|
98
|
+
|
|
99
|
+
DESCRIPTION
|
|
100
|
+
Delete an authentication profile
|
|
101
|
+
|
|
102
|
+
EXAMPLES
|
|
103
|
+
$ mq mysql auth delete
|
|
104
|
+
|
|
105
|
+
$ mq mysql auth delete -p prod
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
_See code: [src/commands/mysql/auth/delete.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/delete.ts)_
|
|
109
|
+
|
|
110
|
+
## `mq mysql auth list`
|
|
111
|
+
|
|
112
|
+
List authentication profiles
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
USAGE
|
|
116
|
+
$ mq mysql auth list [--json]
|
|
117
|
+
|
|
118
|
+
GLOBAL FLAGS
|
|
119
|
+
--json Format output as json.
|
|
120
|
+
|
|
121
|
+
DESCRIPTION
|
|
122
|
+
List authentication profiles
|
|
123
|
+
|
|
124
|
+
EXAMPLES
|
|
125
|
+
$ mq mysql auth list
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
_See code: [src/commands/mysql/auth/list.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/list.ts)_
|
|
129
|
+
|
|
130
|
+
## `mq mysql auth profile`
|
|
131
|
+
|
|
132
|
+
Set or show the default authentication profile
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
USAGE
|
|
136
|
+
$ mq mysql auth profile [--json] [--default <value>]
|
|
137
|
+
|
|
138
|
+
FLAGS
|
|
139
|
+
--default=<value> Profile to set as default
|
|
140
|
+
|
|
141
|
+
GLOBAL FLAGS
|
|
142
|
+
--json Format output as json.
|
|
143
|
+
|
|
144
|
+
DESCRIPTION
|
|
145
|
+
Set or show the default authentication profile
|
|
146
|
+
|
|
147
|
+
EXAMPLES
|
|
148
|
+
$ mq mysql auth profile
|
|
149
|
+
|
|
150
|
+
$ mq mysql auth profile --default test
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
_See code: [src/commands/mysql/auth/profile.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/profile.ts)_
|
|
80
154
|
|
|
81
155
|
## `mq mysql auth test`
|
|
82
156
|
|
|
83
|
-
Test
|
|
157
|
+
Test authentication and connection
|
|
84
158
|
|
|
85
159
|
```
|
|
86
160
|
USAGE
|
|
87
|
-
$ mq mysql auth test [--json] [
|
|
161
|
+
$ mq mysql auth test [--json] [-p <value>]
|
|
88
162
|
|
|
89
163
|
FLAGS
|
|
90
|
-
--profile=<value>
|
|
164
|
+
-p, --profile=<value> Authentication profile name
|
|
91
165
|
|
|
92
166
|
GLOBAL FLAGS
|
|
93
167
|
--json Format output as json.
|
|
94
168
|
|
|
95
169
|
DESCRIPTION
|
|
96
|
-
Test
|
|
170
|
+
Test authentication and connection
|
|
97
171
|
|
|
98
172
|
EXAMPLES
|
|
99
173
|
$ mq mysql auth test
|
|
100
174
|
|
|
101
|
-
$ mq mysql auth test
|
|
175
|
+
$ mq mysql auth test -p prod
|
|
102
176
|
```
|
|
103
177
|
|
|
104
|
-
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
178
|
+
_See code: [src/commands/mysql/auth/test.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/test.ts)_
|
|
105
179
|
|
|
106
180
|
## `mq mysql auth update`
|
|
107
181
|
|
|
108
|
-
Update
|
|
182
|
+
Update MySQL authentication
|
|
109
183
|
|
|
110
184
|
```
|
|
111
185
|
USAGE
|
|
112
|
-
$ mq mysql auth update -
|
|
186
|
+
$ mq mysql auth update -p <value> --host <value> --port <value> -u <value> --password <value> -d <value> --ssl
|
|
187
|
+
[--json]
|
|
113
188
|
|
|
114
189
|
FLAGS
|
|
115
|
-
-P, --port=<value> (required) MySQL port
|
|
116
190
|
-d, --database=<value> (required) Database name
|
|
117
|
-
-p, --
|
|
191
|
+
-p, --profile=<value> (required) Profile name
|
|
118
192
|
-u, --user=<value> (required) Username
|
|
119
193
|
--host=<value> (required) MySQL host
|
|
120
|
-
--
|
|
121
|
-
--
|
|
194
|
+
--password=<value> (required) Password
|
|
195
|
+
--port=<value> (required) MySQL port
|
|
196
|
+
--ssl (required) Use SSL
|
|
122
197
|
|
|
123
198
|
GLOBAL FLAGS
|
|
124
199
|
--json Format output as json.
|
|
125
200
|
|
|
126
201
|
DESCRIPTION
|
|
127
|
-
Update
|
|
202
|
+
Update MySQL authentication
|
|
128
203
|
|
|
129
204
|
EXAMPLES
|
|
130
|
-
$ mq mysql auth update
|
|
205
|
+
$ mq mysql auth update
|
|
131
206
|
|
|
132
|
-
$ mq mysql auth update
|
|
207
|
+
$ mq mysql auth update -p test
|
|
133
208
|
```
|
|
134
209
|
|
|
135
|
-
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
210
|
+
_See code: [src/commands/mysql/auth/update.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/auth/update.ts)_
|
|
136
211
|
|
|
137
212
|
## `mq mysql databases`
|
|
138
213
|
|
|
@@ -154,7 +229,7 @@ EXAMPLES
|
|
|
154
229
|
$ mq mysql databases --profile staging
|
|
155
230
|
```
|
|
156
231
|
|
|
157
|
-
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
232
|
+
_See code: [src/commands/mysql/databases.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/databases.ts)_
|
|
158
233
|
|
|
159
234
|
## `mq mysql describe-table TABLE`
|
|
160
235
|
|
|
@@ -181,7 +256,7 @@ EXAMPLES
|
|
|
181
256
|
$ mq mysql describe-table orders --format json --profile prod
|
|
182
257
|
```
|
|
183
258
|
|
|
184
|
-
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
259
|
+
_See code: [src/commands/mysql/describe-table.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/describe-table.ts)_
|
|
185
260
|
|
|
186
261
|
## `mq mysql explain-query QUERY`
|
|
187
262
|
|
|
@@ -208,7 +283,7 @@ EXAMPLES
|
|
|
208
283
|
$ mq mysql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
|
|
209
284
|
```
|
|
210
285
|
|
|
211
|
-
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
286
|
+
_See code: [src/commands/mysql/explain-query.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/explain-query.ts)_
|
|
212
287
|
|
|
213
288
|
## `mq mysql indexes TABLE`
|
|
214
289
|
|
|
@@ -235,7 +310,7 @@ EXAMPLES
|
|
|
235
310
|
$ mq mysql indexes orders --format json --profile prod
|
|
236
311
|
```
|
|
237
312
|
|
|
238
|
-
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
313
|
+
_See code: [src/commands/mysql/indexes.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/indexes.ts)_
|
|
239
314
|
|
|
240
315
|
## `mq mysql query QUERY`
|
|
241
316
|
|
|
@@ -265,7 +340,7 @@ EXAMPLES
|
|
|
265
340
|
$ mq mysql query "DELETE FROM sessions" --profile prod --skip-confirmation
|
|
266
341
|
```
|
|
267
342
|
|
|
268
|
-
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
343
|
+
_See code: [src/commands/mysql/query.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/query.ts)_
|
|
269
344
|
|
|
270
345
|
## `mq mysql tables`
|
|
271
346
|
|
|
@@ -287,5 +362,5 @@ EXAMPLES
|
|
|
287
362
|
$ mq mysql tables --profile local
|
|
288
363
|
```
|
|
289
364
|
|
|
290
|
-
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.
|
|
365
|
+
_See code: [src/commands/mysql/tables.ts](https://github.com/hesedcasa/mysql/blob/v0.3.0/src/commands/mysql/tables.ts)_
|
|
291
366
|
<!-- commandsstop -->
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class AuthAdd extends Command {
|
|
4
|
-
static args: {};
|
|
5
|
-
static description: string;
|
|
6
|
-
static enableJsonFlag: boolean;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
database: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
-
port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
-
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
ssl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
-
user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
-
};
|
|
17
|
-
run(): Promise<ConnectionTestResult>;
|
|
18
|
-
}
|
|
1
|
+
declare const _default: typeof import("@oclif/core").Command;
|
|
2
|
+
export default _default;
|
|
@@ -1,57 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
profile: Flags.string({ description: 'Profile name', required: !process.stdout.isTTY }),
|
|
18
|
-
ssl: Flags.boolean({ allowNo: true, default: false, description: 'Use SSL', required: false }),
|
|
19
|
-
user: Flags.string({ char: 'u', description: 'Username', required: !process.stdout.isTTY }),
|
|
20
|
-
};
|
|
21
|
-
async run() {
|
|
22
|
-
const { flags } = await this.parse(AuthAdd);
|
|
23
|
-
const profileName = flags.profile ?? (await input({ message: 'Profile name:', required: true }));
|
|
24
|
-
const host = flags.host ?? (await input({ message: 'MySQL host:', required: true }));
|
|
25
|
-
const port = flags.port ?? Number(await input({ default: '3306', message: 'Port:', required: true }));
|
|
26
|
-
const user = flags.user ?? (await input({ message: 'Username:', required: true }));
|
|
27
|
-
const password = flags.password ?? (await input({ message: 'Password:', required: true }));
|
|
28
|
-
const database = flags.database ?? (await input({ message: 'Database:', required: true }));
|
|
29
|
-
const configPath = path.join(this.config.configDir, 'mysql-config.json');
|
|
30
|
-
const profileData = { database, host, password, port, ssl: flags.ssl, user };
|
|
31
|
-
const exists = await fs.pathExists(configPath);
|
|
32
|
-
let config;
|
|
33
|
-
if (exists) {
|
|
34
|
-
config = await fs.readJSON(configPath);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
await fs.createFile(configPath);
|
|
38
|
-
config = { defaultProfile: profileName, profiles: {} };
|
|
39
|
-
}
|
|
40
|
-
config.profiles[profileName] = profileData;
|
|
41
|
-
if (Object.keys(config.profiles).length === 1) {
|
|
42
|
-
config.defaultProfile = profileName;
|
|
43
|
-
}
|
|
44
|
-
await fs.writeJSON(configPath, config, { mode: 0o600 });
|
|
45
|
-
action.start('Testing connection');
|
|
46
|
-
const result = await testDirectConnection(profileData);
|
|
47
|
-
if (result.success) {
|
|
48
|
-
action.stop('✓ successful');
|
|
49
|
-
this.log(`Profile "${profileName}" added successfully`);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
action.stop('✗ failed');
|
|
53
|
-
this.error('Connection failed. Please check your configuration.');
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { createAuthAddCommand } from '@hesed/plugin-lib';
|
|
2
|
+
import { closeConnections, testDirectConnection } from '../../../mysql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'MySQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 3306, description: 'MySQL port', name: 'port', type: 'number' },
|
|
6
|
+
{ char: 'u', description: 'Username', name: 'user', type: 'string' },
|
|
7
|
+
{ description: 'Password', name: 'password', type: 'string' },
|
|
8
|
+
{ char: 'd', description: 'Database name', name: 'database', type: 'string' },
|
|
9
|
+
{ default: false, description: 'Use SSL', name: 'ssl', required: false, type: 'boolean' },
|
|
10
|
+
];
|
|
11
|
+
export default createAuthAddCommand({
|
|
12
|
+
clearClients: closeConnections,
|
|
13
|
+
fields,
|
|
14
|
+
serviceName: 'MySQL',
|
|
15
|
+
testConnection: testDirectConnection,
|
|
16
|
+
});
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class AuthTest extends Command {
|
|
4
|
-
static args: {};
|
|
5
|
-
static description: string;
|
|
6
|
-
static enableJsonFlag: boolean;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
};
|
|
11
|
-
run(): Promise<ConnectionTestResult>;
|
|
12
|
-
}
|
|
1
|
+
declare const _default: typeof import("@oclif/core").Command;
|
|
2
|
+
export default _default;
|
|
@@ -1,41 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { flags } = await this.parse(AuthTest);
|
|
18
|
-
const config = await readConfig(this.config.configDir, this.log.bind(this));
|
|
19
|
-
if (!config) {
|
|
20
|
-
return {
|
|
21
|
-
error: 'Missing connection config',
|
|
22
|
-
success: false,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const profile = config.profiles[flags.profile ?? config.defaultProfile];
|
|
26
|
-
if (!profile) {
|
|
27
|
-
this.error(`Profile "${flags.profile}" not found. Available: ${Object.keys(config.profiles).join(', ')}`);
|
|
28
|
-
}
|
|
29
|
-
action.start('Testing connection');
|
|
30
|
-
const result = await testDirectConnection(profile);
|
|
31
|
-
if (result.success) {
|
|
32
|
-
action.stop('✓ successful');
|
|
33
|
-
this.log('Successfully connected to MySQL');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
action.stop('✗ failed');
|
|
37
|
-
this.error('Failed to connect to MySQL.');
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
import { createAuthTestCommand } from '@hesed/plugin-lib';
|
|
2
|
+
import { closeConnections, testDirectConnection } from '../../../mysql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'MySQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 3306, description: 'MySQL port', name: 'port', type: 'number' },
|
|
6
|
+
{ char: 'u', description: 'Username', name: 'user', type: 'string' },
|
|
7
|
+
{ description: 'Password', name: 'password', type: 'string' },
|
|
8
|
+
{ char: 'd', description: 'Database name', name: 'database', type: 'string' },
|
|
9
|
+
{ default: false, description: 'Use SSL', name: 'ssl', required: false, type: 'boolean' },
|
|
10
|
+
];
|
|
11
|
+
export default createAuthTestCommand({
|
|
12
|
+
clearClients: closeConnections,
|
|
13
|
+
fields,
|
|
14
|
+
serviceName: 'MySQL',
|
|
15
|
+
testConnection: testDirectConnection,
|
|
16
|
+
});
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class AuthUpdate extends Command {
|
|
4
|
-
static args: {};
|
|
5
|
-
static description: string;
|
|
6
|
-
static enableJsonFlag: boolean;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
database: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
host: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
-
port: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
-
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
ssl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
-
user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
-
};
|
|
17
|
-
run(): Promise<ConnectionTestResult | void>;
|
|
18
|
-
}
|
|
1
|
+
declare const _default: typeof import("@oclif/core").Command;
|
|
2
|
+
export default _default;
|
|
@@ -1,74 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
host: Flags.string({ description: 'MySQL host', required: !process.stdout.isTTY }),
|
|
18
|
-
password: Flags.string({ char: 'p', description: 'Password', required: !process.stdout.isTTY }),
|
|
19
|
-
port: Flags.integer({ char: 'P', description: 'MySQL port', required: !process.stdout.isTTY }),
|
|
20
|
-
profile: Flags.string({ description: 'Profile name to update', required: false }),
|
|
21
|
-
ssl: Flags.boolean({ allowNo: true, default: false, description: 'Use SSL', required: false }),
|
|
22
|
-
user: Flags.string({ char: 'u', description: 'Username', required: !process.stdout.isTTY }),
|
|
23
|
-
};
|
|
24
|
-
async run() {
|
|
25
|
-
const { flags } = await this.parse(AuthUpdate);
|
|
26
|
-
const configPath = path.join(this.config.configDir, 'mysql-config.json');
|
|
27
|
-
let config;
|
|
28
|
-
try {
|
|
29
|
-
config = await fs.readJSON(configPath);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
33
|
-
if (msg.toLowerCase().includes('no such file or directory')) {
|
|
34
|
-
this.log('Run auth:add instead');
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this.log(msg);
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const profileName = flags.profile ?? config.defaultProfile;
|
|
42
|
-
const existingProfile = config.profiles[profileName];
|
|
43
|
-
if (!existingProfile) {
|
|
44
|
-
this.error(`Profile "${profileName}" not found. Available: ${Object.keys(config.profiles).join(', ')}`);
|
|
45
|
-
}
|
|
46
|
-
const host = flags.host ??
|
|
47
|
-
(await input({ default: existingProfile.host, message: 'MySQL host:', prefill: 'tab', required: true }));
|
|
48
|
-
const port = flags.port ??
|
|
49
|
-
Number(await input({ default: String(existingProfile.port), message: 'Port:', prefill: 'tab', required: true }));
|
|
50
|
-
const user = flags.user ?? (await input({ default: existingProfile.user, message: 'Username:', prefill: 'tab', required: true }));
|
|
51
|
-
const password = flags.password ??
|
|
52
|
-
(await input({ default: existingProfile.password, message: 'Password:', prefill: 'tab', required: true }));
|
|
53
|
-
const database = flags.database ??
|
|
54
|
-
(await input({ default: existingProfile.database, message: 'Database:', prefill: 'tab', required: true }));
|
|
55
|
-
const answer = await confirm({ message: `Override profile "${profileName}"?` });
|
|
56
|
-
if (!answer) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
config.profiles[profileName] = { database, host, password, port, ssl: flags.ssl, user };
|
|
60
|
-
await fs.writeJSON(configPath, config, { mode: 0o600 });
|
|
61
|
-
action.start('Testing connection');
|
|
62
|
-
const updatedConfig = await fs.readJSON(configPath);
|
|
63
|
-
const result = await testDirectConnection(updatedConfig.profiles[profileName]);
|
|
64
|
-
if (result.success) {
|
|
65
|
-
action.stop('✓ successful');
|
|
66
|
-
this.log(`Profile "${profileName}" updated successfully`);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
action.stop('✗ failed');
|
|
70
|
-
this.error('Connection failed. Please check your configuration.');
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
import { createAuthUpdateCommand } from '@hesed/plugin-lib';
|
|
2
|
+
import { closeConnections, testDirectConnection } from '../../../mysql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'MySQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 3306, description: 'MySQL port', name: 'port', type: 'number' },
|
|
6
|
+
{ char: 'u', description: 'Username', name: 'user', type: 'string' },
|
|
7
|
+
{ description: 'Password', name: 'password', type: 'string' },
|
|
8
|
+
{ char: 'd', description: 'Database name', name: 'database', type: 'string' },
|
|
9
|
+
{ default: false, description: 'Use SSL', name: 'ssl', required: false, type: 'boolean' },
|
|
10
|
+
];
|
|
11
|
+
export default createAuthUpdateCommand({
|
|
12
|
+
clearClients: closeConnections,
|
|
13
|
+
fields,
|
|
14
|
+
serviceName: 'MySQL',
|
|
15
|
+
testConnection: testDirectConnection,
|
|
16
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
-
import { closeConnections,
|
|
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
5
|
static examples = [
|
|
@@ -11,15 +11,7 @@ export default class MySQLDatabases extends Command {
|
|
|
11
11
|
};
|
|
12
12
|
async run() {
|
|
13
13
|
const { flags } = await this.parse(MySQLDatabases);
|
|
14
|
-
|
|
15
|
-
let profile;
|
|
16
|
-
try {
|
|
17
|
-
profile = flags.profile ?? (await getMySQLConfig()).defaultProfile;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
this.error(error instanceof Error ? error.message : String(error));
|
|
21
|
-
}
|
|
22
|
-
const result = await listDatabases(profile);
|
|
14
|
+
const result = await listDatabases(this.config, flags.profile);
|
|
23
15
|
await closeConnections();
|
|
24
16
|
if (result.success) {
|
|
25
17
|
this.logJson(result.databases);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
-
import { closeConnections, describeTable
|
|
2
|
+
import { closeConnections, describeTable } from '../../mysql/index.js';
|
|
3
3
|
export default class MySQLDescribeTable extends Command {
|
|
4
4
|
static args = {
|
|
5
5
|
table: Args.string({ description: 'Table name to describe', required: true }),
|
|
@@ -19,15 +19,7 @@ export default class MySQLDescribeTable extends Command {
|
|
|
19
19
|
};
|
|
20
20
|
async run() {
|
|
21
21
|
const { args, flags } = await this.parse(MySQLDescribeTable);
|
|
22
|
-
|
|
23
|
-
let profile;
|
|
24
|
-
try {
|
|
25
|
-
profile = flags.profile ?? (await getMySQLConfig()).defaultProfile;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
this.error(error instanceof Error ? error.message : String(error));
|
|
29
|
-
}
|
|
30
|
-
const result = await describeTable(profile, args.table, flags.format);
|
|
22
|
+
const result = await describeTable(this.config, args.table, flags.profile, flags.format);
|
|
31
23
|
await closeConnections();
|
|
32
24
|
if (result.success) {
|
|
33
25
|
this.log(result.result ?? '');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
-
import { closeConnections, explainQuery
|
|
2
|
+
import { closeConnections, explainQuery } from '../../mysql/index.js';
|
|
3
3
|
export default class MySQLExplain extends Command {
|
|
4
4
|
static args = {
|
|
5
5
|
query: Args.string({ description: 'SQL query to explain', required: true }),
|
|
@@ -19,15 +19,7 @@ export default class MySQLExplain extends Command {
|
|
|
19
19
|
};
|
|
20
20
|
async run() {
|
|
21
21
|
const { args, flags } = await this.parse(MySQLExplain);
|
|
22
|
-
|
|
23
|
-
let profile;
|
|
24
|
-
try {
|
|
25
|
-
profile = flags.profile ?? (await getMySQLConfig()).defaultProfile;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
this.error(error instanceof Error ? error.message : String(error));
|
|
29
|
-
}
|
|
30
|
-
const result = await explainQuery(profile, args.query, flags.format);
|
|
22
|
+
const result = await explainQuery(this.config, args.query, flags.profile, flags.format);
|
|
31
23
|
await closeConnections();
|
|
32
24
|
if (result.success) {
|
|
33
25
|
this.log(result.result ?? '');
|