triangle-utils 1.4.150 → 1.4.151

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.
@@ -39,7 +39,8 @@ export declare class UtilsRDS {
39
39
  batch_create(table_id: string, items: Record<string, any>[], options?: {
40
40
  is_verbose?: boolean;
41
41
  is_forced?: boolean;
42
- }): Promise<any[] | undefined>;
42
+ batch_num_items?: number;
43
+ }): Promise<void>;
43
44
  put(table_id: string, item: Record<string, any>, options?: {
44
45
  is_verbose?: boolean;
45
46
  is_forced?: boolean;
@@ -47,15 +48,17 @@ export declare class UtilsRDS {
47
48
  batch_put(table_id: string, items: Record<string, any>[], options?: {
48
49
  is_verbose?: boolean;
49
50
  is_forced?: boolean;
50
- }): Promise<any[] | undefined>;
51
+ batch_num_items?: number;
52
+ }): Promise<void>;
51
53
  delete(table_id: string, primary_key: Record<string, any>, options?: {
52
54
  is_verbose?: boolean;
53
55
  is_forced?: boolean;
54
56
  }): Promise<any[]>;
55
- batch_delete(table_id: string, primary_key: Record<string, any[]>, options?: {
57
+ batch_delete(table_id: string, primary_keys: Record<string, any>[], options?: {
56
58
  is_verbose?: boolean;
57
59
  is_forced?: boolean;
58
- }): Promise<any[]>;
60
+ batch_num_items?: number;
61
+ }): Promise<void>;
59
62
  set(table_id: string, primary_key: Record<string, any>, attributes: Record<string, any>, options?: {
60
63
  is_verbose?: boolean;
61
64
  is_forced?: boolean;
@@ -163,15 +163,18 @@ export class UtilsRDS {
163
163
  return;
164
164
  }
165
165
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
166
- 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;";
167
- try {
168
- const items = await this.exec(sql, options);
169
- return items;
170
- }
171
- catch (error) {
172
- console.log(error.stack);
173
- console.log(sql);
174
- return;
166
+ const batch_num_items = options.batch_num_items || 100;
167
+ for (let i = 0; i < items.length; i += batch_num_items) {
168
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_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;";
169
+ try {
170
+ await this.exec(sql, options);
171
+ return;
172
+ }
173
+ catch (error) {
174
+ console.log(error.stack);
175
+ console.log(sql);
176
+ return;
177
+ }
175
178
  }
176
179
  }
177
180
  async put(table_id, item, options = {}) {
@@ -192,24 +195,30 @@ export class UtilsRDS {
192
195
  return;
193
196
  }
194
197
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort();
195
- 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(", ") + ";";
196
- try {
197
- const items = await this.exec(sql, options);
198
- return items;
199
- }
200
- catch (error) {
201
- console.log(error.stack);
202
- console.log(sql);
203
- return;
198
+ const batch_num_items = options.batch_num_items || 100;
199
+ for (let i = 0; i < items.length; i += batch_num_items) {
200
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_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
+ try {
202
+ await this.exec(sql, options);
203
+ }
204
+ catch (error) {
205
+ console.log(error.stack);
206
+ console.log(sql);
207
+ return;
208
+ }
204
209
  }
205
210
  }
206
211
  async delete(table_id, primary_key, options = {}) {
207
212
  const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ");
208
213
  return await this.exec(sql, options);
209
214
  }
210
- async batch_delete(table_id, primary_key, options = {}) {
211
- const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, values]) => key_name + " IN " + "(" + values.map(value => convert_rds_input(value)).join(", ") + ")").join(" AND ");
212
- return await this.exec(sql, options);
215
+ async batch_delete(table_id, primary_keys, options = {}) {
216
+ const batch_num_items = options.batch_num_items || 100;
217
+ const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort();
218
+ for (let i = 0; i < primary_keys.length; i += batch_num_items) {
219
+ const sql = "DELETE FROM " + table_id + " WHERE " + "(" + attribute_names.join(", ") + ")" + " IN " + "(" + primary_keys.map(primary_key => "(" + attribute_names.map(attribute_name => convert_rds_input(primary_key[attribute_name])).join(", ") + ")").join(", ") + ")";
220
+ await this.exec(sql, options);
221
+ }
213
222
  }
214
223
  async set(table_id, primary_key, attributes, options = {}) {
215
224
  const attribute_names = Object.keys(attributes).sort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.150",
3
+ "version": "1.4.151",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -222,21 +222,25 @@ export class UtilsRDS {
222
222
  items : Record<string, any>[],
223
223
  options : {
224
224
  is_verbose? : boolean,
225
- is_forced? : boolean
225
+ is_forced? : boolean,
226
+ batch_num_items? : number
226
227
  } = {}
227
228
  ) {
228
229
  if (items.length === 0) {
229
230
  return
230
231
  }
231
232
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
232
- 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;"
233
- try {
234
- const items = await this.exec(sql, options)
235
- return items
236
- } catch (error : any) {
237
- console.log(error.stack)
238
- console.log(sql)
239
- return
233
+ const batch_num_items = options.batch_num_items || 100
234
+ for (let i = 0; i < items.length; i += batch_num_items) {
235
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_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;"
236
+ try {
237
+ await this.exec(sql, options)
238
+ return
239
+ } catch (error : any) {
240
+ console.log(error.stack)
241
+ console.log(sql)
242
+ return
243
+ }
240
244
  }
241
245
  }
242
246
 
@@ -265,21 +269,24 @@ export class UtilsRDS {
265
269
  items : Record<string, any>[],
266
270
  options : {
267
271
  is_verbose? : boolean,
268
- is_forced? : boolean
272
+ is_forced? : boolean,
273
+ batch_num_items? : number
269
274
  } = {}
270
275
  ) {
271
276
  if (items.length === 0) {
272
277
  return
273
278
  }
274
279
  const attribute_names = Array.from(new Set(items.map(item => Object.keys(item)).flat())).sort()
275
- 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(", ") + ";"
276
- try {
277
- const items = await this.exec(sql, options)
278
- return items
279
- } catch (error : any) {
280
- console.log(error.stack)
281
- console.log(sql)
282
- return
280
+ const batch_num_items = options.batch_num_items || 100
281
+ for (let i = 0; i < items.length; i += batch_num_items) {
282
+ const sql = "INSERT INTO " + table_id + " (" + attribute_names.join(", ") + ")" + " VALUES " + items.slice(i, i + batch_num_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(", ") + ";"
283
+ try {
284
+ await this.exec(sql, options)
285
+ } catch (error : any) {
286
+ console.log(error.stack)
287
+ console.log(sql)
288
+ return
289
+ }
283
290
  }
284
291
  }
285
292
 
@@ -297,14 +304,19 @@ export class UtilsRDS {
297
304
 
298
305
  async batch_delete(
299
306
  table_id : string,
300
- primary_key : Record<string, any[]>,
307
+ primary_keys : Record<string, any>[],
301
308
  options : {
302
309
  is_verbose? : boolean,
303
- is_forced? : boolean
310
+ is_forced? : boolean,
311
+ batch_num_items? : number
304
312
  } = {}
305
313
  ) {
306
- const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, values]) => key_name + " IN " + "(" + values.map(value => convert_rds_input(value)).join(", ") + ")").join(" AND ")
307
- return await this.exec(sql, options)
314
+ const batch_num_items = options.batch_num_items || 100
315
+ const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort()
316
+ for (let i = 0; i < primary_keys.length; i += batch_num_items) {
317
+ const sql = "DELETE FROM " + table_id + " WHERE " + "(" + attribute_names.join(", ") + ")" + " IN " + "(" + primary_keys.map(primary_key => "(" + attribute_names.map(attribute_name => convert_rds_input(primary_key[attribute_name])).join(", ") + ")" ).join(", ") + ")"
318
+ await this.exec(sql, options)
319
+ }
308
320
  }
309
321
 
310
322
  async set(
package/f.txt DELETED
Binary file