triangle-utils 1.4.184 → 1.4.185
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.js +7 -2
- package/dist/src/f.js +6 -1
- package/package.json +1 -1
- package/src/UtilsRDS.ts +8 -3
- package/src/f.ts +6 -1
package/dist/src/UtilsRDS.js
CHANGED
|
@@ -96,8 +96,13 @@ export class UtilsRDS {
|
|
|
96
96
|
console.log(sql);
|
|
97
97
|
}
|
|
98
98
|
const pool = is_read ? this.reader_pool : this.cluster_pool;
|
|
99
|
-
const response = await pool.query(sql)
|
|
100
|
-
|
|
99
|
+
const response = await pool.query(sql)
|
|
100
|
+
.then(response => Array.isArray(response) ? response.at(-1) : response);
|
|
101
|
+
if (response === undefined) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
const rows = response.rows;
|
|
105
|
+
const items = rows.map((item) => Object.fromEntries(response.fields.map(field => [field.name, convert_postgres_output(item, field)])
|
|
101
106
|
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)));
|
|
102
107
|
if (!Array.isArray(items)) {
|
|
103
108
|
if (is_verbose) {
|
package/dist/src/f.js
CHANGED
|
@@ -83,5 +83,10 @@ 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.
|
|
86
|
+
await utils.rds.exec(`SELECT sv.voter_id FROM state_voters as sv
|
|
87
|
+
INNER JOIN states as s ON ST_CONTAINS(s.geom, sv.address_residence_geom) AND s.state_id = 'WA'
|
|
88
|
+
WHERE
|
|
89
|
+
sv.state_id = 'WA'
|
|
90
|
+
ORDER BY random()
|
|
91
|
+
LIMIT 1000`)
|
|
87
92
|
.then(console.log);
|
package/package.json
CHANGED
package/src/UtilsRDS.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldDef, Pool } from "pg"
|
|
1
|
+
import { FieldDef, Pool, QueryResult } from "pg"
|
|
2
2
|
import wkx from "wkx"
|
|
3
3
|
|
|
4
4
|
function convert_postgres_input(input : string | boolean | number | any[] | Record<string, any> | undefined) : string {
|
|
@@ -109,8 +109,13 @@ export class UtilsRDS {
|
|
|
109
109
|
console.log(sql)
|
|
110
110
|
}
|
|
111
111
|
const pool = is_read ? this.reader_pool : this.cluster_pool
|
|
112
|
-
const response = await pool.query(sql)
|
|
113
|
-
|
|
112
|
+
const response : QueryResult<any> | undefined = await pool.query(sql)
|
|
113
|
+
.then(response => Array.isArray(response) ? response.at(-1) : response)
|
|
114
|
+
if (response === undefined) {
|
|
115
|
+
return []
|
|
116
|
+
}
|
|
117
|
+
const rows = response.rows
|
|
118
|
+
const items = rows.map((item : any) => Object.fromEntries(
|
|
114
119
|
response.fields.map(field => [field.name, convert_postgres_output(item, field)])
|
|
115
120
|
.filter(([attribute_name, attribute_value]) => attribute_value !== null && attribute_value !== undefined)
|
|
116
121
|
))
|
package/src/f.ts
CHANGED
|
@@ -107,5 +107,10 @@ const utils = new TriangleUtils(config)
|
|
|
107
107
|
// .then(response => console.log(response))
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
await utils.rds.
|
|
110
|
+
await utils.rds.exec(`SELECT sv.voter_id FROM state_voters as sv
|
|
111
|
+
INNER JOIN states as s ON ST_CONTAINS(s.geom, sv.address_residence_geom) AND s.state_id = 'WA'
|
|
112
|
+
WHERE
|
|
113
|
+
sv.state_id = 'WA'
|
|
114
|
+
ORDER BY random()
|
|
115
|
+
LIMIT 1000`)
|
|
111
116
|
.then(console.log)
|