@opengis/fastify-table 2.0.16 → 2.0.17
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.
|
@@ -13,7 +13,8 @@ function getPG(param = {}) {
|
|
|
13
13
|
const dbListParams = dblist.find((el) => el.key === param?.key) ||
|
|
14
14
|
dblist.find((el) => el.database === (param?.db || param?.database || param) &&
|
|
15
15
|
el.port === param?.port);
|
|
16
|
-
const { user, password, host, port, db, database, name: origin,
|
|
16
|
+
const { user, password, host, port, db, database, name: origin, statement_timeout: timeout, // explicit
|
|
17
|
+
} = dbListParams ??
|
|
17
18
|
(typeof param === "string" ? getDBParams(param) : param || {});
|
|
18
19
|
const name = origin || db || database || param || "client";
|
|
19
20
|
if (pgClients[name])
|
|
@@ -24,7 +25,7 @@ function getPG(param = {}) {
|
|
|
24
25
|
host: host || config.pg?.host,
|
|
25
26
|
port: port || config.pg?.port,
|
|
26
27
|
database: db || database || config.pg?.db || config.pg?.database,
|
|
27
|
-
statement_timeout: config.pg?.statement_timeout || 10000,
|
|
28
|
+
statement_timeout: timeout || config.pg?.statement_timeout || 10000,
|
|
28
29
|
};
|
|
29
30
|
if (!dbConfig.database) {
|
|
30
31
|
return null;
|
|
@@ -12,7 +12,8 @@ async function getPGAsync(param) {
|
|
|
12
12
|
return null;
|
|
13
13
|
const dbListParams = dblist.find((el) => el.key === param?.key) ||
|
|
14
14
|
dblist.find((el) => el.database === (param?.db || param?.database || param));
|
|
15
|
-
const { user, password, host, port, db, database, name: origin,
|
|
15
|
+
const { user, password, host, port, db, database, name: origin, statement_timeout: timeout, // explicit
|
|
16
|
+
} = dbListParams ??
|
|
16
17
|
(typeof param === "string" ? getDBParams(param) : param || {});
|
|
17
18
|
const name = origin || db || database || param || "client";
|
|
18
19
|
if (pgClients[name]?.tlist)
|
|
@@ -23,7 +24,7 @@ async function getPGAsync(param) {
|
|
|
23
24
|
host: host || config.pg?.host,
|
|
24
25
|
port: port || config.pg?.port,
|
|
25
26
|
database: db || database || config.pg?.db || config.pg?.database,
|
|
26
|
-
statement_timeout: config.pg?.statement_timeout || 10000,
|
|
27
|
+
statement_timeout: timeout || config.pg?.statement_timeout || 10000,
|
|
27
28
|
};
|
|
28
29
|
if (!dbConfig.database) {
|
|
29
30
|
return null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pg from "pg";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import config from "../../../../config.js";
|
|
3
4
|
import getRedis from "../../redis/funcs/getRedis.js";
|
|
@@ -68,34 +69,43 @@ async function init(client) {
|
|
|
68
69
|
WHERE
|
|
69
70
|
relkind IN ('r', 'v')`);
|
|
70
71
|
const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
|
|
71
|
-
async function query(q, args = []
|
|
72
|
-
let timeoutWasSet;
|
|
72
|
+
async function query(q, args = []) {
|
|
73
73
|
try {
|
|
74
|
-
if (isstream) {
|
|
75
|
-
await client.query(`set statement_timeout to ${timeout}`);
|
|
76
|
-
timeoutWasSet = true;
|
|
77
|
-
}
|
|
78
74
|
const data = await client.query(q, args);
|
|
79
75
|
return data;
|
|
80
76
|
}
|
|
81
77
|
catch (err) {
|
|
82
|
-
|
|
78
|
+
// canceling statement due to statement timeout
|
|
79
|
+
if (err.code === "57014") {
|
|
83
80
|
logger.file("timeout/query", { q, stack: err.stack });
|
|
81
|
+
}
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function querySafe(q, param) {
|
|
86
|
+
const pg1 = new pg.Pool({
|
|
87
|
+
...client.options,
|
|
88
|
+
statement_timeout: param?.timeout || 100000000,
|
|
89
|
+
});
|
|
90
|
+
try {
|
|
91
|
+
const args = Array.isArray(param) ? param : param?.args || [];
|
|
92
|
+
const data = await pg1.query(q, args);
|
|
93
|
+
console.log("pg.querySafe ok", q);
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
if (err.code === "57014") {
|
|
98
|
+
console.error("pg.querySafe timeout", q);
|
|
84
99
|
return { rows: [], timeout: true };
|
|
85
100
|
}
|
|
86
|
-
|
|
101
|
+
console.error("pg.querySafe error", q);
|
|
102
|
+
throw err;
|
|
87
103
|
}
|
|
88
104
|
finally {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
105
|
+
pg1.end();
|
|
106
|
+
console.log("pg.querySafe released", q);
|
|
92
107
|
}
|
|
93
108
|
}
|
|
94
|
-
async function querySafe(q, param) {
|
|
95
|
-
const args = Array.isArray(param) ? param : param?.args || [];
|
|
96
|
-
const data = await query(q, args, true, param?.timeout);
|
|
97
|
-
return data;
|
|
98
|
-
}
|
|
99
109
|
async function one(q, param) {
|
|
100
110
|
const data = await query(q, Array.isArray(param) ? param : param?.args || []);
|
|
101
111
|
const result = ((Array.isArray(data) ? data.pop() : data)?.rows || [])[0] || {};
|
|
@@ -77,7 +77,7 @@ export default async function getFilterSQL({ table, filter, pg = pgClients.clien
|
|
|
77
77
|
const { fields = [] } = await pg.query(fieldQuery);
|
|
78
78
|
const autoSearchColumn = fields
|
|
79
79
|
?.filter((el) => pg.pgType?.[el.dataTypeID] === "text")
|
|
80
|
-
?.map((el) => el.name)
|
|
80
|
+
?.map((el) => `"${el.name}"`)
|
|
81
81
|
.join(",");
|
|
82
82
|
const searchColumn = body?.search_column || body?.meta?.search || autoSearchColumn;
|
|
83
83
|
const fieldsList = (fieldsModel || fields)?.map((el) => el.name);
|