triangle-utils 1.4.157 → 1.4.158

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.
@@ -1,5 +1,8 @@
1
1
  export declare class UtilsRDS {
2
- private readonly postgres;
2
+ private readonly rds_host;
3
+ private readonly rds_username;
4
+ private readonly rds_password;
5
+ private postgres?;
3
6
  private readonly rds_data;
4
7
  private readonly rds_cluster_arn;
5
8
  private readonly rds_secret_arn;
@@ -8,7 +11,7 @@ export declare class UtilsRDS {
8
11
  disconnect(): Promise<void>;
9
12
  query(sql: string, options?: {
10
13
  is_verbose?: boolean;
11
- }): Promise<any[]>;
14
+ }): Promise<any[] | undefined>;
12
15
  exec(sql: string, options?: {
13
16
  is_verbose?: boolean;
14
17
  is_forced?: boolean;
@@ -50,37 +50,56 @@ function convert_rds_output(input) {
50
50
  return undefined;
51
51
  }
52
52
  export class UtilsRDS {
53
+ rds_host;
54
+ rds_username;
55
+ rds_password;
53
56
  postgres;
54
57
  rds_data;
55
58
  rds_cluster_arn;
56
59
  rds_secret_arn;
57
60
  constructor(region, rds_cluster_arn, rds_secret_arn, rds_host, rds_username, rds_password) {
61
+ this.rds_host = rds_host;
62
+ this.rds_username = rds_username;
63
+ this.rds_password = rds_password;
64
+ this.rds_data = new RDSData({ region: region });
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
+ }
58
72
  this.postgres = new Client({
59
- host: rds_host,
60
- user: rds_username,
61
- password: rds_password,
73
+ host: this.rds_host,
74
+ user: this.rds_username,
75
+ password: this.rds_password,
62
76
  database: "triangle",
63
77
  port: 5432,
64
78
  ssl: {
65
79
  rejectUnauthorized: false
66
80
  }
67
81
  });
68
- this.rds_data = new RDSData({ region: region });
69
- this.rds_cluster_arn = rds_cluster_arn,
70
- this.rds_secret_arn = rds_secret_arn;
71
- }
72
- async connect() {
73
82
  await this.postgres.connect();
74
83
  }
75
84
  async disconnect() {
85
+ if (this.postgres === undefined) {
86
+ return;
87
+ }
76
88
  await this.postgres.end();
89
+ this.postgres = undefined;
77
90
  }
78
91
  async query(sql, options = {}) {
79
92
  const is_verbose = Boolean(options.is_verbose);
93
+ await this.connect();
80
94
  if (is_verbose) {
81
95
  console.log(sql);
82
96
  }
97
+ if (this.postgres === undefined) {
98
+ console.log("Failed to connect to Postgres.");
99
+ return;
100
+ }
83
101
  const response = await this.postgres.query(sql);
102
+ await this.disconnect();
84
103
  return response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
85
104
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
86
105
  }
package/dist/src/f.js CHANGED
@@ -81,5 +81,7 @@ const utils = new TriangleUtils(config);
81
81
  // .then(user => console.log(user))
82
82
  // await utils.bedrock.cohere_invoke("cohere.embed-v4", "yyyyyuuuuuurrrrr")
83
83
  // .then(response => console.log(response))
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
- .then(response => console.log(response));
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
+ // .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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.157",
3
+ "version": "1.4.158",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsRDS.ts CHANGED
@@ -44,7 +44,10 @@ function convert_rds_output(input : Field) {
44
44
 
45
45
  export class UtilsRDS {
46
46
 
47
- private readonly postgres : Client
47
+ private readonly rds_host : string
48
+ private readonly rds_username : string
49
+ private readonly rds_password : string
50
+ private postgres? : Client
48
51
  private readonly rds_data : RDSData
49
52
  private readonly rds_cluster_arn : string
50
53
  private readonly rds_secret_arn : string
@@ -57,27 +60,37 @@ export class UtilsRDS {
57
60
  rds_username : string,
58
61
  rds_password : string
59
62
  ) {
63
+ this.rds_host = rds_host
64
+ this.rds_username = rds_username
65
+ this.rds_password = rds_password
66
+ this.rds_data = new RDSData({ region : region })
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
+ }
60
75
  this.postgres = new Client({
61
- host : rds_host,
62
- user : rds_username,
63
- password : rds_password,
76
+ host : this.rds_host,
77
+ user : this.rds_username,
78
+ password : this.rds_password,
64
79
  database : "triangle",
65
80
  port : 5432,
66
81
  ssl : {
67
82
  rejectUnauthorized: false
68
83
  }
69
84
  })
70
- this.rds_data = new RDSData({ region : region })
71
- this.rds_cluster_arn = rds_cluster_arn,
72
- this.rds_secret_arn = rds_secret_arn
73
- }
74
-
75
- async connect() {
76
85
  await this.postgres.connect()
77
86
  }
78
87
 
79
88
  async disconnect() {
89
+ if (this.postgres === undefined) {
90
+ return
91
+ }
80
92
  await this.postgres.end()
93
+ this.postgres = undefined
81
94
  }
82
95
 
83
96
  async query(
@@ -87,10 +100,16 @@ export class UtilsRDS {
87
100
  } = {}
88
101
  ) {
89
102
  const is_verbose = Boolean(options.is_verbose)
103
+ await this.connect()
90
104
  if (is_verbose) {
91
105
  console.log(sql)
92
106
  }
107
+ if (this.postgres === undefined) {
108
+ console.log("Failed to connect to Postgres.")
109
+ return
110
+ }
93
111
  const response = await this.postgres.query(sql)
112
+ await this.disconnect()
94
113
  return response.rows.map(item => Object.fromEntries(
95
114
  response.fields.map(field => [field.name, field.dataTypeID === 1700 ? Number(item[field.name]) : item[field.name]])
96
115
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
package/src/f.ts CHANGED
@@ -103,5 +103,8 @@ const utils = new TriangleUtils(config)
103
103
  // await utils.bedrock.cohere_invoke("cohere.embed-v4", "yyyyyuuuuuurrrrr")
104
104
  // .then(response => console.log(response))
105
105
 
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
- .then(response => console.log(response))
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
+ // .then(response => console.log(response))
108
+
109
+ const scouts = await utils.rds.batch_get("scouts", [], { is_verbose : true })
110
+ .then(console.log)