@opengis/fastify-table 2.0.15 → 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,28 +69,42 @@ 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
|
+
async function query(q, args = []) {
|
|
72
73
|
try {
|
|
73
|
-
if (isstream) {
|
|
74
|
-
await client.query("set statement_timeout to 100000000");
|
|
75
|
-
}
|
|
76
74
|
const data = await client.query(q, args);
|
|
77
|
-
await client.query("set statement_timeout to 0");
|
|
78
75
|
return data;
|
|
79
76
|
}
|
|
80
77
|
catch (err) {
|
|
81
|
-
|
|
82
|
-
if (err.
|
|
78
|
+
// canceling statement due to statement timeout
|
|
79
|
+
if (err.code === "57014") {
|
|
83
80
|
logger.file("timeout/query", { q, stack: err.stack });
|
|
84
|
-
return { rows: [], timeout: true };
|
|
85
81
|
}
|
|
86
|
-
throw
|
|
82
|
+
throw err;
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
async function querySafe(q, param) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
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);
|
|
99
|
+
return { rows: [], timeout: true };
|
|
100
|
+
}
|
|
101
|
+
console.error("pg.querySafe error", q);
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
pg1.end();
|
|
106
|
+
console.log("pg.querySafe released", q);
|
|
107
|
+
}
|
|
93
108
|
}
|
|
94
109
|
async function one(q, param) {
|
|
95
110
|
const data = await query(q, Array.isArray(param) ? param : param?.args || []);
|
|
@@ -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);
|