@opengis/fastify-table 1.3.45 → 1.3.46

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.3.45",
3
+ "version": "1.3.46",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -8,7 +8,7 @@ import getSelect from './getSelect.js';
8
8
  const limit = 50;
9
9
  const selectMeta = {};
10
10
 
11
- export default async function getSelectMeta({ name, pg = pgClients.client, nocache }) {
11
+ export default async function getSelectMeta({ name, pg = pgClients.client, nocache, parent }) {
12
12
  if (selectMeta[name] && !nocache) return selectMeta[name];
13
13
 
14
14
  const cls = await getSelect(name, pg);
@@ -23,7 +23,7 @@ export default async function getSelectMeta({ name, pg = pgClients.client, nocac
23
23
  const { sql: original } = cls;
24
24
  if (!original.toLowerCase) { console.log(`sql select null: ${name}`); return null; }
25
25
 
26
- const sql = `with c(id,text) as (select * from (${original})q limit ${limit}) select * from c`;
26
+ const sql = `with c(id,text) as (select * from (${original.replace('{{parent}}', parent)})q limit ${limit}) select * from c`;
27
27
 
28
28
  /*= == meta table === */
29
29
 
@@ -32,10 +32,10 @@ export default async function getSelectMeta({ name, pg = pgClients.client, nocac
32
32
 
33
33
  const dataOrigin = await pg1.query(sql?.replace(`limit ${limit}`, 'limit 0'));
34
34
 
35
- const dataOrigin1 = await pg1.query(`${original} limit 0`);
35
+ const dataOrigin1 = await pg1.query(`${original.replace('{{parent}}', parent)} limit 0`);
36
36
 
37
37
  // const table = getTable(original);
38
- const count = cls?.count ?? await pg1.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
38
+ const count = cls?.count ?? await pg1.query(`select count(*) from (${original.replace('{{parent}}', parent)})q`).then((el) => el?.rows?.[0].count);
39
39
 
40
40
  // column name
41
41
  const cols = dataOrigin.fields.map((el) => el.name);
@@ -56,7 +56,7 @@ export default async function suggest(req) {
56
56
 
57
57
  const meta = table && column
58
58
  ? getTableColumnMeta(table, column, query?.key || query?.val)
59
- : await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache });
59
+ : await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache, parent });
60
60
 
61
61
  if (meta?.minLength && query.key && query.key.length < meta?.minLength) {
62
62
  return { message: `min length: ${meta.minLength}` };