triangle-utils 1.4.134 → 1.4.136
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.
- package/dist/src/UtilsRDS.d.ts +4 -2
- package/dist/src/UtilsRDS.js +15 -4
- package/dist/src/f.js +7 -4
- package/package.json +1 -1
- package/src/UtilsRDS.ts +14 -5
- package/src/f.ts +8 -4
package/dist/src/UtilsRDS.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare class UtilsRDS {
|
|
|
12
12
|
exec(sql: string, options?: {
|
|
13
13
|
is_verbose?: boolean;
|
|
14
14
|
}): Promise<any[]>;
|
|
15
|
-
get(table_id: string, primary_key: Record<string, any>,
|
|
15
|
+
get(table_id: string, primary_key: Record<string, any>, options?: {
|
|
16
|
+
attribute_names?: string[];
|
|
16
17
|
is_verbose?: boolean;
|
|
17
18
|
}): Promise<Record<string, any> | undefined>;
|
|
18
|
-
batch_get(table_id: string, primary_key: Record<string, any[]>,
|
|
19
|
+
batch_get(table_id: string, primary_key: Record<string, any[]>, options?: {
|
|
20
|
+
attribute_names?: string[];
|
|
19
21
|
is_verbose?: boolean;
|
|
20
22
|
}): Promise<any[]>;
|
|
21
23
|
create(table_id: string, item: Record<string, any>, options?: {
|
package/dist/src/UtilsRDS.js
CHANGED
|
@@ -13,6 +13,9 @@ function convert_rds_input(input) {
|
|
|
13
13
|
else if (typeof input === "boolean") {
|
|
14
14
|
return input.toString().toUpperCase();
|
|
15
15
|
}
|
|
16
|
+
else if (Array.isArray(input)) {
|
|
17
|
+
return "ARRAY[" + input.map(a => convert_rds_input(a)).join(", ") + "]";
|
|
18
|
+
}
|
|
16
19
|
else if (typeof input === "object") {
|
|
17
20
|
if (input.expression !== undefined) {
|
|
18
21
|
return input.expression;
|
|
@@ -33,6 +36,14 @@ function convert_rds_output(input) {
|
|
|
33
36
|
else if (input.booleanValue !== undefined) {
|
|
34
37
|
return input.booleanValue;
|
|
35
38
|
}
|
|
39
|
+
else if (input.arrayValue !== undefined) {
|
|
40
|
+
return [
|
|
41
|
+
...(input.arrayValue.stringValues || []),
|
|
42
|
+
...(input.arrayValue.longValues || []),
|
|
43
|
+
...(input.arrayValue.booleanValues || [])
|
|
44
|
+
]
|
|
45
|
+
.filter(value => value !== null);
|
|
46
|
+
}
|
|
36
47
|
return undefined;
|
|
37
48
|
}
|
|
38
49
|
export class UtilsRDS {
|
|
@@ -101,14 +112,14 @@ export class UtilsRDS {
|
|
|
101
112
|
}
|
|
102
113
|
return items;
|
|
103
114
|
}
|
|
104
|
-
async get(table_id, primary_key,
|
|
105
|
-
const sql = "SELECT " + (attribute_names === undefined ? "*" : attribute_names.join(", ")) + " FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ");
|
|
115
|
+
async get(table_id, primary_key, options = {}) {
|
|
116
|
+
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 ");
|
|
106
117
|
const items = await this.exec(sql, options);
|
|
107
118
|
const item = items[0];
|
|
108
119
|
return item;
|
|
109
120
|
}
|
|
110
|
-
async batch_get(table_id, primary_key,
|
|
111
|
-
const sql = "SELECT " + (attribute_names === undefined ? "*" : 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 ");
|
|
121
|
+
async batch_get(table_id, primary_key, options = {}) {
|
|
122
|
+
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 ");
|
|
112
123
|
const items = await this.exec(sql, options);
|
|
113
124
|
return items;
|
|
114
125
|
}
|
package/dist/src/f.js
CHANGED
|
@@ -67,7 +67,10 @@ const utils = new TriangleUtils(config);
|
|
|
67
67
|
// }, { is_verbose : true })
|
|
68
68
|
// console.log(response)
|
|
69
69
|
// }
|
|
70
|
-
await utils.rds.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
// console.log(await utils.rds.put("prisms", {
|
|
71
|
+
// prism_id : crypto.randomUUID(),
|
|
72
|
+
// state_id : "ND",
|
|
73
|
+
// name : "2026 Election in North Dakota",
|
|
74
|
+
// target_ids : ["TURNOUT-2026-11-03"]
|
|
75
|
+
// }, { is_verbose : true }))
|
|
76
|
+
// console.log(await utils.rds.exec("SELECT * FROM prisms", { is_verbose : true }))
|
package/package.json
CHANGED
package/src/UtilsRDS.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Field, RDSData } from "@aws-sdk/client-rds-data"
|
|
2
2
|
import { Client } from "pg"
|
|
3
3
|
|
|
4
|
-
function convert_rds_input(input : string | boolean | number | Record<string, any> | undefined) : string {
|
|
4
|
+
function convert_rds_input(input : string | boolean | number | any[] | Record<string, any> | undefined) : string {
|
|
5
5
|
if (input === undefined) {
|
|
6
6
|
return "NULL"
|
|
7
7
|
} else if (typeof input === "string") {
|
|
@@ -10,6 +10,8 @@ function convert_rds_input(input : string | boolean | number | Record<string, an
|
|
|
10
10
|
return input.toString()
|
|
11
11
|
} else if (typeof input === "boolean") {
|
|
12
12
|
return input.toString().toUpperCase()
|
|
13
|
+
} else if (Array.isArray(input)) {
|
|
14
|
+
return "ARRAY[" + input.map(a => convert_rds_input(a)).join(", ") + "]"
|
|
13
15
|
} else if (typeof input === "object") {
|
|
14
16
|
if (input.expression !== undefined) {
|
|
15
17
|
return input.expression
|
|
@@ -27,6 +29,13 @@ function convert_rds_output(input : Field) {
|
|
|
27
29
|
return input.longValue
|
|
28
30
|
} else if (input.booleanValue !== undefined) {
|
|
29
31
|
return input.booleanValue
|
|
32
|
+
} else if (input.arrayValue !== undefined) {
|
|
33
|
+
return [
|
|
34
|
+
...(input.arrayValue.stringValues || []),
|
|
35
|
+
...(input.arrayValue.longValues || []),
|
|
36
|
+
...(input.arrayValue.booleanValues || [])
|
|
37
|
+
]
|
|
38
|
+
.filter(value => value !== null)
|
|
30
39
|
}
|
|
31
40
|
return undefined
|
|
32
41
|
}
|
|
@@ -128,12 +137,12 @@ export class UtilsRDS {
|
|
|
128
137
|
async get(
|
|
129
138
|
table_id : string,
|
|
130
139
|
primary_key : Record<string, any>,
|
|
131
|
-
attribute_names? : string[],
|
|
132
140
|
options : {
|
|
141
|
+
attribute_names? : string[],
|
|
133
142
|
is_verbose? : boolean
|
|
134
143
|
} = {}
|
|
135
144
|
) {
|
|
136
|
-
const sql = "SELECT " + (attribute_names === undefined ? "*" : attribute_names.join(", ")) + " FROM " + table_id + " WHERE " + Object.entries(primary_key).map(([key_name, value]) => key_name + " = " + convert_rds_input(value)).join(" AND ")
|
|
145
|
+
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 ")
|
|
137
146
|
const items = await this.exec(sql, options)
|
|
138
147
|
const item : Record<string, any> | undefined = items[0]
|
|
139
148
|
return item
|
|
@@ -142,12 +151,12 @@ export class UtilsRDS {
|
|
|
142
151
|
async batch_get(
|
|
143
152
|
table_id : string,
|
|
144
153
|
primary_key : Record<string, any[]>,
|
|
145
|
-
attribute_names? : string[],
|
|
146
154
|
options : {
|
|
155
|
+
attribute_names? : string[],
|
|
147
156
|
is_verbose? : boolean
|
|
148
157
|
} = {}
|
|
149
158
|
) {
|
|
150
|
-
const sql = "SELECT " + (attribute_names === undefined ? "*" : 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 ")
|
|
159
|
+
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 ")
|
|
151
160
|
const items = await this.exec(sql, options)
|
|
152
161
|
return items
|
|
153
162
|
}
|
package/src/f.ts
CHANGED
|
@@ -84,7 +84,11 @@ const utils = new TriangleUtils(config)
|
|
|
84
84
|
// console.log(response)
|
|
85
85
|
// }
|
|
86
86
|
|
|
87
|
-
await utils.rds.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
// console.log(await utils.rds.put("prisms", {
|
|
88
|
+
// prism_id : crypto.randomUUID(),
|
|
89
|
+
// state_id : "ND",
|
|
90
|
+
// name : "2026 Election in North Dakota",
|
|
91
|
+
// target_ids : ["TURNOUT-2026-11-03"]
|
|
92
|
+
// }, { is_verbose : true }))
|
|
93
|
+
|
|
94
|
+
// console.log(await utils.rds.exec("SELECT * FROM prisms", { is_verbose : true }))
|