dbgate-datalib 4.4.5-alpha.1 → 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.
@@ -16,7 +16,7 @@ export interface GridConfig extends GridConfigColumns {
16
16
  filters: {
17
17
  [uniqueName: string]: string;
18
18
  };
19
- focusedColumn?: string;
19
+ focusedColumns?: string[];
20
20
  columnWidths: {
21
21
  [uniqueName: string]: number;
22
22
  };
package/lib/GridConfig.js CHANGED
@@ -9,7 +9,7 @@ function createGridConfig() {
9
9
  filters: {},
10
10
  columnWidths: {},
11
11
  sort: [],
12
- focusedColumn: null,
12
+ focusedColumns: null,
13
13
  grouping: {},
14
14
  formFilterColumns: [],
15
15
  };
@@ -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[];
@@ -55,11 +56,12 @@ export declare abstract class GridDisplay {
55
56
  isDynamicStructure: boolean;
56
57
  setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
57
58
  addDynamicColumn(name: string): void;
58
- focusColumn(uniqueName: string): void;
59
+ focusColumns(uniqueNames: string[]): void;
59
60
  get hasReferences(): boolean;
60
- get focusedColumn(): string;
61
+ get focusedColumns(): string[];
61
62
  get engine(): string;
62
63
  get allColumns(): DisplayColumn[];
64
+ findColumn(uniqueName: string): DisplayColumn;
63
65
  getFkTarget(column: DisplayColumn): TableInfo;
64
66
  reload(): void;
65
67
  includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean): void;
@@ -52,14 +52,14 @@ class GridDisplay {
52
52
  addDynamicColumn(name) {
53
53
  this.includeInColumnSet('addedColumns', name, true);
54
54
  }
55
- focusColumn(uniqueName) {
56
- this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumn: uniqueName })));
55
+ focusColumns(uniqueNames) {
56
+ this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumns: uniqueNames })));
57
57
  }
58
58
  get hasReferences() {
59
59
  return false;
60
60
  }
61
- get focusedColumn() {
62
- return this.config.focusedColumn;
61
+ get focusedColumns() {
62
+ return this.config.focusedColumns;
63
63
  }
64
64
  get engine() {
65
65
  var _a;
@@ -68,6 +68,9 @@ class GridDisplay {
68
68
  get allColumns() {
69
69
  return this.getColumns(null).filter(col => col.isChecked || col.uniquePath.length == 1);
70
70
  }
71
+ findColumn(uniqueName) {
72
+ return this.getColumns(null).find(x => x.uniqueName == uniqueName);
73
+ }
71
74
  getFkTarget(column) {
72
75
  return null;
73
76
  }
@@ -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) {
@@ -7,15 +7,18 @@ exports.getDeleteCascades = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const ChangeSet_1 = require("./ChangeSet");
9
9
  // function getDeleteScript()
10
- function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo) {
10
+ function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo, usedTables) {
11
11
  if (result.find(x => x.title == table.pureName))
12
12
  return;
13
13
  const dependencies = allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName);
14
14
  for (const fk of dependencies) {
15
15
  const depTable = dbinfo.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
16
16
  const subFkPath = [...fkPath, fk];
17
- if (depTable && depTable.pureName != baseCmd.pureName) {
18
- processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo);
17
+ if (depTable && !usedTables.includes(depTable.pureName)) {
18
+ processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo, [
19
+ ...usedTables,
20
+ depTable.pureName,
21
+ ]);
19
22
  }
20
23
  const refCmd = {
21
24
  commandType: 'delete',
@@ -103,7 +106,7 @@ function getDeleteCascades(changeSet, dbinfo) {
103
106
  const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
104
107
  if (!table.primaryKey)
105
108
  continue;
106
- processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo);
109
+ processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo, [table.pureName]);
107
110
  // let resItem = result.find(x => x.title == baseCmd.pureName);
108
111
  // if (!resItem) {
109
112
  // resItem = {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.5-alpha.1",
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.4.5-alpha.1",
15
- "dbgate-filterparser": "^4.4.5-alpha.1"
14
+ "dbgate-sqltree": "^4.6.1",
15
+ "dbgate-filterparser": "^4.6.1"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.4.5-alpha.1",
18
+ "dbgate-types": "^4.6.1",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }