@opengis/fastify-table 1.2.64 → 1.2.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.2.64",
3
+ "version": "1.2.66",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -20,13 +20,16 @@ async function init(client) {
20
20
  from pg_class where relkind in ('r','v')`);
21
21
  const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
22
22
 
23
- // const { queryOriginal = client.query } = client;
24
-
25
- async function query(q, args = []) {
23
+ async function query(q, args = [], isstream) {
26
24
  try {
25
+ if (isstream) {
26
+ await client.query('set statement_timeout to 100000000');
27
+ }
27
28
  const data = await client.query(q, args);
29
+ await client.query('set statement_timeout to 0');
28
30
  return data;
29
31
  } catch (err) {
32
+ await client.query('set statement_timeout to 0');
30
33
  if (err.message === 'canceling statement due to statement timeout') {
31
34
  logger.file('timeout/query', { q, stack: err.stack });
32
35
  return { rows: [], timeout: true };
@@ -35,6 +38,12 @@ async function init(client) {
35
38
  }
36
39
  }
37
40
 
41
+ async function querySafe(q, param = {}) {
42
+ const { args, isstream } = param;
43
+ const data = await query(q, args, isstream);
44
+ return data;
45
+ }
46
+
38
47
  async function one(q, param = {}) {
39
48
  const data = await query(q, Array.isArray(param) ? param : param.args || []);
40
49
  const result = ((Array.isArray(data) ? data.pop() : data)?.rows || [])[0] || {};
@@ -88,7 +97,7 @@ async function init(client) {
88
97
  }
89
98
 
90
99
  Object.assign(client, {
91
- one, pgType, pk, tlist, relkinds, queryCache, queryNotice, /* queryOriginal, */
100
+ one, pgType, pk, tlist, relkinds, queryCache, queryNotice, querySafe,
92
101
  });
93
102
  }
94
103
 
@@ -205,7 +205,7 @@ function formatValue({
205
205
  return { op: 'ilike', query, extra };
206
206
  }
207
207
 
208
- const query = data && sql
208
+ const query = data && sql && filterType == 'text'
209
209
  ? `${name || filter?.id} in ( ( with q(id,name) as (${sql}) select id from q where ${filterType === 'autocomplete' ? 'id' : 'name'}::text ${match}) )` // filter with cls
210
210
  : `${name}::text ${match}`; // simple filter
211
211
  // console.log(query);