triangle-utils 1.4.159 → 1.4.160
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 +1 -3
- package/dist/src/UtilsRDS.js +7 -26
- package/dist/src/f.js +0 -2
- package/package.json +1 -1
- package/src/UtilsRDS.ts +7 -28
- package/src/f.ts +0 -3
package/dist/src/UtilsRDS.d.ts
CHANGED
|
@@ -2,13 +2,11 @@ export declare class UtilsRDS {
|
|
|
2
2
|
private readonly rds_host;
|
|
3
3
|
private readonly rds_username;
|
|
4
4
|
private readonly rds_password;
|
|
5
|
-
private
|
|
5
|
+
private readonly rds_pool;
|
|
6
6
|
private readonly rds_data;
|
|
7
7
|
private readonly rds_cluster_arn;
|
|
8
8
|
private readonly rds_secret_arn;
|
|
9
9
|
constructor(region: string, rds_cluster_arn: string, rds_secret_arn: string, rds_host: string, rds_username: string, rds_password: string);
|
|
10
|
-
connect(): Promise<void>;
|
|
11
|
-
disconnect(): Promise<void>;
|
|
12
10
|
query(sql: string, options?: {
|
|
13
11
|
is_verbose?: boolean;
|
|
14
12
|
}): Promise<any[]>;
|
package/dist/src/UtilsRDS.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RDSData } from "@aws-sdk/client-rds-data";
|
|
2
|
-
import {
|
|
2
|
+
import { Pool } from "pg";
|
|
3
3
|
function convert_rds_input(input) {
|
|
4
4
|
if (input === undefined) {
|
|
5
5
|
return "NULL";
|
|
@@ -53,7 +53,7 @@ export class UtilsRDS {
|
|
|
53
53
|
rds_host;
|
|
54
54
|
rds_username;
|
|
55
55
|
rds_password;
|
|
56
|
-
|
|
56
|
+
rds_pool;
|
|
57
57
|
rds_data;
|
|
58
58
|
rds_cluster_arn;
|
|
59
59
|
rds_secret_arn;
|
|
@@ -61,15 +61,7 @@ export class UtilsRDS {
|
|
|
61
61
|
this.rds_host = rds_host;
|
|
62
62
|
this.rds_username = rds_username;
|
|
63
63
|
this.rds_password = rds_password;
|
|
64
|
-
this.
|
|
65
|
-
this.rds_cluster_arn = rds_cluster_arn,
|
|
66
|
-
this.rds_secret_arn = rds_secret_arn;
|
|
67
|
-
}
|
|
68
|
-
async connect() {
|
|
69
|
-
if (this.postgres !== undefined) {
|
|
70
|
-
await this.disconnect();
|
|
71
|
-
}
|
|
72
|
-
this.postgres = new Client({
|
|
64
|
+
this.rds_pool = new Pool({
|
|
73
65
|
host: this.rds_host,
|
|
74
66
|
user: this.rds_username,
|
|
75
67
|
password: this.rds_password,
|
|
@@ -79,27 +71,16 @@ export class UtilsRDS {
|
|
|
79
71
|
rejectUnauthorized: false
|
|
80
72
|
}
|
|
81
73
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (this.postgres === undefined) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
await this.postgres.end();
|
|
89
|
-
this.postgres = undefined;
|
|
74
|
+
this.rds_data = new RDSData({ region: region });
|
|
75
|
+
this.rds_cluster_arn = rds_cluster_arn,
|
|
76
|
+
this.rds_secret_arn = rds_secret_arn;
|
|
90
77
|
}
|
|
91
78
|
async query(sql, options = {}) {
|
|
92
79
|
const is_verbose = Boolean(options.is_verbose);
|
|
93
|
-
await this.connect();
|
|
94
80
|
if (is_verbose) {
|
|
95
81
|
console.log(sql);
|
|
96
82
|
}
|
|
97
|
-
|
|
98
|
-
console.log("Failed to connect to Postgres.");
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
const response = await this.postgres.query(sql);
|
|
102
|
-
await this.disconnect();
|
|
83
|
+
const response = await this.rds_pool.query(sql);
|
|
103
84
|
return response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
|
|
104
85
|
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
|
|
105
86
|
}
|
package/dist/src/f.js
CHANGED
|
@@ -83,5 +83,3 @@ const utils = new TriangleUtils(config);
|
|
|
83
83
|
// .then(response => console.log(response))
|
|
84
84
|
// await utils.s3.get_download_url("s3://triangle-675045717295-us-east-1-an/tenant_documents/a3a9627f-a94d-4d47-a110-307a6f5563af/a146d789-da40-4e3c-a132-8b7110f3f7df.pdf", { name : "hye.pdf" })
|
|
85
85
|
// .then(response => console.log(response))
|
|
86
|
-
const scouts = await utils.rds.batch_get("scouts", [], { is_verbose: true })
|
|
87
|
-
.then(console.log);
|
package/package.json
CHANGED
package/src/UtilsRDS.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Field, RDSData } from "@aws-sdk/client-rds-data"
|
|
2
|
-
import { Client } from "pg"
|
|
2
|
+
import { Client, Pool } from "pg"
|
|
3
3
|
|
|
4
4
|
function convert_rds_input(input : string | boolean | number | any[] | Record<string, any> | undefined) : string {
|
|
5
5
|
if (input === undefined) {
|
|
@@ -47,7 +47,7 @@ export class UtilsRDS {
|
|
|
47
47
|
private readonly rds_host : string
|
|
48
48
|
private readonly rds_username : string
|
|
49
49
|
private readonly rds_password : string
|
|
50
|
-
private
|
|
50
|
+
private readonly rds_pool : Pool
|
|
51
51
|
private readonly rds_data : RDSData
|
|
52
52
|
private readonly rds_cluster_arn : string
|
|
53
53
|
private readonly rds_secret_arn : string
|
|
@@ -63,16 +63,7 @@ export class UtilsRDS {
|
|
|
63
63
|
this.rds_host = rds_host
|
|
64
64
|
this.rds_username = rds_username
|
|
65
65
|
this.rds_password = rds_password
|
|
66
|
-
this.
|
|
67
|
-
this.rds_cluster_arn = rds_cluster_arn,
|
|
68
|
-
this.rds_secret_arn = rds_secret_arn
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async connect() {
|
|
72
|
-
if (this.postgres !== undefined) {
|
|
73
|
-
await this.disconnect()
|
|
74
|
-
}
|
|
75
|
-
this.postgres = new Client({
|
|
66
|
+
this.rds_pool = new Pool({
|
|
76
67
|
host : this.rds_host,
|
|
77
68
|
user : this.rds_username,
|
|
78
69
|
password : this.rds_password,
|
|
@@ -82,15 +73,9 @@ export class UtilsRDS {
|
|
|
82
73
|
rejectUnauthorized: false
|
|
83
74
|
}
|
|
84
75
|
})
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
async disconnect() {
|
|
89
|
-
if (this.postgres === undefined) {
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
await this.postgres.end()
|
|
93
|
-
this.postgres = undefined
|
|
76
|
+
this.rds_data = new RDSData({ region : region })
|
|
77
|
+
this.rds_cluster_arn = rds_cluster_arn,
|
|
78
|
+
this.rds_secret_arn = rds_secret_arn
|
|
94
79
|
}
|
|
95
80
|
|
|
96
81
|
async query(
|
|
@@ -100,16 +85,10 @@ export class UtilsRDS {
|
|
|
100
85
|
} = {}
|
|
101
86
|
) {
|
|
102
87
|
const is_verbose = Boolean(options.is_verbose)
|
|
103
|
-
await this.connect()
|
|
104
88
|
if (is_verbose) {
|
|
105
89
|
console.log(sql)
|
|
106
90
|
}
|
|
107
|
-
|
|
108
|
-
console.log("Failed to connect to Postgres.")
|
|
109
|
-
return []
|
|
110
|
-
}
|
|
111
|
-
const response = await this.postgres.query(sql)
|
|
112
|
-
await this.disconnect()
|
|
91
|
+
const response = await this.rds_pool.query(sql)
|
|
113
92
|
return response.rows.map(item => Object.fromEntries(
|
|
114
93
|
response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
|
|
115
94
|
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
|
package/src/f.ts
CHANGED
|
@@ -105,6 +105,3 @@ const utils = new TriangleUtils(config)
|
|
|
105
105
|
|
|
106
106
|
// await utils.s3.get_download_url("s3://triangle-675045717295-us-east-1-an/tenant_documents/a3a9627f-a94d-4d47-a110-307a6f5563af/a146d789-da40-4e3c-a132-8b7110f3f7df.pdf", { name : "hye.pdf" })
|
|
107
107
|
// .then(response => console.log(response))
|
|
108
|
-
|
|
109
|
-
const scouts = await utils.rds.batch_get("scouts", [], { is_verbose : true })
|
|
110
|
-
.then(console.log)
|