dbgate-datalib 4.6.0 → 4.6.1

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.
@@ -13,6 +13,7 @@ export interface DisplayColumn {
13
13
  autoIncrement?: boolean;
14
14
  isPrimaryKey?: boolean;
15
15
  foreignKey?: ForeignKeyInfo;
16
+ isForeignKeyUnique?: boolean;
16
17
  isExpandable?: boolean;
17
18
  isChecked?: boolean;
18
19
  hintColumnNames?: string[];
@@ -12,7 +12,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
12
12
  var _a;
13
13
  super(config, setConfig, cache, setCache, null);
14
14
  this.filterable = true;
15
- if (structure.columns) {
15
+ if (structure === null || structure === void 0 ? void 0 : structure.columns) {
16
16
  this.columns = lodash_1.default.uniqBy((_a = structure.columns
17
17
  .map(col => ({
18
18
  columnName: col.columnName,
@@ -25,7 +25,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
25
25
  schemaName: null,
26
26
  }))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) }))), col => col.uniqueName);
27
27
  }
28
- if (structure.__isDynamicStructure) {
28
+ if (structure === null || structure === void 0 ? void 0 : structure.__isDynamicStructure) {
29
29
  this.columns = (0, CollectionGridDisplay_1.analyseCollectionDisplayColumns)(rows, this);
30
30
  }
31
31
  if (!this.columns)
@@ -32,6 +32,7 @@ export declare class TableGridDisplay extends GridDisplay {
32
32
  uniquePath: string[];
33
33
  isPrimaryKey: boolean;
34
34
  foreignKey: ForeignKeyInfo;
35
+ isForeignKeyUnique: boolean;
35
36
  pairingId?: string;
36
37
  columnName: string;
37
38
  notNull: boolean;
@@ -64,6 +65,7 @@ export declare class TableGridDisplay extends GridDisplay {
64
65
  uniquePath: string[];
65
66
  isPrimaryKey: boolean;
66
67
  foreignKey: ForeignKeyInfo;
68
+ isForeignKeyUnique: boolean;
67
69
  pairingId?: string;
68
70
  columnName: string;
69
71
  notNull: boolean;
@@ -41,7 +41,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
41
41
  var _a, _b;
42
42
  return (((_b = (_a = table === null || table === void 0 ? void 0 : table.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(table, col, parentPath))) === null || _b === void 0 ? void 0 : _b.map(col => {
43
43
  var _a, _b, _c;
44
- return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.foreignKey)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(columnName => `hint_${col.uniqueName}_${columnName}`)) || null, hintColumnDelimiter: (_c = this.getFkDictionaryDescription(col.foreignKey)) === null || _c === void 0 ? void 0 : _c.delimiter, isExpandable: !!col.foreignKey }));
44
+ return (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnNames: ((_b = (_a = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(columnName => `hint_${col.uniqueName}_${columnName}`)) || null, hintColumnDelimiter: (_c = this.getFkDictionaryDescription(col.isForeignKeyUnique ? col.foreignKey : null)) === null || _c === void 0 ? void 0 : _c.delimiter, isExpandable: !!col.foreignKey }));
45
45
  })) || []);
46
46
  }
47
47
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
@@ -148,7 +148,9 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
148
148
  return [];
149
149
  }
150
150
  getFkTarget(column) {
151
- const { uniqueName, foreignKey } = column;
151
+ const { uniqueName, foreignKey, isForeignKeyUnique } = column;
152
+ if (!isForeignKeyUnique)
153
+ return null;
152
154
  const pureName = foreignKey.refTableName;
153
155
  const schemaName = foreignKey.refSchemaName;
154
156
  return this.findTable({ schemaName, pureName });
@@ -172,9 +174,16 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
172
174
  const uniquePath = [...parentPath, col.columnName];
173
175
  const uniqueName = uniquePath.join('.');
174
176
  // console.log('this.config.addedColumns', this.config.addedColumns, uniquePath);
175
- return Object.assign(Object.assign({}, col), { pureName: table.pureName, schemaName: table.schemaName, headerText: uniquePath.length == 1 ? col.columnName : `${table.pureName}.${col.columnName}`, uniqueName,
177
+ const res = Object.assign(Object.assign({}, col), { pureName: table.pureName, schemaName: table.schemaName, headerText: uniquePath.length == 1 ? col.columnName : `${table.pureName}.${col.columnName}`, uniqueName,
176
178
  uniquePath, isPrimaryKey: table.primaryKey && !!table.primaryKey.columns.find(x => x.columnName == col.columnName), foreignKey: table.foreignKeys &&
177
- table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName) });
179
+ table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName), isForeignKeyUnique: false });
180
+ if (res.foreignKey) {
181
+ const refTableInfo = this.dbinfo.tables.find(x => x.schemaName == res.foreignKey.refSchemaName && x.pureName == res.foreignKey.refTableName);
182
+ if (refTableInfo && (0, dbgate_tools_1.isTableColumnUnique)(refTableInfo, res.foreignKey.columns[0].refColumnName)) {
183
+ res.isForeignKeyUnique = true;
184
+ }
185
+ }
186
+ return res;
178
187
  }
179
188
  addAddedColumnsToSelect(select, columns, parentAlias, displayedColumnInfo) {
180
189
  for (const column of columns) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.6.0",
2
+ "version": "4.6.1",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -11,11 +11,11 @@
11
11
  "lib"
12
12
  ],
13
13
  "dependencies": {
14
- "dbgate-sqltree": "^4.6.0",
15
- "dbgate-filterparser": "^4.6.0"
14
+ "dbgate-sqltree": "^4.6.1",
15
+ "dbgate-filterparser": "^4.6.1"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.6.0",
18
+ "dbgate-types": "^4.6.1",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }