triangle-utils 1.4.155 → 1.4.157

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.
@@ -27,7 +27,8 @@ export declare class UtilsRDS {
27
27
  is_verbose?: boolean;
28
28
  is_forced?: boolean;
29
29
  }): Promise<Record<string, any> | undefined>;
30
- batch_get(table_id: string, primary_key: Record<string, any[]>, options?: {
30
+ batch_get(table_id: string, primary_keys: Record<string, any>[], options?: {
31
+ batch_num_items?: number;
31
32
  attribute_names?: string[];
32
33
  is_verbose?: boolean;
33
34
  is_forced?: boolean;
@@ -140,9 +140,15 @@ export class UtilsRDS {
140
140
  const item = items[0];
141
141
  return item;
142
142
  }
143
- async batch_get(table_id, primary_key, options = {}) {
144
- const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " 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 ");
145
- const items = await this.exec(sql, options);
143
+ async batch_get(table_id, primary_keys, options = {}) {
144
+ const batch_num_items = options.batch_num_items || 100;
145
+ const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort();
146
+ const items = [];
147
+ for (let i = 0; i < primary_keys.length; i += batch_num_items) {
148
+ const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " 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(", ") + ")";
149
+ const new_items = await this.exec(sql, options);
150
+ items.push(...new_items);
151
+ }
146
152
  return items;
147
153
  }
148
154
  async create(table_id, item, options = {}) {
@@ -154,7 +160,9 @@ export class UtilsRDS {
154
160
  }
155
161
  catch (error) {
156
162
  console.log(error.stack);
157
- console.log(sql);
163
+ if (options.is_verbose) {
164
+ console.log(sql);
165
+ }
158
166
  return;
159
167
  }
160
168
  }
@@ -171,7 +179,9 @@ export class UtilsRDS {
171
179
  }
172
180
  catch (error) {
173
181
  console.log(error.stack);
174
- console.log(sql);
182
+ if (options.is_verbose) {
183
+ console.log(sql);
184
+ }
175
185
  return;
176
186
  }
177
187
  }
@@ -185,7 +195,9 @@ export class UtilsRDS {
185
195
  }
186
196
  catch (error) {
187
197
  console.log(error.stack);
188
- console.log(sql);
198
+ if (options.is_verbose) {
199
+ console.log(sql);
200
+ }
189
201
  return;
190
202
  }
191
203
  }
@@ -202,7 +214,9 @@ export class UtilsRDS {
202
214
  }
203
215
  catch (error) {
204
216
  console.log(error.stack);
205
- console.log(sql);
217
+ if (options.is_verbose) {
218
+ console.log(sql);
219
+ }
206
220
  return;
207
221
  }
208
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.155",
3
+ "version": "1.4.157",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -185,15 +185,22 @@ export class UtilsRDS {
185
185
 
186
186
  async batch_get(
187
187
  table_id : string,
188
- primary_key : Record<string, any[]>,
188
+ primary_keys : Record<string, any>[],
189
189
  options : {
190
+ batch_num_items? : number,
190
191
  attribute_names? : string[],
191
192
  is_verbose? : boolean,
192
193
  is_forced? : boolean
193
194
  } = {}
194
195
  ) {
195
- const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " 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 ")
196
- const items = await this.exec(sql, options)
196
+ const batch_num_items = options.batch_num_items || 100
197
+ const attribute_names = Array.from(new Set(primary_keys.map(primary_key => Object.keys(primary_key)).flat())).sort()
198
+ const items = []
199
+ for (let i = 0; i < primary_keys.length; i += batch_num_items) {
200
+ const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " 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(", ") + ")"
201
+ const new_items = await this.exec(sql, options)
202
+ items.push(...new_items)
203
+ }
197
204
  return items
198
205
  }
199
206
 
@@ -212,7 +219,9 @@ export class UtilsRDS {
212
219
  return items
213
220
  } catch (error : any) {
214
221
  console.log(error.stack)
215
- console.log(sql)
222
+ if (options.is_verbose) {
223
+ console.log(sql)
224
+ }
216
225
  return
217
226
  }
218
227
  }
@@ -237,7 +246,9 @@ export class UtilsRDS {
237
246
  await this.exec(sql, options)
238
247
  } catch (error : any) {
239
248
  console.log(error.stack)
240
- console.log(sql)
249
+ if (options.is_verbose) {
250
+ console.log(sql)
251
+ }
241
252
  return
242
253
  }
243
254
  }
@@ -258,7 +269,9 @@ export class UtilsRDS {
258
269
  return items
259
270
  } catch (error : any) {
260
271
  console.log(error.stack)
261
- console.log(sql)
272
+ if (options.is_verbose) {
273
+ console.log(sql)
274
+ }
262
275
  return
263
276
  }
264
277
  }
@@ -283,7 +296,9 @@ export class UtilsRDS {
283
296
  await this.exec(sql, options)
284
297
  } catch (error : any) {
285
298
  console.log(error.stack)
286
- console.log(sql)
299
+ if (options.is_verbose) {
300
+ console.log(sql)
301
+ }
287
302
  return
288
303
  }
289
304
  }