@opengis/fastify-table 1.2.83 → 1.2.84

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.83",
3
+ "version": "1.2.84",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -8,9 +8,21 @@ 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, table, column, key, val }) {
12
12
  if (selectMeta[name] && !nocache) return selectMeta[name];
13
13
 
14
+ if (table && column) {
15
+ const original = {
16
+ false: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column}, count(*) from ${table} group by ${column} limit ${limit}) select * from c`,
17
+ true: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column} from ${table}) select * from c`,
18
+ }[!!(key || val)];
19
+ return {
20
+ original,
21
+ searchQuery: '(lower("text") ~ $1 )',
22
+ pk: 'id',
23
+ };
24
+ }
25
+
14
26
  const cls = await getSelect(name, pg);
15
27
  const db = typeof cls?.db === 'string' ? { database: cls.db } : cls?.db;
16
28
  const pg1 = cls?.db ? getPG(db) : pg;
@@ -42,12 +42,7 @@ export default async function suggest(req) {
42
42
  return { status: 400, message: 'param limit is invalid' };
43
43
  }
44
44
 
45
- const meta = table && column
46
- ? {
47
- original: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column}, count(*) from ${tableName} group by ${column} limit ${limit}) select * from c`,
48
- searchQuery: '(lower("text") ~ $1 )',
49
- }
50
- : await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache });
45
+ const meta = await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache, table, column, key: query?.key, val: query?.val });
51
46
 
52
47
  if (meta?.minLength && query.key && query.key.length < meta?.minLength) {
53
48
  return { message: `min length: ${meta.minLength}` };