@hesed/psql 0.2.0 → 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 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.2.0 linux-x64 node-v22.22.0
29
+ @hesed/psql/0.2.2 linux-x64 node-v22.22.1
30
30
  $ pg --help [COMMAND]
31
31
  USAGE
32
32
  $ pg COMMAND
@@ -76,7 +76,7 @@ EXAMPLES
76
76
  $ pg psql auth add --no-ssl
77
77
  ```
78
78
 
79
- _See code: [src/commands/psql/auth/add.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/auth/add.ts)_
79
+ _See code: [src/commands/psql/auth/add.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/auth/add.ts)_
80
80
 
81
81
  ## `pg psql auth test`
82
82
 
@@ -101,7 +101,7 @@ EXAMPLES
101
101
  $ pg psql auth test --profile staging
102
102
  ```
103
103
 
104
- _See code: [src/commands/psql/auth/test.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/auth/test.ts)_
104
+ _See code: [src/commands/psql/auth/test.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/auth/test.ts)_
105
105
 
106
106
  ## `pg psql auth update`
107
107
 
@@ -132,7 +132,7 @@ EXAMPLES
132
132
  $ pg psql auth update --profile staging
133
133
  ```
134
134
 
135
- _See code: [src/commands/psql/auth/update.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/auth/update.ts)_
135
+ _See code: [src/commands/psql/auth/update.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/auth/update.ts)_
136
136
 
137
137
  ## `pg psql databases`
138
138
 
@@ -154,7 +154,7 @@ EXAMPLES
154
154
  $ pg psql databases --profile staging
155
155
  ```
156
156
 
157
- _See code: [src/commands/psql/databases.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/databases.ts)_
157
+ _See code: [src/commands/psql/databases.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/databases.ts)_
158
158
 
159
159
  ## `pg psql describe-table TABLE`
160
160
 
@@ -181,7 +181,7 @@ EXAMPLES
181
181
  $ pg psql describe-table orders --format json --profile prod
182
182
  ```
183
183
 
184
- _See code: [src/commands/psql/describe-table.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/describe-table.ts)_
184
+ _See code: [src/commands/psql/describe-table.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/describe-table.ts)_
185
185
 
186
186
  ## `pg psql explain-query QUERY`
187
187
 
@@ -208,7 +208,7 @@ EXAMPLES
208
208
  $ pg psql explain-query "SELECT * FROM orders JOIN users ON orders.user_id = users.id" --format json
209
209
  ```
210
210
 
211
- _See code: [src/commands/psql/explain-query.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/explain-query.ts)_
211
+ _See code: [src/commands/psql/explain-query.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/explain-query.ts)_
212
212
 
213
213
  ## `pg psql indexes TABLE`
214
214
 
@@ -235,7 +235,7 @@ EXAMPLES
235
235
  $ pg psql indexes orders --format json --profile prod
236
236
  ```
237
237
 
238
- _See code: [src/commands/psql/indexes.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/indexes.ts)_
238
+ _See code: [src/commands/psql/indexes.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/indexes.ts)_
239
239
 
240
240
  ## `pg psql query QUERY`
241
241
 
@@ -265,7 +265,7 @@ EXAMPLES
265
265
  $ pg psql query "DELETE FROM sessions" --profile prod --skip-confirmation
266
266
  ```
267
267
 
268
- _See code: [src/commands/psql/query.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/query.ts)_
268
+ _See code: [src/commands/psql/query.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/query.ts)_
269
269
 
270
270
  ## `pg psql tables`
271
271
 
@@ -287,5 +287,5 @@ EXAMPLES
287
287
  $ pg psql tables --profile local
288
288
  ```
289
289
 
290
- _See code: [src/commands/psql/tables.ts](https://github.com/hesedcasa/psql/blob/v0.2.0/src/commands/psql/tables.ts)_
290
+ _See code: [src/commands/psql/tables.ts](https://github.com/hesedcasa/psql/blob/v0.2.2/src/commands/psql/tables.ts)_
291
291
  <!-- commandsstop -->
@@ -10,7 +10,7 @@ type PgField = {
10
10
  */
11
11
  export declare class PostgreSQLUtil implements DatabaseUtil {
12
12
  private config;
13
- private connectionPool;
13
+ private connections;
14
14
  constructor(config: PgConfig);
15
15
  /**
16
16
  * Close all connections
@@ -8,17 +8,18 @@ import { analyzeQuery, applyDefaultLimit, checkBlacklist, getQueryType, requires
8
8
  */
9
9
  export class PostgreSQLUtil {
10
10
  config;
11
- connectionPool;
11
+ connections;
12
12
  constructor(config) {
13
13
  this.config = config;
14
- this.connectionPool = new Map();
14
+ this.connections = new Map();
15
15
  }
16
16
  /**
17
17
  * Close all connections
18
18
  */
19
19
  async closeAll() {
20
- await Promise.all([...this.connectionPool.values()].map((c) => c.end()));
21
- this.connectionPool.clear();
20
+ const entries = [...this.connections.values()];
21
+ this.connections.clear();
22
+ await Promise.allSettled(entries.map(async (clientPromise) => (await clientPromise).end()));
22
23
  }
23
24
  /**
24
25
  * Describe table structure
@@ -352,13 +353,29 @@ export class PostgreSQLUtil {
352
353
  * Get or create PostgreSQL client for a profile
353
354
  */
354
355
  async getConnection(profileName) {
355
- if (this.connectionPool.has(profileName)) {
356
- return this.connectionPool.get(profileName);
356
+ const existing = this.connections.get(profileName);
357
+ if (existing) {
358
+ try {
359
+ const client = await existing;
360
+ await client.query('SELECT 1');
361
+ return client;
362
+ }
363
+ catch {
364
+ this.connections.delete(profileName);
365
+ }
366
+ }
367
+ const clientPromise = (async () => {
368
+ const client = new pg.Client(getPgConnectionOptions(this.config, profileName));
369
+ await client.connect();
370
+ return client;
371
+ })();
372
+ this.connections.set(profileName, clientPromise);
373
+ try {
374
+ return await clientPromise;
375
+ }
376
+ catch (error) {
377
+ this.connections.delete(profileName);
378
+ throw error;
357
379
  }
358
- const options = getPgConnectionOptions(this.config, profileName);
359
- const client = new pg.Client(options);
360
- await client.connect();
361
- this.connectionPool.set(profileName, client);
362
- return client;
363
380
  }
364
381
  }
@@ -517,5 +517,5 @@
517
517
  ]
518
518
  }
519
519
  },
520
- "version": "0.2.0"
520
+ "version": "0.2.2"
521
521
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hesed/psql",
3
3
  "description": "CLI for PostgreSQL database interaction",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "author": "Hesed",
6
6
  "bin": {
7
7
  "pg": "./bin/run.js"
@@ -58,9 +58,6 @@
58
58
  "bin": "pg",
59
59
  "dirname": "psql",
60
60
  "commands": "./dist/commands",
61
- "plugins": [
62
- "@oclif/plugin-*"
63
- ],
64
61
  "topicSeparator": " ",
65
62
  "topics": {}
66
63
  },