@opengis/fastify-table 1.1.10 → 1.1.12

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/Changelog.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fastify-table
2
2
 
3
- ## 1.1.10 - 24.09.2024
3
+ ## 1.1.12 - 24.09.2024
4
4
 
5
5
  - fix update crud editor id/date + geom
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -1,6 +1,7 @@
1
1
  import getTemplate from './utils/getTemplate.js';
2
2
  import getSelect from './utils/getSelect.js';
3
3
  import getMeta from '../../pg/funcs/getMeta.js';
4
+ import getFilterSQL from '../funcs/getFilterSQL/index.js';
4
5
 
5
6
  export default async function filter(req) {
6
7
  const time = Date.now();
@@ -12,14 +13,16 @@ export default async function filter(req) {
12
13
  if (!loadTable) { return { status: 404, message: 'not found' }; }
13
14
  const { columns } = await getMeta({ table: loadTable.table });
14
15
 
16
+ const { optimizedSQL = `select * from ${loadTable.table}` } = loadTable?.sql ? await getFilterSQL({ table: params.table, pg: req.pg }) : {};
17
+
15
18
  const filters = loadTable?.filters || loadTable?.filterList || [];
16
19
  await Promise.all(filters.filter((el) => el.data).map(async (el) => {
17
20
  const cls = await getSelect(el.data);
18
21
  if (!cls?.arr || !loadTable.table) return;
19
22
  const { dataTypeID } = columns.find((item) => item.name === el.id) || {};
20
23
  const countArr = req.pg.pgType[dataTypeID]?.includes('[]')
21
- ? await req.pg.queryCache(`select unnest(${el.id})::text as id,count(*) from ${loadTable.table} group by unnest(${el.id})`)
22
- : await req.pg.queryCache(`select ${el.id}::text as id,count(*) from ${loadTable.table} group by ${el.id}`);
24
+ ? await req.pg.queryCache(`select unnest(${el.id})::text as id,count(*) from (${optimizedSQL})q group by unnest(${el.id})`)
25
+ : await req.pg.queryCache(`select ${el.id}::text as id,count(*) from (${optimizedSQL})q group by ${el.id}`);
23
26
 
24
27
  const options = countArr.rows.map(cel => {
25
28
  const data = cls?.arr.find(c => c.id === cel.id);
package/utils.js CHANGED
@@ -23,6 +23,7 @@ import checkXSS from './crud/controllers/utils/checkXSS.js';
23
23
  import gisIRColumn from './table/controllers/utils/gisIRColumn.js';
24
24
  import getMeta from './pg/funcs/getMeta.js';
25
25
  import getAccess from './crud/funcs/getAccess.js';
26
+ import getSelectVal from './table/funcs/metaFormat/getSelectVal.js';
26
27
 
27
28
  export default null;
28
29
  export {
@@ -45,4 +46,5 @@ export {
45
46
  gisIRColumn,
46
47
  getMeta,
47
48
  getAccess,
49
+ getSelectVal,
48
50
  };