triangle-utils 1.4.123 → 1.4.125

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.
@@ -99,7 +99,7 @@ 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;
@@ -110,8 +110,11 @@ export class UtilsRDS {
110
110
  }
111
111
  }
112
112
  async batch_create(table_id, items, options = {}) {
113
+ if (items.length === 0) {
114
+ return;
115
+ }
113
116
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
114
- 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;";
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 DO NOTHING;";
115
118
  try {
116
119
  const items = await this.exec(sql, options);
117
120
  return items;
@@ -134,6 +137,9 @@ export class UtilsRDS {
134
137
  }
135
138
  }
136
139
  async batch_put(table_id, items, options = {}) {
140
+ if (items.length === 0) {
141
+ return;
142
+ }
137
143
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
138
144
  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 UPDATE SET " + attribute_names.map(attribute_name => attribute_name + " = " + "EXCLUDED." + attribute_name).join(", ") + ";";
139
145
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.123",
3
+ "version": "1.4.125",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -143,7 +143,7 @@ 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
@@ -160,8 +160,11 @@ export class UtilsRDS {
160
160
  is_verbose? : boolean
161
161
  } = {}
162
162
  ) {
163
+ if (items.length === 0) {
164
+ return
165
+ }
163
166
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
164
- 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;"
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 DO NOTHING;"
165
168
  try {
166
169
  const items = await this.exec(sql, options)
167
170
  return items
@@ -196,6 +199,9 @@ export class UtilsRDS {
196
199
  is_verbose? : boolean
197
200
  } = {}
198
201
  ) {
202
+ if (items.length === 0) {
203
+ return
204
+ }
199
205
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
200
206
  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 UPDATE SET " + attribute_names.map(attribute_name => attribute_name + " = " + "EXCLUDED." + attribute_name).join(", ") + ";"
201
207
  try {