triangle-utils 1.4.126 → 1.4.128

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.
@@ -1,11 +1,12 @@
1
1
  import { Client } from "pg";
2
2
  export declare class UtilsRDS {
3
3
  private readonly postgres;
4
+ private is_connected;
4
5
  private readonly rds_data;
5
6
  private readonly rds_cluster_arn;
6
7
  private readonly rds_secret_arn;
7
8
  constructor(region: string, rds_cluster_arn: string, rds_secret_arn: string, rds_host: string, rds_username: string, rds_password: string);
8
- connect(): Promise<Client>;
9
+ connect(): Promise<Client | undefined>;
9
10
  disconnect(): Promise<void>;
10
11
  query(sql: string, options?: {
11
12
  is_verbose?: boolean;
@@ -5,7 +5,7 @@ function convert_rds_input(input) {
5
5
  return "NULL";
6
6
  }
7
7
  else if (typeof input === "string") {
8
- return "'" + input.replace("'", "''") + "'";
8
+ return "'" + input.replaceAll("'", "''") + "'";
9
9
  }
10
10
  else if (typeof input === "number") {
11
11
  return input.toString();
@@ -22,10 +22,12 @@ function convert_rds_input(input) {
22
22
  }
23
23
  export class UtilsRDS {
24
24
  postgres;
25
+ is_connected;
25
26
  rds_data;
26
27
  rds_cluster_arn;
27
28
  rds_secret_arn;
28
29
  constructor(region, rds_cluster_arn, rds_secret_arn, rds_host, rds_username, rds_password) {
30
+ this.is_connected = false;
29
31
  this.postgres = new Client({
30
32
  host: rds_host,
31
33
  user: rds_username,
@@ -41,6 +43,9 @@ export class UtilsRDS {
41
43
  this.rds_secret_arn = rds_secret_arn;
42
44
  }
43
45
  async connect() {
46
+ if (this.is_connected) {
47
+ return;
48
+ }
44
49
  return await this.postgres.connect();
45
50
  }
46
51
  async disconnect() {
@@ -51,15 +56,13 @@ export class UtilsRDS {
51
56
  if (is_verbose) {
52
57
  console.log(sql);
53
58
  }
54
- const response_connect = await this.connect();
55
- if (is_verbose) {
56
- console.log(response_connect);
59
+ if (!this.is_connected) {
60
+ const response_connect = await this.connect();
61
+ if (is_verbose) {
62
+ console.log(response_connect);
63
+ }
57
64
  }
58
65
  const response = await this.postgres.query(sql);
59
- const response_disconnect = await this.disconnect();
60
- if (is_verbose) {
61
- console.log(response_disconnect);
62
- }
63
66
  return response.rows;
64
67
  }
65
68
  async exec(sql, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.126",
3
+ "version": "1.4.128",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -5,7 +5,7 @@ function convert_rds_input(input : string | boolean | number | Record<string, an
5
5
  if (input === undefined) {
6
6
  return "NULL"
7
7
  } else if (typeof input === "string") {
8
- return "'" + input.replace("'", "''") + "'"
8
+ return "'" + input.replaceAll("'", "''") + "'"
9
9
  } else if (typeof input === "number") {
10
10
  return input.toString()
11
11
  } else if (typeof input === "boolean") {
@@ -21,6 +21,7 @@ function convert_rds_input(input : string | boolean | number | Record<string, an
21
21
  export class UtilsRDS {
22
22
 
23
23
  private readonly postgres : Client
24
+ private is_connected : boolean
24
25
  private readonly rds_data : RDSData
25
26
  private readonly rds_cluster_arn : string
26
27
  private readonly rds_secret_arn : string
@@ -33,6 +34,7 @@ export class UtilsRDS {
33
34
  rds_username : string,
34
35
  rds_password : string
35
36
  ) {
37
+ this.is_connected = false
36
38
  this.postgres = new Client({
37
39
  host : rds_host,
38
40
  user : rds_username,
@@ -49,6 +51,9 @@ export class UtilsRDS {
49
51
  }
50
52
 
51
53
  async connect() {
54
+ if (this.is_connected) {
55
+ return
56
+ }
52
57
  return await this.postgres.connect()
53
58
  }
54
59
 
@@ -66,15 +71,13 @@ export class UtilsRDS {
66
71
  if (is_verbose) {
67
72
  console.log(sql)
68
73
  }
69
- const response_connect = await this.connect()
70
- if (is_verbose) {
71
- console.log(response_connect)
74
+ if (!this.is_connected) {
75
+ const response_connect = await this.connect()
76
+ if (is_verbose) {
77
+ console.log(response_connect)
78
+ }
72
79
  }
73
80
  const response = await this.postgres.query(sql)
74
- const response_disconnect = await this.disconnect()
75
- if (is_verbose) {
76
- console.log(response_disconnect)
77
- }
78
81
  return response.rows
79
82
  }
80
83