triangle-utils 1.4.148 → 1.4.149

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.
@@ -11,34 +11,53 @@ export declare class UtilsRDS {
11
11
  }): Promise<any[]>;
12
12
  exec(sql: string, options?: {
13
13
  is_verbose?: boolean;
14
+ is_forced?: boolean;
15
+ }): Promise<any[]>;
16
+ scan(table_id: string, options?: {
17
+ filters?: Record<string, any>;
18
+ undefined_attribute_names?: string[];
19
+ defined_attribute_names?: string[];
20
+ attribute_names?: string[];
21
+ max_num_items?: number;
22
+ is_verbose?: boolean;
23
+ is_forced?: boolean;
14
24
  }): Promise<any[]>;
15
25
  get(table_id: string, primary_key: Record<string, any>, options?: {
16
26
  attribute_names?: string[];
17
27
  is_verbose?: boolean;
28
+ is_forced?: boolean;
18
29
  }): Promise<Record<string, any> | undefined>;
19
30
  batch_get(table_id: string, primary_key: Record<string, any[]>, options?: {
20
31
  attribute_names?: string[];
21
32
  is_verbose?: boolean;
33
+ is_forced?: boolean;
22
34
  }): Promise<any[]>;
23
35
  create(table_id: string, item: Record<string, any>, options?: {
24
36
  is_verbose?: boolean;
37
+ is_forced?: boolean;
25
38
  }): Promise<any[] | undefined>;
26
39
  batch_create(table_id: string, items: Record<string, any>[], options?: {
27
40
  is_verbose?: boolean;
41
+ is_forced?: boolean;
28
42
  }): Promise<any[] | undefined>;
29
43
  put(table_id: string, item: Record<string, any>, options?: {
30
44
  is_verbose?: boolean;
45
+ is_forced?: boolean;
31
46
  }): Promise<any[] | undefined>;
32
47
  batch_put(table_id: string, items: Record<string, any>[], options?: {
33
48
  is_verbose?: boolean;
49
+ is_forced?: boolean;
34
50
  }): Promise<any[] | undefined>;
35
51
  delete(table_id: string, primary_key: Record<string, any>, options?: {
36
52
  is_verbose?: boolean;
53
+ is_forced?: boolean;
37
54
  }): Promise<any[]>;
38
55
  batch_delete(table_id: string, primary_key: Record<string, any[]>, options?: {
39
56
  is_verbose?: boolean;
57
+ is_forced?: boolean;
40
58
  }): Promise<any[]>;
41
59
  set(table_id: string, primary_key: Record<string, any>, attributes: Record<string, any>, options?: {
42
60
  is_verbose?: boolean;
61
+ is_forced?: boolean;
43
62
  }): Promise<any[]>;
44
63
  }
@@ -86,10 +86,11 @@ export class UtilsRDS {
86
86
  }
