@opengis/fastify-table 2.0.15 → 2.0.16

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.
@@ -68,27 +68,32 @@ async function init(client) {
68
68
  WHERE
69
69
  relkind IN ('r', 'v')`);
70
70
  const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
71
- async function query(q, args = [], isstream = false) {
71
+ async function query(q, args = [], isstream = false, timeout = 100000000) {
72
+ let timeoutWasSet;
72
73
  try {
73
74
  if (isstream) {
74
- await client.query("set statement_timeout to 100000000");
75
+ await client.query(`set statement_timeout to ${timeout}`);
76
+ timeoutWasSet = true;
75
77
  }
76
78
  const data = await client.query(q, args);
77
- await client.query("set statement_timeout to 0");
78
79
  return data;
79
80
  }
80
81
  catch (err) {
81
- await client.query("set statement_timeout to 0");
82
82
  if (err.message === "canceling statement due to statement timeout") {
83
83
  logger.file("timeout/query", { q, stack: err.stack });
84
84
  return { rows: [], timeout: true };
85
85
  }
86
86
  throw new Error(err);
87
87
  }
88
+ finally {
89
+ if (timeoutWasSet) {
90
+ await client.query("RESET statement_timeout");
91
+ }
92
+ }
88
93
  }
89
94
  async function querySafe(q, param) {
90
95
  const args = Array.isArray(param) ? param : param?.args || [];
91
- const data = await query(q, args, true);
96
+ const data = await query(q, args, true, param?.timeout);
92
97
  return data;
93
98
  }
94
99
  async function one(q, param) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [