@opengis/fastify-table 1.0.93 → 1.0.94

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,5 +1,9 @@
1
1
  # fastify-table
2
2
 
3
+ ## 1.0.94 - 11.09.2024
4
+
5
+ - fix getMeta (public schema)
6
+
3
7
  ## 1.0.93 - 05.09.2024
4
8
 
5
9
  - fix data API with sql columns filter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.93",
3
+ "version": "1.0.94",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -1,27 +1,27 @@
1
- // import pgClient from '../pgClients.js';
2
- import getPG from './getPG.js';
3
-
4
- const data = {};
5
-
6
- // decorator
7
- export default async function getMeta(opt) {
8
- const pg = opt.pg || getPG({ name: 'client' });
9
- const table = opt.table || opt;
10
-
11
- if (data[table]) return data[table];
12
-
13
- if (!pg.tlist?.includes(table)) {
14
- return { error: `${table} - not found`, status: 400 };
15
- }
16
-
17
- const { fields } = await pg.query(`select * from ${table} where $1=$1 limit 0`, [1]);
18
- const { pks1 } = await pg.one(`SELECT json_object_agg(c.conrelid::regclass, a.attname) as pks1 FROM pg_constraint c
19
- left join pg_attribute a on c.conrelid=a.attrelid and a.attnum = c.conkey[1] WHERE c.contype='p'::"char"`, { cache: 0 });
20
- const pk = pks1[table];
21
-
22
- const geomAttr = fields.find((el) => pg.pgType[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
23
-
24
- const res = { pk, columns: fields, geom: geomAttr };
25
- data[table] = res;
26
- return res;
27
- }
1
+ // import pgClient from '../pgClients.js';
2
+ import getPG from './getPG.js';
3
+
4
+ const data = {};
5
+
6
+ // decorator
7
+ export default async function getMeta(opt) {
8
+ const pg = opt.pg || getPG({ name: 'client' });
9
+ const table = opt.table || opt;
10
+
11
+ if (data[table]) return data[table];
12
+
13
+ if (!pg.tlist?.includes(table)) {
14
+ return { error: `${table} - not found`, status: 400 };
15
+ }
16
+
17
+ const { fields } = await pg.query(`select * from ${table} where $1=$1 limit 0`, [1]);
18
+ const { pks1 } = await pg.one(`SELECT json_object_agg(c.conrelid::regclass, a.attname) as pks1 FROM pg_constraint c
19
+ left join pg_attribute a on c.conrelid=a.attrelid and a.attnum = c.conkey[1] WHERE c.contype='p'::"char"`, { cache: 0 });
20
+ const pk = table.startsWith('public.') ? pks1[table.replace('public.', '')] : pks1[table];
21
+
22
+ const geomAttr = fields.find((el) => pg.pgType[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
23
+
24
+ const res = { pk, columns: fields, geom: geomAttr };
25
+ data[table] = res;
26
+ return res;
27
+ }