dbgate-datalib 4.3.4 → 4.4.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.
@@ -17,14 +17,14 @@ export declare class FreeTableGridDisplay extends GridDisplay {
17
17
  notNull: boolean;
18
18
  autoIncrement: boolean;
19
19
  dataType: string;
20
- precision: number;
21
- scale: number;
22
- length: number;
23
- computedExpression: string;
24
- isPersisted: boolean;
25
- isSparse: boolean;
26
- defaultValue: string;
27
- defaultConstraint: string;
20
+ precision?: number;
21
+ scale?: number;
22
+ length?: number;
23
+ computedExpression?: string;
24
+ isPersisted?: boolean;
25
+ isSparse?: boolean;
26
+ defaultValue?: string;
27
+ defaultConstraint?: string;
28
28
  }[];
29
29
  getDisplayColumn(col: ColumnInfo): {
30
30
  pureName: string;
@@ -37,13 +37,13 @@ export declare class FreeTableGridDisplay extends GridDisplay {
37
37
  notNull: boolean;
38
38
  autoIncrement: boolean;
39
39
  dataType: string;
40
- precision: number;
41
- scale: number;
42
- length: number;
43
- computedExpression: string;
44
- isPersisted: boolean;
45
- isSparse: boolean;
46
- defaultValue: string;
47
- defaultConstraint: string;
40
+ precision?: number;
41
+ scale?: number;
42
+ length?: number;
43
+ computedExpression?: string;
44
+ isPersisted?: boolean;
45
+ isSparse?: boolean;
46
+ defaultValue?: string;
47
+ defaultConstraint?: string;
48
48
  };
49
49
  }
