triangle-utils 1.4.179 → 1.4.181

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.
@@ -3,10 +3,7 @@ export declare class UtilsRDS {
3
3
  private readonly rds_username;
4
4
  private readonly rds_password;
5
5
  private readonly pool;
6
- constructor(region: string, rds_cluster_arn: string, rds_secret_arn: string, rds_host: string, rds_username: string, rds_password: string);
7
- query(sql: string, options?: {
8
- is_verbose?: boolean;
9
- }): Promise<any[]>;
6
+ constructor(rds_host: string, rds_username: string, rds_password: string);
10
7
  exec(sql: string, options?: {
11
8
  is_verbose?: boolean;
12
9
  }): Promise<any[]>;
@@ -1,4 +1,5 @@
1
1
  import { Pool } from "pg";
2
+ import wkx from "wkx";
2
3
  function convert_postgres_input(input) {
3
4
  if (input === undefined) {
4
5
  return "NULL";
@@ -16,8 +17,8 @@ function convert_postgres_input(input) {
16
17
  return "ARRAY[" + input.map(a => convert_postgres_input(a)).join(", ") + "]";
17
18
  }
18
19
  else if (typeof input === "object") {
19
- if (input.expression !== undefined) {
20
- return input.expression;
20
+ if (input.wkt !== undefined) {
21
+ return "ST_GEOMFROMTEXT('" + input.wkt + "')";
21
22
  }
22
23
  }
23
24
  return "NULL";
@@ -50,6 +51,9 @@ function convert_postgres_output(output, field) {
50
51
  if (field.dataTypeID === 712048) {
51
52
  return JSON.parse(output[field.name]);
52
53
  }
54
+ if (field.dataTypeID === 110963) {
55
+ return { wkt: wkx.Geometry.parse(output[field.name]).toWkt() };
56
+ }
53
57
  return output[field.name];
54
58
  }
55
59
  export class UtilsRDS {
@@ -57,7 +61,7 @@ export class UtilsRDS {
57
61
  rds_username;
58
62
  rds_password;
59
63
  pool;
60
- constructor(region, rds_cluster_arn, rds_secret_arn, rds_host, rds_username, rds_password) {
64
+ constructor(rds_host, rds_username, rds_password) {
61
65
  this.rds_host = rds_host;
62
66
  this.rds_username = rds_username;
63
67
  this.rds_password = rds_password;
@@ -72,21 +76,14 @@ export class UtilsRDS {
72
76
  }
73
77
  });
74
78
  }
75
- async query(sql, options = {}) {
79
+ async exec(sql, options = {}) {
76
80
  const is_verbose = Boolean(options.is_verbose);
77
81
  if (is_verbose) {
78
82
  console.log(sql);
79
83
  }
80
84
  const response = await this.pool.query(sql);
81
- return response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
85
+ const items = response.rows.map(item => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
82
86
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
83
- }
84
- async exec(sql, options = {}) {
85
- const is_verbose = Boolean(options.is_verbose);
86
- if (is_verbose) {
87
- console.log(sql);
88
- }
89
- const items = await this.query(sql, options);
90
87
  if (!Array.isArray(items)) {
91
88
  if (is_verbose) {
92
89
  console.log("Bad items:", items);
package/dist/src/f.js CHANGED
@@ -83,5 +83,5 @@ 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
- await utils.rds.query("SELECT * FROM twitter_tweets LIMIT 10")
86
+ await utils.rds.exec("SELECT * FROM tenants")
87
87
  .then(console.log);
package/dist/src/index.js CHANGED
@@ -31,7 +31,7 @@ export class TriangleUtils extends UtilsMisc {
31
31
  constructor(config) {
32
32
  super(config);
33
33
  this.dynamodb = new UtilsDynamoDB(config.region);
34
- this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn, config.rds_host, config.rds_username, config.rds_password);
34
+ this.rds = new UtilsRDS(config.rds_host, config.rds_username, config.rds_password);
35
35
  this.s3 = new UtilsS3(config.region);
36
36
  this.s3vectors = new UtilsS3Vectors(config.region);
37
37
  this.bedrock = new UtilsBedrock(config.region);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.179",
3
+ "version": "1.4.181",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -36,7 +36,8 @@
36
36
  "googleapis": "^170.0.0",
37
37
  "jsdom": "^29.0.1",
38
38
  "pg": "^8.23.0",
39
- "scrapingbee": "^1.8.2"
39
+ "scrapingbee": "^1.8.2",
40
+ "wkx": "^0.5.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@eslint/js": "^9.39.2",
package/src/UtilsRDS.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FieldDef, Pool } from "pg"
2
+ import wkx from "wkx"
2
3
 
3
4
  function convert_postgres_input(input : string | boolean | number | any[] | Record<string, any> | undefined) : string {
4
5
  if (input === undefined) {
@@ -12,8 +13,8 @@ function convert_postgres_input(input : string | boolean | number | any[] | Reco
12
13
  } else if (Array.isArray(input)) {
13
14
  return "ARRAY[" + input.map(a => convert_postgres_input(a)).join(", ") + "]"
14
15
  } else if (typeof input === "object") {
15
- if (input.expression !== undefined) {
16
- return input.expression
16
+ if (input.wkt !== undefined) {
17
+ return "ST_GEOMFROMTEXT('" + input.wkt + "')"
17
18
  }
18
19
  }
19
20
  return "NULL"
@@ -48,6 +49,9 @@ function convert_postgres_output(output : any, field : FieldDef) {
48
49
  if (field.dataTypeID === 712048) {
49
50
  return JSON.parse(output[field.name])
50
51
  }
52
+ if (field.dataTypeID === 110963) {
53
+ return { wkt : wkx.Geometry.parse(output[field.name]).toWkt() }
54
+ }
51
55
  return output[field.name]
52
56
  }
53
57
 
@@ -59,9 +63,6 @@ export class UtilsRDS {
59
63
  private readonly pool : Pool
60
64
 
61
65
  constructor(
62
- region : string,
63
- rds_cluster_arn : string,
64
- rds_secret_arn : string,
65
66
  rds_host : string,
66
67
  rds_username : string,
67
68
  rds_password : string
@@ -81,7 +82,7 @@ export class UtilsRDS {
81
82
  })
82
83
  }
83
84
 
84
- async query(
85
+ async exec(
85
86
  sql : string,
86
87
  options : {
87
88
  is_verbose? : boolean
@@ -92,23 +93,10 @@ export class UtilsRDS {
92
93
  console.log(sql)
93
94
  }
94
95
  const response = await this.pool.query(sql)
95
- return response.rows.map(item => Object.fromEntries(
96
+ const items = response.rows.map(item => Object.fromEntries(
96
97
  response.fields.map(field => [field.name, convert_postgres_output(item, field)])
97
98
  .filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
98
99
  ))
99
- }
100
-
101
- async exec(
102
- sql : string,
103
- options : {
104
- is_verbose? : boolean
105
- } = {}
106
- ) {
107
- const is_verbose = Boolean(options.is_verbose)
108
- if (is_verbose) {
109
- console.log(sql)
110
- }
111
- const items = await this.query(sql, options)
112
100
  if (!Array.isArray(items)) {
113
101
  if (is_verbose) {
114
102
  console.log("Bad items:", items)
package/src/f.ts CHANGED
@@ -107,5 +107,5 @@ const utils = new TriangleUtils(config)
107
107
  // .then(response => console.log(response))
108
108
 
109
109
 
110
- await utils.rds.query("SELECT * FROM twitter_tweets LIMIT 10")
110
+ await utils.rds.exec("SELECT * FROM tenants")
111
111
  .then(console.log)
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ export class TriangleUtils extends UtilsMisc {
37
37
  constructor(config : GlobalConfig) {
38
38
  super(config)
39
39
  this.dynamodb = new UtilsDynamoDB(config.region)
40
- this.rds = new UtilsRDS(config.region, config.rds_cluster_arn, config.rds_secret_arn, config.rds_host, config.rds_username, config.rds_password)
40
+ this.rds = new UtilsRDS(config.rds_host, config.rds_username, config.rds_password)
41
41
  this.s3 = new UtilsS3(config.region)
42
42
  this.s3vectors = new UtilsS3Vectors(config.region)
43
43
  this.bedrock = new UtilsBedrock(config.region)