@opengis/fastify-table 2.0.113 → 2.0.114

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.
@@ -11,7 +11,7 @@ CREATE TABLE if not exists {{nspname}}.{{relname}}
11
11
  {{column_name}} {{data_type}} {{#unless is_nullable}}NOT NULL{{/unless}}{{#if column_default}}DEFAULT {{column_default}}{{/if}}{{#ifCond @index '!=' (_math ../columns.length '-' 1)}},{{/ifCond}} -- {{{coalesce description '-'}}}
12
12
  {{/each}}{{#if constraints.length}},{{/if}}
13
13
  {{#each constraints}}
14
- CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
14
+ CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'c'}} {{check_definition}} {{/ifCond}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
15
15
  {{/each}}
16
16
  );
17
17
 
@@ -115,7 +115,8 @@ async function schemaItem({ pg, table, schema, debug, }) {
115
115
  throw new Error("invalid params");
116
116
  const { rows: constraints } = await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
117
117
  con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
118
- con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column from pg_constraint con
118
+ con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
119
+ case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
119
120
  left join pg_class c ON c.oid = con.conrelid
120
121
  left join pg_namespace n ON n.oid = c.relnamespace
121
122
  left join lateral (
@@ -136,7 +137,14 @@ async function schemaItem({ pg, table, schema, debug, }) {
136
137
  Object.assign(col, { constraint_type });
137
138
  });
138
139
  // table relations
139
- const tableConstraints = constraints?.filter((el) => el?.constraint_table === `${row.nspname}.${row.relname}`);
140
+ const tableConstraints = constraints
141
+ ?.filter((el) => el?.constraint_table === `${row.nspname}.${row.relname}`)
142
+ ?.map((el) => ({
143
+ ...el,
144
+ check_definition: el.check_definition
145
+ ? new handlebars.SafeString(el.check_definition)
146
+ : null,
147
+ }));
140
148
  Object.assign(row, { constraints: tableConstraints });
141
149
  });
142
150
  if (debug)
@@ -156,7 +156,8 @@ async function schemaItem({
156
156
  const { rows: constraints } =
157
157
  await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
158
158
  con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
159
- con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column from pg_constraint con
159
+ con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
160
+ case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
160
161
  left join pg_class c ON c.oid = con.conrelid
161
162
  left join pg_namespace n ON n.oid = c.relnamespace
162
163
  left join lateral (
@@ -185,9 +186,16 @@ async function schemaItem({
185
186
  });
186
187
 
187
188
  // table relations
188
- const tableConstraints = constraints?.filter(
189
- (el: any) => el?.constraint_table === `${row.nspname}.${row.relname}`
190
- );
189
+ const tableConstraints = constraints
190
+ ?.filter(
191
+ (el: any) => el?.constraint_table === `${row.nspname}.${row.relname}`
192
+ )
193
+ ?.map((el: any) => ({
194
+ ...el,
195
+ check_definition: el.check_definition
196
+ ? new handlebars.SafeString(el.check_definition)
197
+ : null,
198
+ }));
191
199
  Object.assign(row, { constraints: tableConstraints });
192
200
  });
193
201
 
@@ -231,7 +231,7 @@ export default async function dataAPI({ pg = pgClients.client, params, table, id
231
231
  const fData = checkFilter
232
232
  ? await getFilterSQL({
233
233
  pg,
234
- table: loadTable ? paramsTable : table1,
234
+ table: loadTable ? tokenData?.table || paramsTable : table1,
235
235
  filter: query?.filter,
236
236
  search: query?.search,
237
237
  state: query?.state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.113",
3
+ "version": "2.0.114",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -21,8 +21,10 @@
21
21
  "dist/*"
22
22
  ],
23
23
  "scripts": {
24
- "dump": "bun ./dist/script/dump.js",
25
- "migrate": "MIGRATE=true bun ./dist/script/migrate.js",
24
+ "dump": "bun ./script/dump.ts",
25
+ "migrate": "MIGRATE=true bun ./script/migrate.ts",
26
+ "dump1": "bun ./dist/script/dump.js",
27
+ "migrate1": "MIGRATE=true bun ./dist/script/migrate.js",
26
28
  "prepublishOnly": "npm run build",
27
29
  "clean": "tsc -b --clean",
28
30
  "build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist && copyfiles server/templates/**/*.hbs dist && copyfiles script/* dist && copyfiles -u 2 module/core/*/* dist/module/core",