@@ -15,7 +15,7 @@ export interface DisplayColumn {
15
15
  foreignKey?: ForeignKeyInfo;
16
16
  isExpandable?: boolean;
17
17
  isChecked?: boolean;
18
- hintColumnName?: string;
18
+ hintColumnNames?: string[];
19
19
  dataType?: string;
20
20
  filterType?: boolean;
21
21
  isStructured?: boolean;
@@ -4,10 +4,11 @@ import { EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
4
4
  import { GridConfig, GridCache } from './GridConfig';
5
5
  import { Select, Condition } from 'dbgate-sqltree';
6
6
  import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
7
+ import { DictionaryDescriptionFunc } from '.';
7
8
  export declare class TableFormViewDisplay extends FormViewDisplay {
8
9
  tableName: NamedObjectInfo;
9
10
  private gridDisplay;
10
- constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any);
11
+ constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any, getDictionaryDescription?: DictionaryDescriptionFunc);
11
12
  addDisplayColumns(columns: DisplayColumn[]): void;
12
13
  getPrimaryKeyEqualCondition(row?: any): Condition;
13
14
  getPrimaryKeyOperatorCondition(operator: any): Condition;
@@ -9,10 +9,10 @@ const dbgate_sqltree_1 = require("dbgate-sqltree");
9
9
  const TableGridDisplay_1 = require("./TableGridDisplay");
10
10
  const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
11
11
  class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
12
- constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion) {
12
+ constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription = null) {
13
13
  super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
14
14
  this.tableName = tableName;
15
- this.gridDisplay = new TableGridDisplay_1.TableGridDisplay(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion);
15
+ this.gridDisplay = new TableGridDisplay_1.TableGridDisplay(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription);
16
16
  this.gridDisplay.addAllExpandedColumnsToSelected = true;
17
17
  this.isLoadedCorrectly = this.gridDisplay.isLoadedCorrectly && !!this.driver;
18
18
  this.columns = [];
@@ -1,21 +1,29 @@
1
1
  import { GridDisplay, ChangeCacheFunc, DisplayColumn, DisplayedColumnInfo, ChangeConfigFunc } from './GridDisplay';
2
- import { TableInfo, EngineDriver, ColumnInfo, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
2
+ import { TableInfo, EngineDriver, ColumnInfo, NamedObjectInfo, DatabaseInfo, ForeignKeyInfo } from 'dbgate-types';
3
3
  import { GridConfig, GridCache } from './GridConfig';
4
4
  import { Select } from 'dbgate-sqltree';
5
+ export interface DictionaryDescription {
6
+ expression: string;
7
+ columns: string[];
8
+ delimiter: string;
9
+ }
10
+ export declare type DictionaryDescriptionFunc = (table: TableInfo) => DictionaryDescription;
5
11
  export declare class TableGridDisplay extends GridDisplay {
6
12
  tableName: NamedObjectInfo;
7
13
  displayOptions: any;
14
+ getDictionaryDescription: DictionaryDescriptionFunc;
8
15
  table: TableInfo;
9
16
  addAllExpandedColumnsToSelected: boolean;
10
17
  hintBaseColumns: DisplayColumn[];
11
- constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any);
18
+ constructor(tableName: NamedObjectInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, displayOptions: any, serverVersion: any, getDictionaryDescription?: DictionaryDescriptionFunc);
12
19
  findTable({ schemaName, pureName }: {
13
20
  schemaName?: any;
14
21
  pureName: any;
15
22
  }): TableInfo;
16
23
  getDisplayColumns(table: TableInfo, parentPath: string[]): {
17
24
  isChecked: boolean;
18
- hintColumnName: string;
25
+ hintColumnNames: string[];
26
+ hintColumnDelimiter: string;
19
27
  isExpandable: boolean;
20
28
  pureName: string;
21
29
  schemaName: string;
@@ -23,23 +31,24 @@ export declare class TableGridDisplay extends GridDisplay {
23
31
  uniqueName: string;
24
32
  uniquePath: string[];
25
33
  isPrimaryKey: boolean;
26
- foreignKey: import("dbgate-types").ForeignKeyInfo;
34
+ foreignKey: ForeignKeyInfo;
27
35
  pairingId?: string;
28
36
  columnName: string;
29
37
  notNull: boolean;
30
38
  autoIncrement: boolean;
31
39
  dataType: string;
32
- precision: number;
33
- scale: number;
34
- length: number;
35
- computedExpression: string;
36
- isPersisted: boolean;
37
- isSparse: boolean;
38
- defaultValue: string;
39
- defaultConstraint: string;
40
+ precision?: number;
41
+ scale?: number;
42
+ length?: number;
43
+ computedExpression?: string;
44
+ isPersisted?: boolean;
45
+ isSparse?: boolean;
46
+ defaultValue?: string;
47
+ defaultConstraint?: string;
40
48
  }[];
41
49
  addJoinsFromExpandedColumns(select: Select, columns: DisplayColumn[], parentAlias: string, columnSources: any): void;
42
50
  addReferenceToSelect(select: Select, parentAlias: string, column: DisplayColumn): void;
51
+ getFkDictionaryDescription(foreignKey: ForeignKeyInfo): DictionaryDescription;
43
52
  addHintsToSelect(select: Select): boolean;
44
53
  enrichExpandedColumns(list: DisplayColumn[]): DisplayColumn[];
45
54
  getExpandedColumns(column: DisplayColumn): DisplayColumn[];
@@ -54,20 +63,20 @@ export declare class TableGridDisplay extends GridDisplay {
54
63
  uniqueName: string;
55
64
  uniquePath: string[];
56
65
  isPrimaryKey: boolean;
57
- foreignKey: import("dbgate-types").ForeignKeyInfo;
66
+ foreignKey: ForeignKeyInfo;
58
67
  pairingId?: string;
59
68
  columnName: string;
60
69
  notNull: boolean;
61
70
  autoIncrement: boolean;
62
71
  dataType: string;
63
- precision: number;
64
- scale: number;
65
- length: number;
66
- computedExpression: string;
67
- isPersisted: boolean;
68
- isSparse: boolean;
69
- defaultValue: string;
70
- defaultConstraint: string;
72
+ precision?: number;
73
+ scale?: number;
74
+ length?: number;
75
+ computedExpression?: string;
76
+ isPersisted?: boolean;
77
+ isSparse?: boolean;
78
+ defaultValue?: string;
79
+ defaultConstraint?: string;
71
80
  };
72
81
  addAddedColumnsToSelect(select: Select, columns: DisplayColumn[], parentAlias: string, displayedColumnInfo: DisplayedColumnInfo): void;
73
82
  get hasReferences(): boolean;
@@ -4,10 +4,11 @@ exports.TableGridDisplay = void 0;
4
4
  const dbgate_tools_1 = require("dbgate-tools");
5
5
  const GridDisplay_1 = require("./GridDisplay");
6
6
  class TableGridDisplay extends GridDisplay_1.GridDisplay {
7
- constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion) {
7
+ constructor(tableName, driver, config, setConfig, cache, setCache, dbinfo, displayOptions, serverVersion, getDictionaryDescription = null) {
8
8
  super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
9
9
  this.tableName = tableName;
10
10
  this.displayOptions = displayOptions;
11
+ this.getDictionaryDescription = getDictionaryDescription;
11
12
  this.addAllExpandedColumnsToSelected = false;
12
13
  this.table = this.findTable(tableName);
13
14
  if (!this.table) {
@@ -38,7 +39,10 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
38
39
  }
39
40
  getDisplayColumns(table, parentPath) {
40
41
  var _a, _b;
41
- 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 => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col), hintColumnName: col.foreignKey ? `hint_${col.uniqueName}` : null, isExpandable: !!col.foreignKey })))) || []);
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
+ 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 }));
45
+ })) || []);
42
46
  }
