dbgate-datalib 5.3.4 → 5.4.0
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/lib/ChangeSet.d.ts +5 -1
- package/lib/ChangeSet.js +64 -19
- package/lib/CollectionGridDisplay.js +11 -6
- package/lib/CustomGridDisplay.d.ts +16 -0
- package/lib/CustomGridDisplay.js +52 -0
- package/lib/GridDisplay.d.ts +12 -5
- package/lib/GridDisplay.js +42 -23
- package/lib/JslGridDisplay.js +2 -1
- package/lib/PerspectiveCache.js +0 -1
- package/lib/PerspectiveConfig.d.ts +2 -2
- package/lib/PerspectiveDataLoader.d.ts +0 -1
- package/lib/PerspectiveDataLoader.js +34 -29
- package/lib/PerspectiveDataProvider.d.ts +0 -1
- package/lib/PerspectiveTreeNode.d.ts +6 -7
- package/lib/PerspectiveTreeNode.js +56 -47
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +5 -5
package/lib/ChangeSet.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface ChangeSetItem {
|
|
|
13
13
|
fields?: {
|
|
14
14
|
[column: string]: string;
|
|
15
15
|
};
|
|
16
|
+
insertIfNotExistsFields?: {
|
|
17
|
+
[column: string]: string;
|
|
18
|
+
};
|
|
16
19
|
}
|
|
17
20
|
export interface ChangeSetItemFields {
|
|
18
21
|
inserts: ChangeSetItem[];
|
|
@@ -48,5 +51,6 @@ export declare function revertChangeSetRowChanges(changeSet: ChangeSet, definiti
|
|
|
48
51
|
export declare function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
|
|
49
52
|
export declare function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo): any[];
|
|
50
53
|
export declare function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet;
|
|
51
|
-
export declare function changeSetInsertDocuments(changeSet: ChangeSet, documents: any[], name?: NamedObjectInfo): ChangeSet;
|
|
54
|
+
export declare function changeSetInsertDocuments(changeSet: ChangeSet, documents: any[], name?: NamedObjectInfo, insertIfNotExistsFieldNames?: string[]): ChangeSet;
|
|
52
55
|
export declare function changeSetContainsChanges(changeSet: ChangeSet): boolean;
|
|
56
|
+
export declare function changeSetChangedCount(changeSet: ChangeSet): number;
|
package/lib/ChangeSet.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.changeSetContainsChanges = exports.changeSetInsertDocuments = exports.changeSetInsertNewRow = exports.getChangeSetInsertedRows = exports.deleteChangeSetRows = exports.revertChangeSetRowChanges = exports.changeSetToSql = exports.extractChangeSetCondition = exports.batchUpdateChangeSet = exports.setChangeSetRowData = exports.setChangeSetValue = exports.findExistingChangeSetItem = exports.createChangeSet = void 0;
|
|
6
|
+
exports.changeSetChangedCount = exports.changeSetContainsChanges = exports.changeSetInsertDocuments = exports.changeSetInsertNewRow = exports.getChangeSetInsertedRows = exports.deleteChangeSetRows = exports.revertChangeSetRowChanges = exports.changeSetToSql = exports.extractChangeSetCondition = exports.batchUpdateChangeSet = exports.setChangeSetRowData = exports.setChangeSetValue = exports.findExistingChangeSetItem = exports.createChangeSet = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
function createChangeSet() {
|
|
9
9
|
return {
|
|
@@ -136,28 +136,33 @@ function batchUpdateChangeSet(changeSet, rowDefinitions, dataRows) {
|
|
|
136
136
|
return changeSet;
|
|
137
137
|
}
|
|
138
138
|
exports.batchUpdateChangeSet = batchUpdateChangeSet;
|
|
139
|
-
function extractFields(item, allowNulls = true) {
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
function extractFields(item, allowNulls = true, allowedDocumentColumns = []) {
|
|
140
|
+
const allFields = Object.assign({}, item.fields);
|
|
141
|
+
for (const docField in item.document || {}) {
|
|
142
|
+
if (allowedDocumentColumns.includes(docField)) {
|
|
143
|
+
allFields[docField] = item.document[docField];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lodash_1.default.keys(allFields)
|
|
147
|
+
.filter(targetColumn => allowNulls || allFields[targetColumn] != null)
|
|
142
148
|
.map(targetColumn => ({
|
|
143
149
|
targetColumn,
|
|
144
150
|
exprType: 'value',
|
|
145
|
-
value:
|
|
151
|
+
value: allFields[targetColumn],
|
|
146
152
|
}));
|
|
147
153
|
}
|
|
148
154
|
function changeSetInsertToSql(item, dbinfo = null) {
|
|
149
|
-
|
|
155
|
+
var _a, _b;
|
|
156
|
+
const table = (_a = dbinfo === null || dbinfo === void 0 ? void 0 : dbinfo.tables) === null || _a === void 0 ? void 0 : _a.find(x => x.schemaName == item.schemaName && x.pureName == item.pureName);
|
|
157
|
+
const fields = extractFields(item, false, (_b = table === null || table === void 0 ? void 0 : table.columns) === null || _b === void 0 ? void 0 : _b.map(x => x.columnName));
|
|
150
158
|
if (fields.length == 0)
|
|
151
159
|
return null;
|
|
152
160
|
let autoInc = false;
|
|
153
|
-
if (
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (autoIncCol && fields.find(x => x.targetColumn == autoIncCol.columnName)) {
|
|
159
|
-
autoInc = true;
|
|
160
|
-
}
|
|
161
|
+
if (table) {
|
|
162
|
+
const autoIncCol = table.columns.find(x => x.autoIncrement);
|
|
163
|
+
// console.log('autoIncCol', autoIncCol);
|
|
164
|
+
if (autoIncCol && fields.find(x => x.targetColumn == autoIncCol.columnName)) {
|
|
165
|
+
autoInc = true;
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
const targetTable = {
|
|
@@ -176,6 +181,9 @@ function changeSetInsertToSql(item, dbinfo = null) {
|
|
|
176
181
|
targetTable,
|
|
177
182
|
commandType: 'insert',
|
|
178
183
|
fields,
|
|
184
|
+
insertWhereNotExistsCondition: item.insertIfNotExistsFields
|
|
185
|
+
? compileSimpleChangeSetCondition(item.insertIfNotExistsFields)
|
|
186
|
+
: null,
|
|
179
187
|
},
|
|
180
188
|
autoInc
|
|
181
189
|
? {
|
|
@@ -224,7 +232,40 @@ function extractChangeSetCondition(item, alias) {
|
|
|
224
232
|
};
|
|
225
233
|
}
|
|
226
234
|
exports.extractChangeSetCondition = extractChangeSetCondition;
|
|
227
|
-
function
|
|
235
|
+
function compileSimpleChangeSetCondition(fields) {
|
|
236
|
+
function getColumnCondition(columnName) {
|
|
237
|
+
const value = fields[columnName];
|
|
238
|
+
const expr = {
|
|
239
|
+
exprType: 'column',
|
|
240
|
+
columnName,
|
|
241
|
+
};
|
|
242
|
+
if (value == null) {
|
|
243
|
+
return {
|
|
244
|
+
conditionType: 'isNull',
|
|
245
|
+
expr,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
return {
|
|
250
|
+
conditionType: 'binary',
|
|
251
|
+
operator: '=',
|
|
252
|
+
left: expr,
|
|
253
|
+
right: {
|
|
254
|
+
exprType: 'value',
|
|
255
|
+
value,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
conditionType: 'and',
|
|
262
|
+
conditions: lodash_1.default.keys(fields).map(columnName => getColumnCondition(columnName)),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function changeSetUpdateToSql(item, dbinfo = null) {
|
|
266
|
+
var _a, _b, _c;
|
|
267
|
+
const table = (_a = dbinfo === null || dbinfo === void 0 ? void 0 : dbinfo.tables) === null || _a === void 0 ? void 0 : _a.find(x => x.schemaName == item.schemaName && x.pureName == item.pureName);
|
|
268
|
+
const autoIncCol = (_b = table === null || table === void 0 ? void 0 : table.columns) === null || _b === void 0 ? void 0 : _b.find(x => x.autoIncrement);
|
|
228
269
|
return {
|
|
229
270
|
from: {
|
|
230
271
|
name: {
|
|
@@ -233,7 +274,7 @@ function changeSetUpdateToSql(item) {
|
|
|
233
274
|
},
|
|
234
275
|
},
|
|
235
276
|
commandType: 'update',
|
|
236
|
-
fields: extractFields(item),
|
|
277
|
+
fields: extractFields(item, true, (_c = table === null || table === void 0 ? void 0 : table.columns) === null || _c === void 0 ? void 0 : _c.map(x => x.columnName).filter(x => x != (autoIncCol === null || autoIncCol === void 0 ? void 0 : autoIncCol.columnName))),
|
|
237
278
|
where: extractChangeSetCondition(item),
|
|
238
279
|
};
|
|
239
280
|
}
|
|
@@ -252,7 +293,7 @@ function changeSetDeleteToSql(item) {
|
|
|
252
293
|
function changeSetToSql(changeSet, dbinfo) {
|
|
253
294
|
return lodash_1.default.compact(lodash_1.default.flatten([
|
|
254
295
|
...changeSet.inserts.map(item => changeSetInsertToSql(item, dbinfo)),
|
|
255
|
-
...changeSet.updates.map(changeSetUpdateToSql),
|
|
296
|
+
...changeSet.updates.map(item => changeSetUpdateToSql(item, dbinfo)),
|
|
256
297
|
...changeSet.deletes.map(changeSetDeleteToSql),
|
|
257
298
|
]));
|
|
258
299
|
}
|
|
@@ -327,11 +368,11 @@ function changeSetInsertNewRow(changeSet, name) {
|
|
|
327
368
|
] });
|
|
328
369
|
}
|
|
329
370
|
exports.changeSetInsertNewRow = changeSetInsertNewRow;
|
|
330
|
-
function changeSetInsertDocuments(changeSet, documents, name) {
|
|
371
|
+
function changeSetInsertDocuments(changeSet, documents, name, insertIfNotExistsFieldNames) {
|
|
331
372
|
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
|
332
373
|
return Object.assign(Object.assign({}, changeSet), { inserts: [
|
|
333
374
|
...changeSet.inserts,
|
|
334
|
-
...documents.map((doc, index) => (Object.assign(Object.assign({}, name), { insertedRowIndex: insertedRows.length + index, fields: doc }))),
|
|
375
|
+
...documents.map((doc, index) => (Object.assign(Object.assign({}, name), { insertedRowIndex: insertedRows.length + index, fields: doc, insertIfNotExistsFields: insertIfNotExistsFieldNames ? lodash_1.default.pick(doc, insertIfNotExistsFieldNames) : null }))),
|
|
335
376
|
] });
|
|
336
377
|
}
|
|
337
378
|
exports.changeSetInsertDocuments = changeSetInsertDocuments;
|
|
@@ -347,3 +388,7 @@ function changeSetContainsChanges(changeSet) {
|
|
|
347
388
|
((_a = changeSet.dataUpdateCommands) === null || _a === void 0 ? void 0 : _a.length) > 0);
|
|
348
389
|
}
|
|
349
390
|
exports.changeSetContainsChanges = changeSetContainsChanges;
|
|
391
|
+
function changeSetChangedCount(changeSet) {
|
|
392
|
+
return changeSet.deletes.length + changeSet.updates.length + changeSet.inserts.length;
|
|
393
|
+
}
|
|
394
|
+
exports.changeSetChangedCount = changeSetChangedCount;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.CollectionGridDisplay = exports.analyseCollectionDisplayColumns = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const GridDisplay_1 = require("./GridDisplay");
|
|
9
|
+
const dbgate_tools_1 = require("dbgate-tools");
|
|
9
10
|
function getObjectKeys(obj) {
|
|
10
11
|
if (lodash_1.default.isArray(obj)) {
|
|
11
12
|
return Object.keys(obj)
|
|
@@ -58,7 +59,7 @@ function getColumnsForObject(basePath, obj, res, display) {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
function getDisplayColumn(basePath, columnName, display) {
|
|
61
|
-
var _a, _b;
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
62
63
|
const uniquePath = [...basePath, columnName];
|
|
63
64
|
const uniqueName = uniquePath.join('.');
|
|
64
65
|
return {
|
|
@@ -68,9 +69,12 @@ function getDisplayColumn(basePath, columnName, display) {
|
|
|
68
69
|
uniquePath,
|
|
69
70
|
isStructured: true,
|
|
70
71
|
parentHeaderText: createHeaderText(basePath),
|
|
71
|
-
|
|
72
|
-
pureName: (
|
|
73
|
-
schemaName: (
|
|
72
|
+
filterBehaviour: (_b = (_a = display === null || display === void 0 ? void 0 : display.driver) === null || _a === void 0 ? void 0 : _a.getFilterBehaviour(null, dbgate_tools_1.standardFilterBehaviours)) !== null && _b !== void 0 ? _b : dbgate_tools_1.mongoFilterBehaviour,
|
|
73
|
+
pureName: (_c = display.collection) === null || _c === void 0 ? void 0 : _c.pureName,
|
|
74
|
+
schemaName: (_d = display.collection) === null || _d === void 0 ? void 0 : _d.schemaName,
|
|
75
|
+
isPartitionKey: !!((_f = (_e = display === null || display === void 0 ? void 0 : display.collection) === null || _e === void 0 ? void 0 : _e.partitionKey) === null || _f === void 0 ? void 0 : _f.find(x => x.columnName == uniqueName)),
|
|
76
|
+
isClusterKey: !!((_h = (_g = display === null || display === void 0 ? void 0 : display.collection) === null || _g === void 0 ? void 0 : _g.clusterKey) === null || _h === void 0 ? void 0 : _h.find(x => x.columnName == uniqueName)),
|
|
77
|
+
isUniqueKey: !!((_k = (_j = display === null || display === void 0 ? void 0 : display.collection) === null || _j === void 0 ? void 0 : _j.uniqueKey) === null || _k === void 0 ? void 0 : _k.find(x => x.columnName == uniqueName)),
|
|
74
78
|
};
|
|
75
79
|
}
|
|
76
80
|
function analyseCollectionDisplayColumns(rows, display) {
|
|
@@ -90,6 +94,7 @@ function analyseCollectionDisplayColumns(rows, display) {
|
|
|
90
94
|
exports.analyseCollectionDisplayColumns = analyseCollectionDisplayColumns;
|
|
91
95
|
class CollectionGridDisplay extends GridDisplay_1.GridDisplay {
|
|
92
96
|
constructor(collection, driver, config, setConfig, cache, setCache, loadedRows, changeSet, readOnly = false) {
|
|
97
|
+
var _a, _b;
|
|
93
98
|
super(config, setConfig, cache, setCache, driver);
|
|
94
99
|
this.collection = collection;
|
|
95
100
|
const changedDocs = lodash_1.default.compact(changeSet.updates.map(chs => chs.document));
|
|
@@ -97,10 +102,10 @@ class CollectionGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
97
102
|
this.columns = analyseCollectionDisplayColumns([...(loadedRows || []), ...changedDocs, ...insertedDocs], this);
|
|
98
103
|
this.filterable = true;
|
|
99
104
|
this.sortable = true;
|
|
100
|
-
this.editable = !readOnly;
|
|
105
|
+
this.editable = !readOnly && ((_a = collection === null || collection === void 0 ? void 0 : collection.uniqueKey) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
101
106
|
this.supportsReload = true;
|
|
102
107
|
this.isDynamicStructure = true;
|
|
103
|
-
this.changeSetKeyFields =
|
|
108
|
+
this.changeSetKeyFields = (_b = collection === null || collection === void 0 ? void 0 : collection.uniqueKey) === null || _b === void 0 ? void 0 : _b.map(x => x.columnName);
|
|
104
109
|
this.baseCollection = collection;
|
|
105
110
|
}
|
|
106
111
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
|
|
2
|
+
import type { EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
|
3
|
+
import { GridConfig, GridCache } from './GridConfig';
|
|
4
|
+
import { Select, Condition } from 'dbgate-sqltree';
|
|
5
|
+
export interface CustomGridColumn {
|
|
6
|
+
columnName: string;
|
|
7
|
+
columnLabel: string;
|
|
8
|
+
isPrimaryKey?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class CustomGridDisplay extends GridDisplay {
|
|
11
|
+
tableName: NamedObjectInfo;
|
|
12
|
+
additionalcondition: Condition;
|
|
13
|
+
customColumns: CustomGridColumn[];
|
|
14
|
+
constructor(tableName: NamedObjectInfo, columns: CustomGridColumn[], driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, serverVersion: any, isReadOnly?: boolean, additionalcondition?: Condition);
|
|
15
|
+
createSelect(options?: {}): Select;
|
|
16
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomGridDisplay = void 0;
|
|
4
|
+
const GridDisplay_1 = require("./GridDisplay");
|
|
5
|
+
class CustomGridDisplay extends GridDisplay_1.GridDisplay {
|
|
6
|
+
constructor(tableName, columns, driver, config, setConfig, cache, setCache, dbinfo, serverVersion, isReadOnly = false, additionalcondition = null) {
|
|
7
|
+
super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
|
|
8
|
+
this.tableName = tableName;
|
|
9
|
+
this.additionalcondition = additionalcondition;
|
|
10
|
+
this.customColumns = columns;
|
|
11
|
+
this.columns = columns.map(col => ({
|
|
12
|
+
columnName: col.columnName,
|
|
13
|
+
headerText: col.columnLabel,
|
|
14
|
+
uniqueName: col.columnName,
|
|
15
|
+
uniquePath: [col.columnName],
|
|
16
|
+
isPrimaryKey: col.isPrimaryKey,
|
|
17
|
+
isForeignKeyUnique: false,
|
|
18
|
+
schemaName: tableName.schemaName,
|
|
19
|
+
pureName: tableName.pureName,
|
|
20
|
+
}));
|
|
21
|
+
this.changeSetKeyFields = columns.filter(x => x.isPrimaryKey).map(x => x.columnName);
|
|
22
|
+
this.baseTable = Object.assign(Object.assign({}, tableName), { columns: this.columns.map(x => (Object.assign(Object.assign({}, tableName), { columnName: x.columnName, dataType: 'string' }))), foreignKeys: [] });
|
|
23
|
+
this.filterable = true;
|
|
24
|
+
this.sortable = true;
|
|
25
|
+
this.groupable = false;
|
|
26
|
+
this.editable = !isReadOnly;
|
|
27
|
+
this.supportsReload = true;
|
|
28
|
+
}
|
|
29
|
+
createSelect(options = {}) {
|
|
30
|
+
var _a;
|
|
31
|
+
const select = this.createSelectBase(this.tableName, [],
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
// this.columns.map(col => ({
|
|
34
|
+
// columnName: col.columnName,
|
|
35
|
+
// })),
|
|
36
|
+
options, (_a = this.customColumns.find(x => x.isPrimaryKey)) === null || _a === void 0 ? void 0 : _a.columnName);
|
|
37
|
+
select.selectAll = true;
|
|
38
|
+
if (this.additionalcondition) {
|
|
39
|
+
if (select.where) {
|
|
40
|
+
select.where = {
|
|
41
|
+
conditionType: 'and',
|
|
42
|
+
conditions: [select.where, this.additionalcondition],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
select.where = this.additionalcondition;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return select;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CustomGridDisplay = CustomGridDisplay;
|
package/lib/GridDisplay.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GridConfig, GridCache, GridConfigColumns, GroupFunc } from './GridConfig';
|
|
2
|
-
import type { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo, CollectionInfo, SqlDialect, ViewInfo } from 'dbgate-types';
|
|
2
|
+
import type { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo, CollectionInfo, SqlDialect, ViewInfo, FilterBehaviour } from 'dbgate-types';
|
|
3
3
|
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
|
4
4
|
import { Select, Condition } from 'dbgate-sqltree';
|
|
5
5
|
export interface DisplayColumn {
|
|
@@ -12,13 +12,16 @@ export interface DisplayColumn {
|
|
|
12
12
|
notNull?: boolean;
|
|
13
13
|
autoIncrement?: boolean;
|
|
14
14
|
isPrimaryKey?: boolean;
|
|
15
|
+
isPartitionKey?: boolean;
|
|
16
|
+
isClusterKey?: boolean;
|
|
17
|
+
isUniqueKey?: boolean;
|
|
15
18
|
foreignKey?: ForeignKeyInfo;
|
|
16
19
|
isForeignKeyUnique?: boolean;
|
|
17
20
|
isExpandable?: boolean;
|
|
18
21
|
isChecked?: boolean;
|
|
19
22
|
hintColumnNames?: string[];
|
|
20
23
|
dataType?: string;
|
|
21
|
-
|
|
24
|
+
filterBehaviour?: FilterBehaviour;
|
|
22
25
|
isStructured?: boolean;
|
|
23
26
|
}
|
|
24
27
|
export interface DisplayedColumnEx extends DisplayColumn {
|
|
@@ -56,7 +59,7 @@ export declare abstract class GridDisplay {
|
|
|
56
59
|
isLoadedCorrectly: boolean;
|
|
57
60
|
supportsReload: boolean;
|
|
58
61
|
isDynamicStructure: boolean;
|
|
59
|
-
|
|
62
|
+
filterBehaviourOverride: any;
|
|
60
63
|
setColumnVisibility(uniquePath: string[], isVisible: boolean): void;
|
|
61
64
|
addDynamicColumn(name: string): void;
|
|
62
65
|
focusColumns(uniqueNames: string[]): void;
|
|
@@ -67,7 +70,11 @@ export declare abstract class GridDisplay {
|
|
|
67
70
|
findColumn(uniqueName: string): DisplayColumn;
|
|
68
71
|
getFkTarget(column: DisplayColumn): TableInfo;
|
|
69
72
|
reload(): void;
|
|
70
|
-
includeInColumnSet(
|
|
73
|
+
includeInColumnSet(modifications: ({
|
|
74
|
+
field: keyof GridConfigColumns;
|
|
75
|
+
uniqueName: string;
|
|
76
|
+
isIncluded: boolean;
|
|
77
|
+
} | null)[]): void;
|
|
71
78
|
showAllColumns(): void;
|
|
72
79
|
hideAllColumns(): void;
|
|
73
80
|
get hiddenColumnIndexes(): number[];
|
|
@@ -105,7 +112,7 @@ export declare abstract class GridDisplay {
|
|
|
105
112
|
createSelect(options?: {}): Select;
|
|
106
113
|
processReferences(select: Select, displayedColumnInfo: DisplayedColumnInfo, options: any): void;
|
|
107
114
|
createColumnExpression(col: any, source: any, alias?: any): any;
|
|
108
|
-
createSelectBase(name: NamedObjectInfo, columns: ColumnInfo[], options: any): Select;
|
|
115
|
+
createSelectBase(name: NamedObjectInfo, columns: ColumnInfo[], options: any, defaultOrderColumnName?: string): Select;
|
|
109
116
|
getRowNumberOverSelect(select: Select, offset: number, count: number): Select;
|
|
110
117
|
getPageQuery(offset: number, count: number): Select;
|
|
111
118
|
getExportQuery(postprocessSelect?: any): string;
|
package/lib/GridDisplay.js
CHANGED
|
@@ -29,7 +29,7 @@ class GridDisplay {
|
|
|
29
29
|
this.isLoadedCorrectly = true;
|
|
30
30
|
this.supportsReload = false;
|
|
31
31
|
this.isDynamicStructure = false;
|
|
32
|
-
this.
|
|
32
|
+
this.filterBehaviourOverride = null;
|
|
33
33
|
this.dialect = ((driver === null || driver === void 0 ? void 0 : driver.dialectByVersion) && (driver === null || driver === void 0 ? void 0 : driver.dialectByVersion(serverVersion))) || (driver === null || driver === void 0 ? void 0 : driver.dialect);
|
|
34
34
|
}
|
|
35
35
|
get baseTableOrSimilar() {
|
|
@@ -44,16 +44,22 @@ class GridDisplay {
|
|
|
44
44
|
setColumnVisibility(uniquePath, isVisible) {
|
|
45
45
|
const uniqueName = uniquePath.join('.');
|
|
46
46
|
if (uniquePath.length == 1) {
|
|
47
|
-
this.includeInColumnSet(
|
|
47
|
+
this.includeInColumnSet([
|
|
48
|
+
{ field: 'hiddenColumns', uniqueName, isIncluded: !isVisible },
|
|
49
|
+
isVisible == false && this.isDynamicStructure && { field: 'addedColumns', uniqueName, isIncluded: false },
|
|
50
|
+
]);
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
50
|
-
this.includeInColumnSet('addedColumns', uniqueName, isVisible);
|
|
53
|
+
this.includeInColumnSet([{ field: 'addedColumns', uniqueName, isIncluded: isVisible }]);
|
|
51
54
|
if (!this.isDynamicStructure)
|
|
52
55
|
this.reload();
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
addDynamicColumn(name) {
|
|
56
|
-
this.includeInColumnSet(
|
|
59
|
+
this.includeInColumnSet([
|
|
60
|
+
{ field: 'addedColumns', uniqueName: name, isIncluded: true },
|
|
61
|
+
{ field: 'hiddenColumns', uniqueName: name, isIncluded: false },
|
|
62
|
+
]);
|
|
57
63
|
}
|
|
58
64
|
focusColumns(uniqueNames) {
|
|
59
65
|
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { focusedColumns: uniqueNames })));
|
|
@@ -80,14 +86,23 @@ class GridDisplay {
|
|
|
80
86
|
reload() {
|
|
81
87
|
this.setCache(reloadDataCacheFunc);
|
|
82
88
|
}
|
|
83
|
-
includeInColumnSet(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
includeInColumnSet(modifications) {
|
|
90
|
+
this.setConfig(cfg => {
|
|
91
|
+
let res = cfg;
|
|
92
|
+
for (const modification of modifications) {
|
|
93
|
+
if (!modification) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const { field, uniqueName, isIncluded } = modification;
|
|
97
|
+
if (isIncluded) {
|
|
98
|
+
res = Object.assign(Object.assign({}, res), { [field]: [...(cfg[field] || []), uniqueName] });
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
res = Object.assign(Object.assign({}, res), { [field]: (cfg[field] || []).filter(x => x != uniqueName) });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return res;
|
|
105
|
+
});
|
|
91
106
|
}
|
|
92
107
|
showAllColumns() {
|
|
93
108
|
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { hiddenColumns: [] })));
|
|
@@ -106,6 +121,7 @@ class GridDisplay {
|
|
|
106
121
|
: this.config.addedColumns.includes(column.uniqueName);
|
|
107
122
|
}
|
|
108
123
|
applyFilterOnSelect(select, displayedColumnInfo) {
|
|
124
|
+
var _a, _b;
|
|
109
125
|
const conditions = [];
|
|
110
126
|
for (const uniqueName in this.config.filters) {
|
|
111
127
|
const filter = this.config.filters[uniqueName];
|
|
@@ -115,7 +131,7 @@ class GridDisplay {
|
|
|
115
131
|
if (!column)
|
|
116
132
|
continue;
|
|
117
133
|
try {
|
|
118
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, (0,
|
|
134
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, (_b = (_a = this.driver) === null || _a === void 0 ? void 0 : _a.getFilterBehaviour(column.dataType, dbgate_tools_2.standardFilterBehaviours)) !== null && _b !== void 0 ? _b : (0, dbgate_tools_2.detectSqlFilterBehaviour)(column.dataType));
|
|
119
135
|
if (condition) {
|
|
120
136
|
conditions.push(lodash_1.default.cloneDeepWith(condition, (expr) => {
|
|
121
137
|
if (expr.exprType == 'placeholder') {
|
|
@@ -141,7 +157,7 @@ class GridDisplay {
|
|
|
141
157
|
};
|
|
142
158
|
for (const column of this.baseTableOrView.columns) {
|
|
143
159
|
try {
|
|
144
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)(this.config.multiColumnFilter, (0,
|
|
160
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(this.config.multiColumnFilter, (0, dbgate_tools_2.detectSqlFilterBehaviour)(column.dataType));
|
|
145
161
|
if (condition) {
|
|
146
162
|
orCondition.conditions.push(lodash_1.default.cloneDeepWith(condition, (expr) => {
|
|
147
163
|
if (expr.exprType == 'placeholder') {
|
|
@@ -258,7 +274,9 @@ class GridDisplay {
|
|
|
258
274
|
return this.config.expandedColumns.includes(uniqueName);
|
|
259
275
|
}
|
|
260
276
|
toggleExpandedColumn(uniqueName, value) {
|
|
261
|
-
this.includeInColumnSet(
|
|
277
|
+
this.includeInColumnSet([
|
|
278
|
+
{ field: 'expandedColumns', uniqueName, isIncluded: value == null ? !this.isExpandedColumn(uniqueName) : value },
|
|
279
|
+
]);
|
|
262
280
|
}
|
|
263
281
|
getFilter(uniqueName) {
|
|
264
282
|
return this.config.filters[uniqueName];
|
|
@@ -389,11 +407,11 @@ class GridDisplay {
|
|
|
389
407
|
}
|
|
390
408
|
return Object.assign({ exprType: 'column', alias: alias || col.columnName, source }, col);
|
|
391
409
|
}
|
|
392
|
-
createSelectBase(name, columns, options) {
|
|
393
|
-
var _a;
|
|
410
|
+
createSelectBase(name, columns, options, defaultOrderColumnName) {
|
|
411
|
+
var _a, _b;
|
|
394
412
|
if (!columns)
|
|
395
413
|
return null;
|
|
396
|
-
const orderColumnName = columns[0].columnName;
|
|
414
|
+
const orderColumnName = defaultOrderColumnName !== null && defaultOrderColumnName !== void 0 ? defaultOrderColumnName : (_a = columns[0]) === null || _a === void 0 ? void 0 : _a.columnName;
|
|
397
415
|
const select = {
|
|
398
416
|
commandType: 'select',
|
|
399
417
|
from: {
|
|
@@ -401,7 +419,7 @@ class GridDisplay {
|
|
|
401
419
|
alias: 'basetbl',
|
|
402
420
|
},
|
|
403
421
|
columns: columns.map(col => this.createColumnExpression(col, { alias: 'basetbl' })),
|
|
404
|
-
orderBy: ((
|
|
422
|
+
orderBy: ((_b = this.driver) === null || _b === void 0 ? void 0 : _b.requiresDefaultSortCriteria)
|
|
405
423
|
? [
|
|
406
424
|
{
|
|
407
425
|
exprType: 'column',
|
|
@@ -554,13 +572,14 @@ class GridDisplay {
|
|
|
554
572
|
alias: 'count',
|
|
555
573
|
},
|
|
556
574
|
];
|
|
575
|
+
select.selectAll = false;
|
|
557
576
|
}
|
|
558
577
|
return select;
|
|
559
578
|
// const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
|
560
579
|
// return sql;
|
|
561
580
|
}
|
|
562
581
|
compileJslFilters() {
|
|
563
|
-
var _a;
|
|
582
|
+
var _a, _b, _c;
|
|
564
583
|
const filters = this.config && this.config.filters;
|
|
565
584
|
if (!filters)
|
|
566
585
|
return null;
|
|
@@ -569,9 +588,9 @@ class GridDisplay {
|
|
|
569
588
|
const column = this.isDynamicStructure ? null : this.columns.find(x => x.columnName == name);
|
|
570
589
|
if (!this.isDynamicStructure && !column)
|
|
571
590
|
continue;
|
|
572
|
-
const
|
|
591
|
+
const filterBehaviour = (_c = (_a = this.filterBehaviourOverride) !== null && _a !== void 0 ? _a : (_b = this.driver) === null || _b === void 0 ? void 0 : _b.getFilterBehaviour(column.dataType, dbgate_tools_2.standardFilterBehaviours)) !== null && _c !== void 0 ? _c : (0, dbgate_tools_2.detectSqlFilterBehaviour)(column.dataType);
|
|
573
592
|
try {
|
|
574
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)(filters[name],
|
|
593
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filters[name], filterBehaviour);
|
|
575
594
|
const replaced = lodash_1.default.cloneDeepWith(condition, (expr) => {
|
|
576
595
|
if (expr.exprType == 'placeholder')
|
|
577
596
|
return {
|
|
@@ -586,7 +605,7 @@ class GridDisplay {
|
|
|
586
605
|
}
|
|
587
606
|
}
|
|
588
607
|
if (this.config.multiColumnFilter) {
|
|
589
|
-
const placeholderCondition = (0, dbgate_filterparser_1.parseFilter)(this.config.multiColumnFilter,
|
|
608
|
+
const placeholderCondition = (0, dbgate_filterparser_1.parseFilter)(this.config.multiColumnFilter, dbgate_tools_2.stringFilterBehaviour);
|
|
590
609
|
if (placeholderCondition) {
|
|
591
610
|
conditions.push({
|
|
592
611
|
conditionType: 'anyColumnPass',
|
package/lib/JslGridDisplay.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.JslGridDisplay = void 0;
|
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const GridDisplay_1 = require("./GridDisplay");
|
|
9
9
|
const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
|
|
10
|
+
const dbgate_tools_1 = require("dbgate-tools");
|
|
10
11
|
class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
11
12
|
constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload, editable = false) {
|
|
12
13
|
var _a;
|
|
@@ -15,7 +16,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
15
16
|
this.sortable = true;
|
|
16
17
|
this.supportsReload = supportsReload;
|
|
17
18
|
this.isDynamicStructure = isDynamicStructure;
|
|
18
|
-
this.
|
|
19
|
+
this.filterBehaviourOverride = dbgate_tools_1.evalFilterBehaviour;
|
|
19
20
|
this.editable = editable;
|
|
20
21
|
this.editableStructure = editable ? structure : null;
|
|
21
22
|
if (structure === null || structure === void 0 ? void 0 : structure.columns) {
|
package/lib/PerspectiveCache.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatabaseInfo, ForeignKeyInfo } from 'dbgate-types';
|
|
1
|
+
import type { DatabaseInfo, FilterBehaviour, ForeignKeyInfo } from 'dbgate-types';
|
|
2
2
|
export type PerspectiveDatabaseEngineType = 'sqldb' | 'docdb';
|
|
3
3
|
export interface PerspectiveDatabaseConfig {
|
|
4
4
|
conid: string;
|
|
@@ -20,7 +20,7 @@ export interface PerspectiveCustomJoinConfig {
|
|
|
20
20
|
}
|
|
21
21
|
export interface PerspectiveFilterColumnInfo {
|
|
22
22
|
columnName: string;
|
|
23
|
-
|
|
23
|
+
filterBehaviour: FilterBehaviour;
|
|
24
24
|
pureName: string;
|
|
25
25
|
schemaName: string;
|
|
26
26
|
foreignKey: ForeignKeyInfo;
|
|
@@ -4,7 +4,6 @@ export declare class PerspectiveDataLoader {
|
|
|
4
4
|
apiCall: any;
|
|
5
5
|
constructor(apiCall: any);
|
|
6
6
|
buildSqlCondition(props: PerspectiveDataLoadProps): Condition;
|
|
7
|
-
buildMongoCondition(props: PerspectiveDataLoadProps): {};
|
|
8
7
|
loadGroupingSqlDb(props: PerspectiveDataLoadProps): Promise<any>;
|
|
9
8
|
loadGroupingDocDb(props: PerspectiveDataLoadProps): Promise<any>;
|
|
10
9
|
loadGrouping(props: PerspectiveDataLoadProps): Promise<any>;
|
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PerspectiveDataLoader = void 0;
|
|
16
16
|
const debug_1 = __importDefault(require("debug"));
|
|
17
|
-
const zipObject_1 = __importDefault(require("lodash/zipObject"));
|
|
18
17
|
const mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
19
18
|
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
20
19
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
@@ -61,19 +60,6 @@ class PerspectiveDataLoader {
|
|
|
61
60
|
}
|
|
62
61
|
: null;
|
|
63
62
|
}
|
|
64
|
-
buildMongoCondition(props) {
|
|
65
|
-
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, mongoCondition } = props;
|
|
66
|
-
const conditions = [];
|
|
67
|
-
if (mongoCondition) {
|
|
68
|
-
conditions.push(mongoCondition);
|
|
69
|
-
}
|
|
70
|
-
if ((bindingColumns === null || bindingColumns === void 0 ? void 0 : bindingColumns.length) == 1) {
|
|
71
|
-
conditions.push({
|
|
72
|
-
[bindingColumns[0]]: { $in: bindingValues.map(x => x[0]) },
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return conditions.length == 1 ? conditions[0] : conditions.length > 0 ? { $and: conditions } : null;
|
|
76
|
-
}
|
|
77
63
|
loadGroupingSqlDb(props) {
|
|
78
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
65
|
const { schemaName, pureName, bindingColumns } = props;
|
|
@@ -122,15 +108,28 @@ class PerspectiveDataLoader {
|
|
|
122
108
|
loadGroupingDocDb(props) {
|
|
123
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
110
|
const { schemaName, pureName, bindingColumns } = props;
|
|
125
|
-
const aggregate =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
const aggregate = {
|
|
112
|
+
condition: this.buildSqlCondition(props),
|
|
113
|
+
groupByColumns: bindingColumns,
|
|
114
|
+
aggregateColumns: [
|
|
115
|
+
{
|
|
116
|
+
alias: 'pergrpsize',
|
|
117
|
+
aggregateFunction: 'count',
|
|
131
118
|
},
|
|
132
|
-
|
|
133
|
-
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
// const aggregate = [
|
|
122
|
+
// { $match: this.buildMongoCondition(props) },
|
|
123
|
+
// {
|
|
124
|
+
// $group: {
|
|
125
|
+
// _id: _zipObject(
|
|
126
|
+
// bindingColumns,
|
|
127
|
+
// bindingColumns.map(col => '$' + col)
|
|
128
|
+
// ),
|
|
129
|
+
// count: { $sum: 1 },
|
|
130
|
+
// },
|
|
131
|
+
// },
|
|
132
|
+
// ];
|
|
134
133
|
if (dbg === null || dbg === void 0 ? void 0 : dbg.enabled) {
|
|
135
134
|
dbg(`LOAD COUNTS, table=${props.pureName}, columns=${bindingColumns === null || bindingColumns === void 0 ? void 0 : bindingColumns.join(',')}`);
|
|
136
135
|
}
|
|
@@ -144,7 +143,7 @@ class PerspectiveDataLoader {
|
|
|
144
143
|
});
|
|
145
144
|
if (response.errorMessage)
|
|
146
145
|
return response;
|
|
147
|
-
return response.rows.map(row => (Object.assign(Object.assign({}, row
|
|
146
|
+
return response.rows.map(row => (Object.assign(Object.assign({}, row), { _perspective_group_size_: parseInt(row.pergrpsize) })));
|
|
148
147
|
});
|
|
149
148
|
}
|
|
150
149
|
loadGrouping(props) {
|
|
@@ -209,13 +208,19 @@ class PerspectiveDataLoader {
|
|
|
209
208
|
const { pureName } = props;
|
|
210
209
|
const res = {
|
|
211
210
|
pureName,
|
|
212
|
-
condition: this.
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
condition: this.buildSqlCondition(props),
|
|
212
|
+
sort: useSort && ((_a = props.orderBy) === null || _a === void 0 ? void 0 : _a.length) > 0
|
|
213
|
+
? props.orderBy.map(x => (Object.assign(Object.assign({}, x), { direction: x.order })))
|
|
214
|
+
: undefined,
|
|
215
|
+
skip: (_b = props.range) === null || _b === void 0 ? void 0 : _b.offset,
|
|
216
|
+
limit: (_c = props.range) === null || _c === void 0 ? void 0 : _c.limit,
|
|
215
217
|
};
|
|
216
|
-
if (useSort &&
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
// if (useSort && props.orderBy?.length > 0) {
|
|
219
|
+
// res.sort = _zipObject(
|
|
220
|
+
// props.orderBy.map(col => col.columnName),
|
|
221
|
+
// props.orderBy.map(col => (col.order == 'DESC' ? -1 : 1))
|
|
222
|
+
// );
|
|
223
|
+
// }
|
|
219
224
|
return res;
|
|
220
225
|
}
|
|
221
226
|
loadDataDocDb(props) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { CollectionInfo, ColumnInfo, DatabaseInfo, ForeignKeyInfo, NamedObjectInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
|
1
|
+
import type { CollectionInfo, ColumnInfo, DatabaseInfo, FilterBehaviour, ForeignKeyInfo, NamedObjectInfo, TableInfo, ViewInfo } from 'dbgate-types';
|
|
2
2
|
import { ChangePerspectiveConfigFunc, MultipleDatabaseInfo, PerspectiveConfig, PerspectiveCustomJoinConfig, PerspectiveDatabaseConfig, PerspectiveDatabaseEngineType, PerspectiveFilterColumnInfo, PerspectiveNodeConfig, PerspectiveReferenceConfig } from './PerspectiveConfig';
|
|
3
3
|
import { PerspectiveDataLoadProps, PerspectiveDataProvider } from './PerspectiveDataProvider';
|
|
4
|
-
import { FilterType } from 'dbgate-filterparser/lib/types';
|
|
5
4
|
import { Condition } from 'dbgate-sqltree';
|
|
6
5
|
import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern';
|
|
7
6
|
export interface PerspectiveDataLoadPropsWithNode {
|
|
@@ -53,7 +52,7 @@ export declare abstract class PerspectiveTreeNode {
|
|
|
53
52
|
get isSecondaryChecked(): boolean;
|
|
54
53
|
get secondaryCheckable(): boolean;
|
|
55
54
|
get columnTitle(): any;
|
|
56
|
-
get
|
|
55
|
+
get filterBehaviour(): FilterBehaviour;
|
|
57
56
|
get columnName(): any;
|
|
58
57
|
get customJoinConfig(): PerspectiveCustomJoinConfig;
|
|
59
58
|
get db(): DatabaseInfo;
|
|
@@ -73,10 +72,10 @@ export declare abstract class PerspectiveTreeNode {
|
|
|
73
72
|
includeInNodeSet(field: 'expandedColumns' | 'uncheckedColumns' | 'checkedColumns', isIncluded: boolean): void;
|
|
74
73
|
getFilter(): string;
|
|
75
74
|
getDataLoadColumns(): any[];
|
|
75
|
+
getMutliColumnCondition(source: any): Condition;
|
|
76
76
|
getMutliColumnSqlCondition(source: any): Condition;
|
|
77
|
-
|
|
77
|
+
getMutliColumnNoSqlCondition(): Condition;
|
|
78
78
|
getChildrenSqlCondition(source?: any): Condition;
|
|
79
|
-
getChildrenMongoCondition(source?: any): {};
|
|
80
79
|
getOrderBy(table: TableInfo | ViewInfo | CollectionInfo): PerspectiveDataLoadProps['orderBy'];
|
|
81
80
|
getBaseTables(): any[];
|
|
82
81
|
getBaseTableFromThis(): TableInfo | ViewInfo | CollectionInfo;
|
|
@@ -112,7 +111,7 @@ export declare class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|
|
112
111
|
get title(): string;
|
|
113
112
|
get isExpandable(): boolean;
|
|
114
113
|
get isSortable(): boolean;
|
|
115
|
-
get
|
|
114
|
+
get filterBehaviour(): FilterBehaviour;
|
|
116
115
|
get isCircular(): boolean;
|
|
117
116
|
get isSecondaryChecked(): boolean;
|
|
118
117
|
get isChecked(): boolean;
|
|
@@ -151,7 +150,7 @@ export declare class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|
|
151
150
|
get title(): string;
|
|
152
151
|
get isExpandable(): boolean;
|
|
153
152
|
get isSortable(): boolean;
|
|
154
|
-
get
|
|
153
|
+
get filterBehaviour(): FilterBehaviour;
|
|
155
154
|
get preloadedLevelData(): boolean;
|
|
156
155
|
generatePatternChildNodes(): PerspectivePatternColumnNode[];
|
|
157
156
|
hasCheckedJoinChild(): boolean;
|
|
@@ -166,8 +166,8 @@ class PerspectiveTreeNode {
|
|
|
166
166
|
get columnTitle() {
|
|
167
167
|
return this.title;
|
|
168
168
|
}
|
|
169
|
-
get
|
|
170
|
-
return
|
|
169
|
+
get filterBehaviour() {
|
|
170
|
+
return dbgate_tools_1.stringFilterBehaviour;
|
|
171
171
|
}
|
|
172
172
|
get columnName() {
|
|
173
173
|
return null;
|
|
@@ -273,6 +273,21 @@ class PerspectiveTreeNode {
|
|
|
273
273
|
.map(x => x.columnName),
|
|
274
274
|
]));
|
|
275
275
|
}
|
|
276
|
+
getMutliColumnCondition(source) {
|
|
277
|
+
var _a;
|
|
278
|
+
if (!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.multiColumnFilter))
|
|
279
|
+
return null;
|
|
280
|
+
const base = this.getBaseTableFromThis();
|
|
281
|
+
if (!base)
|
|
282
|
+
return null;
|
|
283
|
+
const isDocDb = (0, dbgate_tools_1.isCollectionInfo)(base);
|
|
284
|
+
if (isDocDb) {
|
|
285
|
+
return this.getMutliColumnNoSqlCondition();
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
return this.getMutliColumnSqlCondition(source);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
276
291
|
getMutliColumnSqlCondition(source) {
|
|
277
292
|
var _a, _b;
|
|
278
293
|
if (!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.multiColumnFilter))
|
|
@@ -281,7 +296,7 @@ class PerspectiveTreeNode {
|
|
|
281
296
|
if (!base)
|
|
282
297
|
return null;
|
|
283
298
|
try {
|
|
284
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)((_b = this.nodeConfig) === null || _b === void 0 ? void 0 : _b.multiColumnFilter,
|
|
299
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)((_b = this.nodeConfig) === null || _b === void 0 ? void 0 : _b.multiColumnFilter, dbgate_tools_1.stringFilterBehaviour);
|
|
285
300
|
if (condition) {
|
|
286
301
|
const orCondition = {
|
|
287
302
|
conditionType: 'or',
|
|
@@ -308,34 +323,39 @@ class PerspectiveTreeNode {
|
|
|
308
323
|
}
|
|
309
324
|
return null;
|
|
310
325
|
}
|
|
311
|
-
|
|
326
|
+
getMutliColumnNoSqlCondition() {
|
|
312
327
|
var _a, _b, _c, _d;
|
|
313
328
|
if (!((_a = this.nodeConfig) === null || _a === void 0 ? void 0 : _a.multiColumnFilter))
|
|
314
329
|
return null;
|
|
315
330
|
const pattern = (_c = (_b = this.dataProvider) === null || _b === void 0 ? void 0 : _b.dataPatterns) === null || _c === void 0 ? void 0 : _c[this.designerId];
|
|
316
331
|
if (!pattern)
|
|
317
332
|
return null;
|
|
318
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)((_d = this.nodeConfig) === null || _d === void 0 ? void 0 : _d.multiColumnFilter,
|
|
333
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)((_d = this.nodeConfig) === null || _d === void 0 ? void 0 : _d.multiColumnFilter, dbgate_tools_1.mongoFilterBehaviour);
|
|
319
334
|
if (!condition)
|
|
320
335
|
return null;
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
336
|
+
const orCondition = {
|
|
337
|
+
conditionType: 'or',
|
|
338
|
+
conditions: [],
|
|
339
|
+
};
|
|
340
|
+
for (const column of pattern.columns || []) {
|
|
341
|
+
orCondition.conditions.push((0, cloneDeepWith_1.default)(condition, (expr) => {
|
|
342
|
+
if (expr.exprType == 'placeholder') {
|
|
324
343
|
return {
|
|
325
|
-
|
|
344
|
+
exprType: 'column',
|
|
345
|
+
columnName: column.name,
|
|
326
346
|
};
|
|
327
347
|
}
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
if (orCondition.conditions.length > 0) {
|
|
351
|
+
return orCondition;
|
|
352
|
+
}
|
|
333
353
|
}
|
|
334
354
|
getChildrenSqlCondition(source = null) {
|
|
335
355
|
const conditions = (0, compact_1.default)([
|
|
336
356
|
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
|
337
357
|
...this.buildParentFilterConditions(),
|
|
338
|
-
this.
|
|
358
|
+
this.getMutliColumnCondition(source),
|
|
339
359
|
]);
|
|
340
360
|
if (conditions.length == 0) {
|
|
341
361
|
return null;
|
|
@@ -348,19 +368,6 @@ class PerspectiveTreeNode {
|
|
|
348
368
|
conditions,
|
|
349
369
|
};
|
|
350
370
|
}
|
|
351
|
-
getChildrenMongoCondition(source = null) {
|
|
352
|
-
const conditions = (0, compact_1.default)([
|
|
353
|
-
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
|
354
|
-
this.getMutliColumnMongoCondition(),
|
|
355
|
-
]);
|
|
356
|
-
if (conditions.length == 0) {
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
if (conditions.length == 1) {
|
|
360
|
-
return conditions[0];
|
|
361
|
-
}
|
|
362
|
-
return { $and: conditions };
|
|
363
|
-
}
|
|
364
371
|
getOrderBy(table) {
|
|
365
372
|
var _a;
|
|
366
373
|
const res = (0, compact_1.default)(this.childNodes.map(node => {
|
|
@@ -381,6 +388,9 @@ class PerspectiveTreeNode {
|
|
|
381
388
|
}));
|
|
382
389
|
if (pkColumns)
|
|
383
390
|
return pkColumns;
|
|
391
|
+
const uqColumns = table === null || table === void 0 ? void 0 : table.uniqueKey;
|
|
392
|
+
if ((uqColumns === null || uqColumns === void 0 ? void 0 : uqColumns.length) >= 1)
|
|
393
|
+
return uqColumns.map(x => ({ columnName: x.columnName, order: 'ASC' }));
|
|
384
394
|
const columns = table === null || table === void 0 ? void 0 : table.columns;
|
|
385
395
|
if (columns)
|
|
386
396
|
return [{ columnName: columns[0].columnName, order: 'ASC' }];
|
|
@@ -613,8 +623,8 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|
|
613
623
|
get isSortable() {
|
|
614
624
|
return true;
|
|
615
625
|
}
|
|
616
|
-
get
|
|
617
|
-
return (0,
|
|
626
|
+
get filterBehaviour() {
|
|
627
|
+
return (0, dbgate_tools_1.detectSqlFilterBehaviour)(this.column.dataType);
|
|
618
628
|
}
|
|
619
629
|
get isCircular() {
|
|
620
630
|
var _a, _b;
|
|
@@ -655,7 +665,7 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|
|
655
665
|
get filterInfo() {
|
|
656
666
|
return {
|
|
657
667
|
columnName: this.columnName,
|
|
658
|
-
|
|
668
|
+
filterBehaviour: this.filterBehaviour,
|
|
659
669
|
pureName: this.column.pureName,
|
|
660
670
|
schemaName: this.column.schemaName,
|
|
661
671
|
foreignKey: this.foreignKey,
|
|
@@ -665,7 +675,7 @@ class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|
|
665
675
|
const filter = this.getFilter();
|
|
666
676
|
if (!filter)
|
|
667
677
|
return null;
|
|
668
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, this.
|
|
678
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, this.filterBehaviour);
|
|
669
679
|
if (!condition)
|
|
670
680
|
return null;
|
|
671
681
|
return (0, cloneDeepWith_1.default)(condition, (expr) => {
|
|
@@ -807,10 +817,10 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|
|
807
817
|
get isSortable() {
|
|
808
818
|
return !this.isChildColumn;
|
|
809
819
|
}
|
|
810
|
-
get
|
|
820
|
+
get filterBehaviour() {
|
|
811
821
|
if (this.tableColumn)
|
|
812
|
-
return (0,
|
|
813
|
-
return
|
|
822
|
+
return (0, dbgate_tools_1.detectSqlFilterBehaviour)(this.tableColumn.dataType);
|
|
823
|
+
return dbgate_tools_1.mongoFilterBehaviour;
|
|
814
824
|
}
|
|
815
825
|
get preloadedLevelData() {
|
|
816
826
|
return true;
|
|
@@ -907,7 +917,7 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|
|
907
917
|
}
|
|
908
918
|
return {
|
|
909
919
|
columnName: this.columnName,
|
|
910
|
-
|
|
920
|
+
filterBehaviour: this.filterBehaviour,
|
|
911
921
|
pureName: this.table.pureName,
|
|
912
922
|
schemaName: this.table.schemaName,
|
|
913
923
|
foreignKey: this.foreignKey,
|
|
@@ -917,7 +927,7 @@ class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|
|
917
927
|
const filter = this.getFilter();
|
|
918
928
|
if (!filter)
|
|
919
929
|
return null;
|
|
920
|
-
const condition = (0, dbgate_filterparser_1.parseFilter)(filter,
|
|
930
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, dbgate_tools_1.mongoFilterBehaviour);
|
|
921
931
|
if (!condition)
|
|
922
932
|
return null;
|
|
923
933
|
return (0, cloneDeepWith_1.default)(condition, expr => {
|
|
@@ -940,17 +950,16 @@ class PerspectiveTableNode extends PerspectiveTreeNode {
|
|
|
940
950
|
return (0, dbgate_tools_1.isCollectionInfo)(this.table) ? 'docdb' : 'sqldb';
|
|
941
951
|
}
|
|
942
952
|
getNodeLoadProps(parentRows) {
|
|
943
|
-
const
|
|
953
|
+
const isDocDb = (0, dbgate_tools_1.isCollectionInfo)(this.table);
|
|
944
954
|
return {
|
|
945
955
|
schemaName: this.table.schemaName,
|
|
946
956
|
pureName: this.table.pureName,
|
|
947
957
|
dataColumns: this.getDataLoadColumns(),
|
|
948
|
-
allColumns:
|
|
958
|
+
allColumns: isDocDb,
|
|
949
959
|
databaseConfig: this.databaseConfig,
|
|
950
960
|
orderBy: this.getOrderBy(this.table),
|
|
951
|
-
sqlCondition:
|
|
952
|
-
|
|
953
|
-
engineType: isMongo ? 'docdb' : 'sqldb',
|
|
961
|
+
sqlCondition: this.getChildrenSqlCondition(),
|
|
962
|
+
engineType: isDocDb ? 'docdb' : 'sqldb',
|
|
954
963
|
};
|
|
955
964
|
}
|
|
956
965
|
get codeName() {
|
|
@@ -1105,7 +1114,7 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
|
|
|
1105
1114
|
// console.log('CUSTOM JOIN', this.customJoin);
|
|
1106
1115
|
// console.log('PARENT ROWS', parentRows);
|
|
1107
1116
|
// console.log('this.getDataLoadColumns()', this.getDataLoadColumns());
|
|
1108
|
-
const
|
|
1117
|
+
const isDocDb = (0, dbgate_tools_1.isCollectionInfo)(this.table);
|
|
1109
1118
|
// const bindingValues = [];
|
|
1110
1119
|
// for (const row of parentRows) {
|
|
1111
1120
|
// const rowBindingValueArrays = [];
|
|
@@ -1153,12 +1162,12 @@ class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
|
|
|
1153
1162
|
bindingColumns: this.getParentMatchColumns(),
|
|
1154
1163
|
bindingValues: (0, uniqBy_1.default)(bindingValues, x => JSON.stringify(x)),
|
|
1155
1164
|
dataColumns: this.getDataLoadColumns(),
|
|
1156
|
-
allColumns:
|
|
1165
|
+
allColumns: isDocDb,
|
|
1157
1166
|
databaseConfig: this.databaseConfig,
|
|
1158
1167
|
orderBy: this.getOrderBy(this.table),
|
|
1159
|
-
sqlCondition:
|
|
1160
|
-
mongoCondition: isMongo ? this.getChildrenMongoCondition() : null,
|
|
1161
|
-
engineType:
|
|
1168
|
+
sqlCondition: this.getChildrenSqlCondition(),
|
|
1169
|
+
// mongoCondition: isMongo ? this.getChildrenMongoCondition() : null,
|
|
1170
|
+
engineType: isDocDb ? 'docdb' : 'sqldb',
|
|
1162
1171
|
};
|
|
1163
1172
|
}
|
|
1164
1173
|
// get title() {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -37,3 +37,4 @@ __exportStar(require("./perspectiveTools"), exports);
|
|
|
37
37
|
__exportStar(require("./DataDuplicator"), exports);
|
|
38
38
|
__exportStar(require("./FreeTableGridDisplay"), exports);
|
|
39
39
|
__exportStar(require("./FreeTableModel"), exports);
|
|
40
|
+
__exportStar(require("./CustomGridDisplay"), exports);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.
|
|
2
|
+
"version": "5.4.0",
|
|
3
3
|
"name": "dbgate-datalib",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"lib"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"dbgate-sqltree": "^5.
|
|
17
|
-
"dbgate-tools": "^5.
|
|
18
|
-
"dbgate-filterparser": "^5.
|
|
16
|
+
"dbgate-sqltree": "^5.4.0",
|
|
17
|
+
"dbgate-tools": "^5.4.0",
|
|
18
|
+
"dbgate-filterparser": "^5.4.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"dbgate-types": "^5.
|
|
21
|
+
"dbgate-types": "^5.4.0",
|
|
22
22
|
"@types/node": "^13.7.0",
|
|
23
23
|
"jest": "^28.1.3",
|
|
24
24
|
"ts-jest": "^28.0.7",
|