triangle-utils 1.4.124 → 1.4.126

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.
@@ -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();
@@ -99,13 +99,14 @@ export class UtilsRDS {
99
99
  }
100
100
  async create(table_id, item, options = {}) {
101
101
  const attribute_names = Object.keys(item).sort();
102
- const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")" + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey IGNORE;";
102
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")" + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;";
103
103
  try {
104
104
  const items = await this.exec(sql, options);
105
105
  return items;
106
106
  }
107
107
  catch (error) {
108
108
  console.log(error.stack);
109
+ console.log(sql);
109
110
  return;
110
111
  }
111
112
  }
@@ -114,13 +115,14 @@ export class UtilsRDS {
114
115
  return;
115
116
  }
116
117
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
117
- const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey IGNORE;";
118
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;";
118
119
  try {
119
120
  const items = await this.exec(sql, options);
120
121
  return items;
121
122
  }
122
123
  catch (error) {
123
124
  console.log(error.stack);
125
+ console.log(sql);
124
126
  return;
125
127
  }
126
128
  }
@@ -133,6 +135,7 @@ export class UtilsRDS {
133
135
  }
134
136
  catch (error) {
135
137
  console.log(error.stack);
138
+ console.log(sql);
136
139
  return;
137
140
  }
138
141
  }
@@ -148,6 +151,7 @@ export class UtilsRDS {
148
151
  }
149
152
  catch (error) {
150
153
  console.log(error.stack);
154
+ console.log(sql);
151
155
  return;
152
156
  }
153
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.124",
3
+ "version": "1.4.126",
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") {
@@ -143,12 +143,13 @@ export class UtilsRDS {
143
143
  } = {}
144
144
  ) {
145
145
  const attribute_names = Object.keys(item).sort()
146
- const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")" + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey IGNORE;"
146
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")" + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;"
147
147
  try {
148
148
  const items = await this.exec(sql, options)
149
149
  return items
150
150
  } catch (error : any) {
151
151
  console.log(error.stack)
152
+ console.log(sql)
152
153
  return
153
154
  }
154
155
  }
@@ -164,12 +165,13 @@ export class UtilsRDS {
164
165
  return
165
166
  }
166
167
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
167
- const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey IGNORE;"
168
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.map(item => "(" + attribute_names.map(attribute_name => convert_rds_input(item[attribute_name])).join(", ") + ")").join(", ") + " ON CONFLICT ON CONSTRAINT " + table_id + "_pkey DO NOTHING;"
168
169
  try {
169
170
  const items = await this.exec(sql, options)
170
171
  return items
171
172
  } catch (error : any) {
172
173
  console.log(error.stack)
174
+ console.log(sql)
173
175
  return
174
176
  }
175
177
  }
@@ -188,6 +190,7 @@ export class UtilsRDS {
188
190
  return items
189
191
  } catch (error : any) {
190
192
  console.log(error.stack)
193
+ console.log(sql)
191
194
  return
192
195
  }
193
196
  }
@@ -209,6 +212,7 @@ export class UtilsRDS {
209
212
  return items
210
213
  } catch (error : any) {
211
214
  console.log(error.stack)
215
+ console.log(sql)
212
216
  return
213
217
  }
214
218
  }