triangle-utils 1.4.132 → 1.4.134
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 +2 -6
- package/dist/src/UtilsRDS.js +27 -18
- package/dist/src/f.js +3 -1
- package/package.json +1 -1
- package/src/UtilsRDS.ts +29 -18
- package/src/f.ts +4 -2
package/dist/src/UtilsRDS.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { Client } from "pg";
|
|
2
1
|
export declare class UtilsRDS {
|
|
3
2
|
private readonly postgres;
|
|
4
|
-
private is_connected;
|
|
5
3
|
private readonly rds_data;
|
|
6
4
|
private readonly rds_cluster_arn;
|
|
7
5
|
private readonly rds_secret_arn;
|
|
8
6
|
constructor(region: string, rds_cluster_arn: string, rds_secret_arn: string, rds_host: string, rds_username: string, rds_password: string);
|
|
9
|
-
connect(): Promise<
|
|
7
|
+
connect(): Promise<void>;
|
|
10
8
|
disconnect(): Promise<void>;
|
|
11
9
|
query(sql: string, options?: {
|
|
12
10
|
is_verbose?: boolean;
|
|
13
|
-
}): Promise<
|
|
14
|
-
[k: string]: unknown;
|
|
15
|
-
}[]>;
|
|
11
|
+
}): Promise<any[]>;
|
|
16
12
|
exec(sql: string, options?: {
|
|
17
13
|
is_verbose?: boolean;
|
|
18
14
|
}): Promise<any[]>;
|
package/dist/src/UtilsRDS.js
CHANGED
|
@@ -20,14 +20,27 @@ function convert_rds_input(input) {
|
|
|
20
20
|
}
|
|
21
21
|
return "NULL";
|
|
22
22
|
}
|
|
23
|
+
function convert_rds_output(input) {
|
|
24
|
+
if (input.isNull) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
else if (input.stringValue !== undefined) {
|
|
28
|
+
return input.stringValue;
|
|
29
|
+
}
|
|
30
|
+
else if (input.longValue !== undefined) {
|
|
31
|
+
return input.longValue;
|
|
32
|
+
}
|
|
33
|
+
else if (input.booleanValue !== undefined) {
|
|
34
|
+
return input.booleanValue;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
23
38
|
export class UtilsRDS {
|
|
24
39
|
postgres;
|
|
25
|
-
is_connected;
|
|
26
40
|
rds_data;
|
|
27
41
|
rds_cluster_arn;
|
|
28
42
|
rds_secret_arn;
|
|
29
43
|
constructor(region, rds_cluster_arn, rds_secret_arn, rds_host, rds_username, rds_password) {
|
|
30
|
-
this.is_connected = false;
|
|
31
44
|
this.postgres = new Client({
|
|
32
45
|
host: rds_host,
|
|
33
46
|
user: rds_username,
|
|
@@ -43,29 +56,19 @@ export class UtilsRDS {
|
|
|
43
56
|
this.rds_secret_arn = rds_secret_arn;
|
|
44
57
|
}
|
|
45
58
|
async connect() {
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.is_connected = true;
|
|
50
|
-
return await this.postgres.connect();
|
|
59
|
+
await this.postgres.connect();
|
|
51
60
|
}
|
|
52
61
|
async disconnect() {
|
|
53
62
|
await this.postgres.end();
|
|
54
|
-
this.is_connected = false;
|
|
55
63
|
}
|
|
56
64
|
async query(sql, options = {}) {
|
|
57
65
|
const is_verbose = Boolean(options.is_verbose);
|
|
58
66
|
if (is_verbose) {
|
|
59
67
|
console.log(sql);
|
|
60
68
|
}
|
|
61
|
-
if (!this.is_connected) {
|
|
62
|
-
const response_connect = await this.connect();
|
|
63
|
-
if (is_verbose) {
|
|
64
|
-
console.log(response_connect);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
69
|
const response = await this.postgres.query(sql);
|
|
68
|
-
return response.rows.map(item => Object.fromEntries(
|
|
70
|
+
return response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
|
|
71
|
+
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
|
|
69
72
|
}
|
|
70
73
|
async exec(sql, options = {}) {
|
|
71
74
|
const is_verbose = Boolean(options.is_verbose);
|
|
@@ -78,10 +81,16 @@ export class UtilsRDS {
|
|
|
78
81
|
secretArn: this.rds_secret_arn,
|
|
79
82
|
database: "postgres",
|
|
80
83
|
sql: sql,
|
|
81
|
-
|
|
84
|
+
includeResultMetadata: true
|
|
82
85
|
})
|
|
83
|
-
.then(response =>
|
|
84
|
-
.
|
|
86
|
+
// .then(response => {
|
|
87
|
+
// console.log(response)
|
|
88
|
+
// return response
|
|
89
|
+
// })
|
|
90
|
+
.then(response => (response.records || [])
|
|
91
|
+
.map((item) => Object.fromEntries((response.columnMetadata || [])
|
|
92
|
+
.map((column, i) => [column.name || "", column.typeName === "numeric" ? Number(convert_rds_output(item[i])) : convert_rds_output(item[i])])
|
|
93
|
+
.filter(([key, value]) => value !== null))))
|
|
85
94
|
:
|
|
86
95
|
await this.query(sql, options);
|
|
87
96
|
if (!Array.isArray(items)) {
|
package/dist/src/f.js
CHANGED
|
@@ -67,5 +67,7 @@ const utils = new TriangleUtils(config);
|
|
|
67
67
|
// }, { is_verbose : true })
|
|
68
68
|
// console.log(response)
|
|
69
69
|
// }
|
|
70
|
-
|
|
70
|
+
await utils.rds.connect();
|
|
71
|
+
const lal_file_voters = await utils.rds.query("SELECT lal_file_voter_id, address_residence_city, address_residence_latitude, address_residence_longitude, address_residence_property_sqft FROM lal_file_voters LIMIT 3;");
|
|
71
72
|
console.log(lal_file_voters);
|
|
73
|
+
await utils.rds.disconnect();
|
package/package.json
CHANGED
package/src/UtilsRDS.ts
CHANGED
|
@@ -18,10 +18,22 @@ function convert_rds_input(input : string | boolean | number | Record<string, an
|
|
|
18
18
|
return "NULL"
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function convert_rds_output(input : Field) {
|
|
22
|
+
if (input.isNull) {
|
|
23
|
+
return undefined
|
|
24
|
+
} else if (input.stringValue !== undefined) {
|
|
25
|
+
return input.stringValue
|
|
26
|
+
} else if (input.longValue !== undefined) {
|
|
27
|
+
return input.longValue
|
|
28
|
+
} else if (input.booleanValue !== undefined) {
|
|
29
|
+
return input.booleanValue
|
|
30
|
+
}
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
export class UtilsRDS {
|
|
22
35
|
|
|
23
36
|
private readonly postgres : Client
|
|
24
|
-
private is_connected : boolean
|
|
25
37
|
private readonly rds_data : RDSData
|
|
26
38
|
private readonly rds_cluster_arn : string
|
|
27
39
|
private readonly rds_secret_arn : string
|
|
@@ -34,7 +46,6 @@ export class UtilsRDS {
|
|
|
34
46
|
rds_username : string,
|
|
35
47
|
rds_password : string
|
|
36
48
|
) {
|
|
37
|
-
this.is_connected = false
|
|
38
49
|
this.postgres = new Client({
|
|
39
50
|
host : rds_host,
|
|
40
51
|
user : rds_username,
|
|
@@ -51,16 +62,11 @@ export class UtilsRDS {
|
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
async connect() {
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
this.is_connected = true
|
|
58
|
-
return await this.postgres.connect()
|
|
65
|
+
await this.postgres.connect()
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
async disconnect() {
|
|
62
69
|
await this.postgres.end()
|
|
63
|
-
this.is_connected = false
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
async query(
|
|
@@ -73,14 +79,11 @@ export class UtilsRDS {
|
|
|
73
79
|
if (is_verbose) {
|
|
74
80
|
console.log(sql)
|
|
75
81
|
}
|
|
76
|
-
if (!this.is_connected) {
|
|
77
|
-
const response_connect = await this.connect()
|
|
78
|
-
if (is_verbose) {
|
|
79
|
-
console.log(response_connect)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
82
|
const response = await this.postgres.query(sql)
|
|
83
|
-
return response.rows.map(item => Object.fromEntries(
|
|
83
|
+
return response.rows.map(item => Object.fromEntries(
|
|
84
|
+
response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
|
|
85
|
+
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
|
|
86
|
+
))
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
async exec(
|
|
@@ -99,10 +102,18 @@ export class UtilsRDS {
|
|
|
99
102
|
secretArn : this.rds_secret_arn,
|
|
100
103
|
database : "postgres",
|
|
101
104
|
sql : sql,
|
|
102
|
-
|
|
105
|
+
includeResultMetadata : true
|
|
103
106
|
})
|
|
104
|
-
.then(response =>
|
|
105
|
-
.
|
|
107
|
+
// .then(response => {
|
|
108
|
+
// console.log(response)
|
|
109
|
+
// return response
|
|
110
|
+
// })
|
|
111
|
+
.then(response => (response.records || [])
|
|
112
|
+
.map((item : any) => Object.fromEntries((response.columnMetadata || [])
|
|
113
|
+
.map((column, i) => [column.name || "", column.typeName === "numeric" ? Number(convert_rds_output(item[i])) : convert_rds_output(item[i])])
|
|
114
|
+
.filter(([key, value]) => value !== null)
|
|
115
|
+
))
|
|
116
|
+
)
|
|
106
117
|
:
|
|
107
118
|
await this.query(sql, options)
|
|
108
119
|
if (!Array.isArray(items)) {
|
package/src/f.ts
CHANGED
|
@@ -84,5 +84,7 @@ const utils = new TriangleUtils(config)
|
|
|
84
84
|
// console.log(response)
|
|
85
85
|
// }
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
await utils.rds.connect()
|
|
88
|
+
const lal_file_voters = await utils.rds.query("SELECT lal_file_voter_id, address_residence_city, address_residence_latitude, address_residence_longitude, address_residence_property_sqft FROM lal_file_voters LIMIT 3;")
|
|
89
|
+
console.log(lal_file_voters)
|
|
90
|
+
await utils.rds.disconnect()
|