@opengis/fastify-table 1.1.16 → 1.1.17

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.1.17 - 30.09.2024
4
+
5
+ - add relkinds to pg
6
+
3
7
  ## 1.1.16 - 27.09.2024
4
8
 
5
9
  - add migrations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -21,7 +21,9 @@ export default async function getMeta(opt) {
21
21
 
22
22
  const geomAttr = fields.find((el) => pg.pgType[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
23
23
 
24
- const res = { pk, columns: fields, geom: geomAttr };
24
+ const res = {
25
+ pk, columns: fields, geom: geomAttr, view: pg.relkinds?.[table] === 'v',
26
+ };
25
27
  data[table] = res;
26
28
  return res;
27
29
  }
package/pg/funcs/init.js CHANGED
@@ -14,6 +14,10 @@ async function init(client) {
14
14
  const tlist = await client.query(`select array_agg((select nspname from pg_namespace where oid=relnamespace)||'.'||relname) tlist
15
15
  from pg_class where relkind in ('r','v')`).then((d) => d.rows[0].tlist);
16
16
 
17
+ const { rows = [] } = await client.query(`select (select nspname from pg_namespace where oid=relnamespace)||'.'||relname as tname, relkind
18
+ from pg_class where relkind in ('r','v')`);
19
+ const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
20
+
17
21
  async function one(query, param = {}) {
18
22
  const data = await client.query(query, Array.isArray(param) ? param : param.args || []);
19
23
  const result = ((Array.isArray(data) ? data.pop() : data)?.rows || [])[0] || {};
@@ -29,7 +33,8 @@ async function init(client) {
29
33
  try {
30
34
  result = await clientCb.query(query, args);
31
35
  clientCb.end();
32
- } catch (err) {
36
+ }
37
+ catch (err) {
33
38
  clientCb.end();
34
39
  cb(err.toString(), 1);
35
40
  throw err;
@@ -51,7 +56,7 @@ async function init(client) {
51
56
  }
52
57
 
53
58
  Object.assign(client, {
54
- one, pgType, pk, tlist, queryCache, queryNotice,
59
+ one, pgType, pk, tlist, relkinds, queryCache, queryNotice,
55
60
  });
56
61
  }
57
62
 
@@ -21,7 +21,12 @@ export default async function dataAPI({
21
21
  const {
22
22
  table, columns, sql, cardSql, filters, form, meta, sqlColumns, ispublic,
23
23
  } = loadTable;
24
- const { pk, columns: dbColumns = [] } = await getMeta(table);
24
+ const tableMeta = await getMeta(table);
25
+ if (tableMeta?.view) {
26
+ if (!loadTable?.key) return { message: `key not found: ${table}`, status: 404 };
27
+ Object.assign(tableMeta, { pk: loadTable?.key });
28
+ }
29
+ const { pk, columns: dbColumns = [] } = tableMeta || {};
25
30
 
26
31
  if (!pk) return { message: `table not found: ${table}`, status: 404 };
27
32