@hesed/psql 0.2.1 → 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/psql/auth/add.d.ts +2 -18
- package/dist/commands/psql/auth/add.js +16 -57
- package/dist/commands/psql/auth/delete.d.ts +2 -0
- package/dist/commands/psql/auth/delete.js +2 -0
- package/dist/commands/psql/auth/list.d.ts +2 -0
- package/dist/commands/psql/auth/list.js +2 -0
- package/dist/commands/psql/auth/profile.d.ts +2 -0
- package/dist/commands/psql/auth/profile.js +2 -0
- package/dist/commands/psql/auth/test.d.ts +2 -12
- package/dist/commands/psql/auth/test.js +16 -41
- package/dist/commands/psql/auth/update.d.ts +2 -18
- package/dist/commands/psql/auth/update.js +16 -74
- package/dist/commands/psql/databases.js +2 -10
- package/dist/commands/psql/describe-table.js +2 -10
- package/dist/commands/psql/explain-query.js +2 -10
- package/dist/commands/psql/indexes.js +2 -10
- package/dist/commands/psql/query.js +2 -10
- package/dist/commands/psql/tables.js +2 -10
- package/dist/psql/config-loader.d.ts +8 -14
- package/dist/psql/config-loader.js +0 -7
- package/dist/psql/formatters.d.ts +8 -0
- package/dist/psql/formatters.js +76 -0
- package/dist/psql/index.d.ts +1 -2
- package/dist/psql/index.js +1 -1
- package/dist/psql/postgres-client.d.ts +8 -57
- package/dist/psql/postgres-client.js +44 -101
- package/dist/psql/postgres-utils.d.ts +2 -56
- package/dist/psql/postgres-utils.js +36 -179
- package/dist/psql/query-validator.d.ts +0 -19
- package/dist/psql/query-validator.js +13 -20
- package/oclif.manifest.json +176 -59
- package/package.json +2 -1
- 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/psql
|
|
|
26
26
|
$ pg COMMAND
|
|
27
27
|
running command...
|
|
28
28
|
$ pg (--version)
|
|
29
|
-
@hesed/psql/0.
|
|
29
|
+
@hesed/psql/0.3.0 linux-x64 node-v24.16.0
|
|
30
30
|
$ pg --help [COMMAND]
|
|
31
31
|
USAGE
|
|
32
32
|
$ pg COMMAND
|
|
@@ -38,6 +38,9 @@ USAGE
|
|
|
38
38
|
|
|
39
39
|
<!-- commands -->
|
|
40
40
|
* [`pg psql auth add`](#pg-psql-auth-add)
|
|
41
|
+
* [`pg psql auth delete`](#pg-psql-auth-delete)
|
|
42
|
+
* [`pg psql auth list`](#pg-psql-auth-list)
|
|
43
|
+
* [`pg psql auth profile`](#pg-psql-auth-profile)
|
|
41
44
|
* [`pg psql auth test`](#pg-psql-auth-test)
|
|
42
45
|
* [`pg psql auth update`](#pg-psql-auth-update)
|
|
43
46
|
* [`pg psql databases`](#pg-psql-databases)
|
|
@@ -49,90 +52,162 @@ USAGE
|
|
|
49
52
|
|
|
50
53
|
## `pg psql auth add`
|
|
51
54
|
|
|
52
|
-
Add
|
|
55
|
+
Add PostgreSQL authentication
|
|
53
56
|
|
|
54
57
|
```
|
|
55
58
|
USAGE
|
|
56
|
-
$ pg psql auth add -
|
|
59
|
+
$ pg psql 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) PostgreSQL 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) PostgreSQL host
|
|
64
|
-
--
|
|
65
|
-
--
|
|
67
|
+
--password=<value> (required) Password
|
|
68
|
+
--port=<value> (required) PostgreSQL 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 PostgreSQL authentication
|
|
72
76
|
|
|
73
77
|
EXAMPLES
|
|
74
78
|
$ pg psql auth add
|
|
75
79
|
|
|
76
|
-
$ pg psql auth add
|
|
80
|
+
$ pg psql auth add -p prod
|
|
77
81
|
```
|
|
78
82
|
|
|
79
|
-
_See code: [src/commands/psql/auth/add.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
83
|
+
_See code: [src/commands/psql/auth/add.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/add.ts)_
|
|
84
|
+
|
|
85
|
+
## `pg psql auth delete`
|
|
86
|
+
|
|
87
|
+
Delete an authentication profile
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
USAGE
|
|
91
|
+
$ pg psql 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
|
+
$ pg psql auth delete
|
|
104
|
+
|
|
105
|
+
$ pg psql auth delete -p prod
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
_See code: [src/commands/psql/auth/delete.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/delete.ts)_
|
|
109
|
+
|
|
110
|
+
## `pg psql auth list`
|
|
111
|
+
|
|
112
|
+
List authentication profiles
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
USAGE
|
|
116
|
+
$ pg psql auth list [--json]
|
|
117
|
+
|
|
118
|
+
GLOBAL FLAGS
|
|
119
|
+
--json Format output as json.
|
|
120
|
+
|
|
121
|
+
DESCRIPTION
|
|
122
|
+
List authentication profiles
|
|
123
|
+
|
|
124
|
+
EXAMPLES
|
|
125
|
+
$ pg psql auth list
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
_See code: [src/commands/psql/auth/list.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/list.ts)_
|
|
129
|
+
|
|
130
|
+
## `pg psql auth profile`
|
|
131
|
+
|
|
132
|
+
Set or show the default authentication profile
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
USAGE
|
|
136
|
+
$ pg psql 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
|
+
$ pg psql auth profile
|
|
149
|
+
|
|
150
|
+
$ pg psql auth profile --default test
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
_See code: [src/commands/psql/auth/profile.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/profile.ts)_
|
|
80
154
|
|
|
81
155
|
## `pg psql auth test`
|
|
82
156
|
|
|
83
|
-
Test
|
|
157
|
+
Test authentication and connection
|
|
84
158
|
|
|
85
159
|
```
|
|
86
160
|
USAGE
|
|
87
|
-
$ pg psql auth test [--json] [
|
|
161
|
+
$ pg psql 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
|
$ pg psql auth test
|
|
100
174
|
|
|
101
|
-
$ pg psql auth test
|
|
175
|
+
$ pg psql auth test -p prod
|
|
102
176
|
```
|
|
103
177
|
|
|
104
|
-
_See code: [src/commands/psql/auth/test.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
178
|
+
_See code: [src/commands/psql/auth/test.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/test.ts)_
|
|
105
179
|
|
|
106
180
|
## `pg psql auth update`
|
|
107
181
|
|
|
108
|
-
Update
|
|
182
|
+
Update PostgreSQL authentication
|
|
109
183
|
|
|
110
184
|
```
|
|
111
185
|
USAGE
|
|
112
|
-
$ pg psql auth update -
|
|
186
|
+
$ pg psql 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) PostgreSQL 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) PostgreSQL host
|
|
120
|
-
--
|
|
121
|
-
--
|
|
194
|
+
--password=<value> (required) Password
|
|
195
|
+
--port=<value> (required) PostgreSQL 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 PostgreSQL authentication
|
|
128
203
|
|
|
129
204
|
EXAMPLES
|
|
130
|
-
$ pg psql auth update
|
|
205
|
+
$ pg psql auth update
|
|
131
206
|
|
|
132
|
-
$ pg psql auth update
|
|
207
|
+
$ pg psql auth update -p test
|
|
133
208
|
```
|
|
134
209
|
|
|
135
|
-
_See code: [src/commands/psql/auth/update.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
210
|
+
_See code: [src/commands/psql/auth/update.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/auth/update.ts)_
|
|
136
211
|
|
|
137
212
|
## `pg psql databases`
|
|
138
213
|
|
|
@@ -154,7 +229,7 @@ EXAMPLES
|
|
|
154
229
|
$ pg psql databases --profile staging
|
|
155
230
|
```
|
|
156
231
|
|
|
157
|
-
_See code: [src/commands/psql/databases.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
232
|
+
_See code: [src/commands/psql/databases.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/databases.ts)_
|
|
158
233
|
|
|
159
234
|
## `pg psql describe-table TABLE`
|
|
160
235
|
|
|
@@ -181,7 +256,7 @@ EXAMPLES
|
|
|
181
256
|
$ pg psql describe-table orders --format json --profile prod
|
|
182
257
|
```
|
|
183
258
|
|
|
184
|
-
_See code: [src/commands/psql/describe-table.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
259
|
+
_See code: [src/commands/psql/describe-table.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/describe-table.ts)_
|
|
185
260
|
|
|
186
261
|
## `pg psql explain-query QUERY`
|
|
187
262
|
|
|
@@ -208,7 +283,7 @@ EXAMPLES
|
|
|
208
283
|
$ pg psql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
|
|
209
284
|
```
|
|
210
285
|
|
|
211
|
-
_See code: [src/commands/psql/explain-query.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
286
|
+
_See code: [src/commands/psql/explain-query.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/explain-query.ts)_
|
|
212
287
|
|
|
213
288
|
## `pg psql indexes TABLE`
|
|
214
289
|
|
|
@@ -235,7 +310,7 @@ EXAMPLES
|
|
|
235
310
|
$ pg psql indexes orders --format json --profile prod
|
|
236
311
|
```
|
|
237
312
|
|
|
238
|
-
_See code: [src/commands/psql/indexes.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
313
|
+
_See code: [src/commands/psql/indexes.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/indexes.ts)_
|
|
239
314
|
|
|
240
315
|
## `pg psql query QUERY`
|
|
241
316
|
|
|
@@ -265,7 +340,7 @@ EXAMPLES
|
|
|
265
340
|
$ pg psql query "DELETE FROM sessions" --profile prod --skip-confirmation
|
|
266
341
|
```
|
|
267
342
|
|
|
268
|
-
_See code: [src/commands/psql/query.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
343
|
+
_See code: [src/commands/psql/query.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/query.ts)_
|
|
269
344
|
|
|
270
345
|
## `pg psql tables`
|
|
271
346
|
|
|
@@ -287,5 +362,5 @@ EXAMPLES
|
|
|
287
362
|
$ pg psql tables --profile local
|
|
288
363
|
```
|
|
289
364
|
|
|
290
|
-
_See code: [src/commands/psql/tables.ts](https://github.com/hesedcasa/psql/blob/v0.
|
|
365
|
+
_See code: [src/commands/psql/tables.ts](https://github.com/hesedcasa/psql/blob/v0.3.0/src/commands/psql/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: 'PostgreSQL host:', required: true }));
|
|
25
|
-
const port = flags.port ?? Number(await input({ default: '5432', 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, 'pg-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 '../../../psql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'PostgreSQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 5432, description: 'PostgreSQL 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: 'PostgreSQL',
|
|
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 PostgreSQL');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
action.stop('✗ failed');
|
|
37
|
-
this.error('Failed to connect to PostgreSQL.');
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
import { createAuthTestCommand } from '@hesed/plugin-lib';
|
|
2
|
+
import { closeConnections, testDirectConnection } from '../../../psql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'PostgreSQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 5432, description: 'PostgreSQL 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: 'PostgreSQL',
|
|
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: 'PostgreSQL host', required: !process.stdout.isTTY }),
|
|
18
|
-
password: Flags.string({ char: 'p', description: 'Password', required: !process.stdout.isTTY }),
|
|
19
|
-
port: Flags.integer({ char: 'P', description: 'PostgreSQL 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, 'pg-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: 'PostgreSQL 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 '../../../psql/index.js';
|
|
3
|
+
const fields = [
|
|
4
|
+
{ description: 'PostgreSQL host', name: 'host', type: 'string' },
|
|
5
|
+
{ default: 5432, description: 'PostgreSQL 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: 'PostgreSQL',
|
|
15
|
+
testConnection: testDirectConnection,
|
|
16
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, Flags } from '@oclif/core';
|
|
2
|
-
import { closeConnections,
|
|
2
|
+
import { closeConnections, listDatabases } from '../../psql/index.js';
|
|
3
3
|
export default class PostgresDatabases extends Command {
|
|
4
4
|
static description = 'List all databases accessible on the PostgreSQL server';
|
|
5
5
|
static examples = [
|
|
@@ -11,15 +11,7 @@ export default class PostgresDatabases extends Command {
|
|
|
11
11
|
};
|
|
12
12
|
async run() {
|
|
13
13
|
const { flags } = await this.parse(PostgresDatabases);
|
|
14
|
-
|
|
15
|
-
let profile;
|
|
16
|
-
try {
|
|
17
|
-
profile = flags.profile ?? (await getPgConfig()).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 '../../psql/index.js';
|
|
3
3
|
export default class PostgresDescribeTable 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 PostgresDescribeTable extends Command {
|
|
|
19
19
|
};
|
|
20
20
|
async run() {
|
|
21
21
|
const { args, flags } = await this.parse(PostgresDescribeTable);
|
|
22
|
-
|
|
23
|
-
let profile;
|
|
24
|
-
try {
|
|
25
|
-
profile = flags.profile ?? (await getPgConfig()).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 '../../psql/index.js';
|
|
3
3
|
export default class PostgresExplain 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 PostgresExplain extends Command {
|
|
|
19
19
|
};
|
|
20
20
|
async run() {
|
|
21
21
|
const { args, flags } = await this.parse(PostgresExplain);
|
|
22
|
-
|
|
23
|
-
let profile;
|
|
24
|
-
try {
|
|
25
|
-
profile = flags.profile ?? (await getPgConfig()).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 ?? '');
|