triangle-utils 1.4.125 → 1.4.127

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 + "'";
8
+ return "'" + input.replace("'", "''") + "'";
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 = {}) {
@@ -106,6 +109,7 @@ export class UtilsRDS {
106
109
  }
107
110
  catch (error) {
108
111
  console.log(error.stack);
112
+ console.log(sql);
109
113
  return;
110
114
  }
111
115
  }
@@ -121,6 +125,7 @@ export class UtilsRDS {
121
125
  }
122
126
  catch (error) {
123
127
  console.log(error.stack);
128
+ console.log(sql);
124
129
  return;
125
130
  }
126
131
  }
@@ -133,6 +138,7 @@ export class UtilsRDS {
133
138
  }
134
139
  catch (error) {
135
140
  console.log(error.stack);
141
+ console.log(sql);
136
142
  return;
137
143
  }
138
144
  }
@@ -148,6 +154,7 @@ export class UtilsRDS {
148
154
  }
149
155
  catch (error) {
150
156
  console.log(error.stack);
157
+ console.log(sql);
151
158
  return;
152
159
  }
153
160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.125",
3
+ "version": "1.4.127",
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 + "'"
8
+ return "'" + input.replace("'", "''") + "'"
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
 
@@ -149,6 +152,7 @@ export class UtilsRDS {
149
152
  return items
150
153
  } catch (error : any) {
151
154
  console.log(error.stack)
155
+ console.log(sql)
152
156
  return
153
157
  }
154
158
  }
@@ -170,6 +174,7 @@ export class UtilsRDS {
170
174
  return items
171
175
  } catch (error : any) {
172
176
  console.log(error.stack)
177
+ console.log(sql)
173
178
  return
174
179
  }
175
180
  }
@@ -188,6 +193,7 @@ export class UtilsRDS {
188
193
  return items
189
194
  } catch (error : any) {
190
195
  console.log(error.stack)
196
+ console.log(sql)
191
197
  return
192
198
  }
193
199
  }
@@ -209,6 +215,7 @@ export class UtilsRDS {
209
215
  return items
210
216
  } catch (error : any) {
211
217
  console.log(error.stack)
218
+ console.log(sql)
212
219
  return
213
220
  }
214
221
  }