87
87
  async exec(sql, options = {}) {
88
88
  const is_verbose = Boolean(options.is_verbose);
89
+ const is_forced = Boolean(options.is_forced);
89
90
  if (is_verbose) {
90
91
  console.log(sql);
91
92
  }
92
- const items = sql.length <= 60000 ?
93
+ const items = (sql.length <= 60000 && !is_forced) ?
93
94
  await this.rds_data.executeStatement({
94
95
  resourceArn: this.rds_cluster_arn,
95
96
  secretArn: this.rds_secret_arn,
@@ -115,6 +116,24 @@ export class UtilsRDS {
115
116
  }
116
117
  return items;
117
118
  }
119
+ async scan(table_id, options = {}) {
120
+ const undefined_attribute_names = options.undefined_attribute_names || [];
121
+ const defined_attribute_names = options.defined_attribute_names || [];
122
+ const filters = options.filters || {};
123
+ const clauses_where = [
124
+ ...Object.entries(filters).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)),
125
+ ...undefined_attribute_names.map(undefined_attribute_name => undefined_attribute_name + " IS NULL"),
126
+ ...defined_attribute_names.map(undefined_attribute_name => undefined_attribute_name + " IS NOT NULL")
127
+ ];
128
+ const sql = [
129
+ "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")),
130
+ "FROM " + table_id,
131
+ (clauses_where.length !== 0 ? ("WHERE " + clauses_where.join(" AND ")) : ""),
132
+ (options.max_num_items !== undefined ? ("LIMIT " + options.max_num_items) : "")
133
+ ].join("\n");
134
+ const items = await this.exec(sql, options);
135
+ return items;
136
+ }
118
137
  async get(table_id, primary_key, options = {}) {
119
138
  const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ");
120
139
  const items = await this.exec(sql, options);
package/dist/src/f.js CHANGED
@@ -74,4 +74,6 @@ const utils = new TriangleUtils(config);
74
74
  // target_ids : ["TURNOUT-2026-11-03"]
75
75
  // }, { is_verbose : true }))
76
76
  // console.log(await utils.rds.exec("SELECT * FROM prisms", { is_verbose : true }))\
77
- console.log(await utils.rds.exec("SELECT * FROM state_voter_targets WHERE state_id = 'ND' AND voter_id = '187195'"));
77
+ // await utils.rds.connect()
78
+ // console.log(await utils.rds.scan("web_articles", { is_verbose : true, is_forced : true, max_num_items : 100 }))
79
+ // await utils.rds.disconnect()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.148",
3
+ "version": "1.4.149",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -100,14 +100,16 @@ export class UtilsRDS {
100
100
  async exec(
101
101
  sql : string,
102
102
  options : {
103
- is_verbose? : boolean
103
+ is_verbose? : boolean,
104
+ is_forced? : boolean
104
105
  } = {}
105
106
  ) {
106
107
  const is_verbose = Boolean(options.is_verbose)
108
+ const is_forced = Boolean(options.is_forced)
107
109
  if (is_verbose) {
108
110
  console.log(sql)
109
111
  }
110
- const items = sql.length <= 60000 ?
112
+ const items = (sql.length <= 60000 && !is_forced) ?
111
113
  await this.rds_data.executeStatement({
112
114
  resourceArn : this.rds_cluster_arn,
113
115
  secretArn : this.rds_secret_arn,
@@ -136,12 +138,43 @@ export class UtilsRDS {
136
138
  return items
137
139
  }
138
140
 
141
+ async scan(
142
+ table_id : string,
143
+ options : {
144
+ filters? : Record<string, any>,
145
+ undefined_attribute_names? : string[],
146
+ defined_attribute_names? : string[],
147
+ attribute_names? : string[],
148
+ max_num_items? : number,
149
+ is_verbose? : boolean,
150
+ is_forced? : boolean
151
+ } = {}
152
+ ) {
153
+ const undefined_attribute_names = options.undefined_attribute_names || []
154
+ const defined_attribute_names = options.defined_attribute_names || []
155
+ const filters = options.filters || {}
156
+ const clauses_where = [
157
+ ...Object.entries(filters).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)),
158
+ ...undefined_attribute_names.map(undefined_attribute_name => undefined_attribute_name + " IS NULL"),
159
+ ...defined_attribute_names.map(undefined_attribute_name => undefined_attribute_name + " IS NOT NULL")
160
+ ]
161
+ const sql = [
162
+ "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")),
163
+ "FROM " + table_id,
164
+ (clauses_where.length !== 0 ? ("WHERE " + clauses_where.join(" AND ")) : ""),
165
+ (options.max_num_items !== undefined ? ("LIMIT " + options.max_num_items) : "")
166
+ ].join("\n")
167
+ const items = await this.exec(sql, options)
168
+ return items
169
+ }
170
+
139
171
  async get(
140
172
  table_id : string,
141
173
  primary_key : Record<string, any>,
142
174
  options : {
143
175
  attribute_names? : string[],
144
- is_verbose? : boolean
176
+ is_verbose? : boolean,
177
+ is_forced? : boolean
145
178
  } = {}
146
179
  ) {
147
180
  const sql = "SELECT " + (options.attribute_names === undefined ? "*" : options.attribute_names.join(", ")) + " FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ")
@@ -155,7 +188,8 @@ export class UtilsRDS {
155
188
  primary_key : Record<string, any[]>,
156
189
  options : {
157
190
  attribute_names? : string[],
158
- is_verbose? : boolean
191
+ is_verbose? : boolean,
192
+ is_forced? : boolean
159
193
  } = {}
160
194
  ) {
161
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 ")
@@ -167,7 +201,8 @@ export class UtilsRDS {
167
201
  table_id : string,
168
202
  item : Record<string, any>,
169
203
  options : {
170
- is_verbose? : boolean
204
+ is_verbose? : boolean,
205
+ is_forced? : boolean
171
206
  } = {}
172
207
  ) {
173
208
  const attribute_names = Object.keys(item).sort()
@@ -186,7 +221,8 @@ export class UtilsRDS {
186
221
  table_id : string,
187
222
  items : Record<string, any>[],
188
223
  options : {
189
- is_verbose? : boolean
224
+ is_verbose? : boolean,
225
+ is_forced? : boolean
190
226
  } = {}
191
227
  ) {
192
228
  if (items.length === 0) {
@@ -208,7 +244,8 @@ export class UtilsRDS {
208
244
  table_id : string,
209
245
  item : Record<string, any>,
210
246
  options : {
211
- is_verbose? : boolean
247
+ is_verbose? : boolean,
248
+ is_forced? : boolean
212
249
  } = {}
213
250
  ) {
214
251
  const attribute_names = Object.keys(item).sort()
@@ -227,7 +264,8 @@ export class UtilsRDS {
227
264
  table_id : string,
228
265
  items : Record<string, any>[],
229
266
  options : {
230
- is_verbose? : boolean
267
+ is_verbose? : boolean,
268
+ is_forced? : boolean
231
269
  } = {}
232
270
  ) {
233
271
  if (items.length === 0) {
@@ -249,7 +287,8 @@ export class UtilsRDS {
249
287
  table_id : string,
250
288
  primary_key : Record<string, any>,
251
289
  options : {
252
- is_verbose? : boolean
290
+ is_verbose? : boolean,
291
+ is_forced? : boolean
253
292
  } = {}
254
293
  ) {
255
294
  const sql = "DELETE FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ")
@@ -260,7 +299,8 @@ export class UtilsRDS {
260
299
  table_id : string,
261
300
  primary_key : Record<string, any[]>,
262
301
  options : {
263
- is_verbose? : boolean
302
+ is_verbose? : boolean,
303
+ is_forced? : boolean
264
304
  } = {}
265
305
  ) {
266
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 ")
@@ -272,7 +312,8 @@ export class UtilsRDS {
272
312
  primary_key : Record<string, any>,
273
313
  attributes : Record<string, any>,
274
314
  options : {
275
- is_verbose? : boolean
315
+ is_verbose? : boolean,
316
+ is_forced? : boolean
276
317
  } = {}
277
318
  ) {
278
319
  const attribute_names = Object.keys(attributes).sort()
package/src/f.ts CHANGED
@@ -93,5 +93,6 @@ const utils = new TriangleUtils(config)
93
93
 
94
94
  // console.log(await utils.rds.exec("SELECT * FROM prisms", { is_verbose : true }))\
95
95
 
96
-
97
- console.log(await utils.rds.exec("SELECT * FROM state_voter_targets WHERE state_id = 'ND' AND voter_id = '187195'"))
96
+ // await utils.rds.connect()
97
+ // console.log(await utils.rds.scan("web_articles", { is_verbose : true, is_forced : true, max_num_items : 100 }))
98
+ // await utils.rds.disconnect()