43
47
  addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
44
48
  for (const column of columns) {
@@ -86,6 +90,18 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
86
90
  ];
87
91
  }
88
92
  }
93
+ getFkDictionaryDescription(foreignKey) {
94
+ if (!foreignKey)
95
+ return null;
96
+ const pureName = foreignKey.refTableName;
97
+ const schemaName = foreignKey.refSchemaName;
98
+ const table = this.findTable({ schemaName, pureName });
99
+ if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
100
+ const hintDescription = this.getDictionaryDescription(table);
101
+ return hintDescription;
102
+ }
103
+ return null;
104
+ }
89
105
  addHintsToSelect(select) {
90
106
  let res = false;
91
107
  const groupColumns = this.groupColumns;
@@ -96,17 +112,18 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
96
112
  }
97
113
  const table = this.getFkTarget(column);
98
114
  if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
99
- const hintColumn = table.columns.find(x => { var _a, _b; return (_b = (_a = x === null || x === void 0 ? void 0 : x.dataType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes('char'); });
100
- if (hintColumn) {
115
+ // const hintColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
116
+ const hintDescription = this.getDictionaryDescription(table);
117
+ if (hintDescription) {
101
118
  const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
102
119
  this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
103
120
  const childAlias = `${column.uniqueName}_ref`;
104
- select.columns.push({
121
+ select.columns.push(...hintDescription.columns.map(columnName => ({
105
122
  exprType: 'column',
106
- columnName: hintColumn.columnName,
107
- alias: `hint_${column.uniqueName}`,
123
+ columnName,
124
+ alias: `hint_${column.uniqueName}_${columnName}`,
108
125
  source: { alias: childAlias },
109
- });
126
+ })));
110
127
  res = true;
111
128
  }
112
129
  }
@@ -16,14 +16,14 @@ export declare class ViewGridDisplay extends GridDisplay {
16
16
  notNull: boolean;
17
17
  autoIncrement: boolean;
18
18
  dataType: string;
19
- precision: number;
20
- scale: number;
21
- length: number;
22
- computedExpression: string;
23
- isPersisted: boolean;
24
- isSparse: boolean;
25
- defaultValue: string;
26
- defaultConstraint: string;
19
+ precision?: number;
20
+ scale?: number;
21
+ length?: number;
22
+ computedExpression?: string;
23
+ isPersisted?: boolean;
24
+ isSparse?: boolean;
25
+ defaultValue?: string;
26
+ defaultConstraint?: string;
27
27
  }[];
28
28
  getDisplayColumn(view: ViewInfo, col: ColumnInfo): {
29
29
  pureName: string;
@@ -36,14 +36,14 @@ export declare class ViewGridDisplay extends GridDisplay {
36
36
  notNull: boolean;
37
37
  autoIncrement: boolean;
38
38
  dataType: string;
39
- precision: number;
40
- scale: number;
41
- length: number;
42
- computedExpression: string;
43
- isPersisted: boolean;
44
- isSparse: boolean;
45
- defaultValue: string;
46
- defaultConstraint: string;
39
+ precision?: number;
40
+ scale?: number;
41
+ length?: number;
42
+ computedExpression?: string;
43
+ isPersisted?: boolean;
44
+ isSparse?: boolean;
45
+ defaultValue?: string;
46
+ defaultConstraint?: string;
47
47
  };
48
48
  createSelect(options?: {}): import("dbgate-sqltree").Select;
49
49
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.3.4",
2
+ "version": "4.4.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.3.4",
15
- "dbgate-filterparser": "^4.3.4"
14
+ "dbgate-sqltree": "^4.4.1",
15
+ "dbgate-filterparser": "^4.4.1"
16
16
  },
17
17
  "devDependencies": {
18
- "dbgate-types": "^4.3.4",
18
+ "dbgate-types": "^4.4.1",
19
19
  "@types/node": "^13.7.0",
20
20
  "typescript": "^4.4.3"
21
21
  }