triangle-utils 1.4.156 → 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 = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.156",
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