dbgate-datalib 4.2.6 → 4.3.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.
- package/lib/ChangeSet.d.ts +2 -1
- package/lib/ChangeSet.js +12 -9
- package/lib/CollectionGridDisplay.js +1 -0
- package/lib/FormViewDisplay.js +4 -4
- package/lib/FreeTableGridDisplay.d.ts +2 -0
- package/lib/FreeTableGridDisplay.js +3 -2
- package/lib/FreeTableModel.js +1 -0
- package/lib/GridConfig.js +1 -0
- package/lib/GridDisplay.d.ts +1 -0
- package/lib/GridDisplay.js +13 -13
- package/lib/JslGridDisplay.js +2 -1
- package/lib/TableFormViewDisplay.js +10 -9
- package/lib/TableGridDisplay.d.ts +2 -0
- package/lib/TableGridDisplay.js +6 -4
- package/lib/ViewGridDisplay.d.ts +2 -0
- package/lib/ViewGridDisplay.js +4 -2
- package/lib/deleteCascade.d.ts +8 -0
- package/lib/deleteCascade.js +119 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +24 -15
- package/lib/runMacro.js +2 -1
- package/package.json +5 -5
package/lib/ChangeSet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command } from 'dbgate-sqltree';
|
|
1
|
+
import { Command, Condition } from 'dbgate-sqltree';
|
|
2
2
|
import { NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
|
3
3
|
export interface ChangeSetItem {
|
|
4
4
|
pureName: string;
|
|
@@ -34,6 +34,7 @@ export declare function findExistingChangeSetItem(changeSet: ChangeSet, definiti
|
|
|
34
34
|
export declare function setChangeSetValue(changeSet: ChangeSet, definition: ChangeSetFieldDefinition, value: string): ChangeSet;
|
|
35
35
|
export declare function setChangeSetRowData(changeSet: ChangeSet, definition: ChangeSetRowDefinition, document: any): ChangeSet;
|
|
36
36
|
export declare function batchUpdateChangeSet(changeSet: ChangeSet, rowDefinitions: ChangeSetRowDefinition[], dataRows: []): ChangeSet;
|
|
37
|
+
export declare function extractChangeSetCondition(item: ChangeSetItem, alias?: string): Condition;
|
|
37
38
|
export declare function changeSetToSql(changeSet: ChangeSet, dbinfo: DatabaseInfo): Command[];
|
|
38
39
|
export declare function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
|
|
39
40
|
export declare function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet;
|
package/lib/ChangeSet.js
CHANGED
|
@@ -3,6 +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.changeSetInsertNewRow = exports.getChangeSetInsertedRows = exports.deleteChangeSetRows = exports.revertChangeSetRowChanges = exports.changeSetToSql = exports.extractChangeSetCondition = exports.batchUpdateChangeSet = exports.setChangeSetRowData = exports.setChangeSetValue = exports.findExistingChangeSetItem = exports.createChangeSet = void 0;
|
|
6
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
8
|
function createChangeSet() {
|
|
8
9
|
return {
|
|
@@ -140,7 +141,7 @@ function extractFields(item, allowNulls = true) {
|
|
|
140
141
|
value: item.fields[targetColumn],
|
|
141
142
|
}));
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
+
function changeSetInsertToSql(item, dbinfo = null) {
|
|
144
145
|
const fields = extractFields(item, false);
|
|
145
146
|
if (fields.length == 0)
|
|
146
147
|
return null;
|
|
@@ -181,7 +182,7 @@ function insertToSql(item, dbinfo = null) {
|
|
|
181
182
|
: null,
|
|
182
183
|
];
|
|
183
184
|
}
|
|
184
|
-
function
|
|
185
|
+
function extractChangeSetCondition(item, alias) {
|
|
185
186
|
return {
|
|
186
187
|
conditionType: 'and',
|
|
187
188
|
conditions: lodash_1.default.keys(item.condition).map(columnName => ({
|
|
@@ -195,6 +196,7 @@ function extractCondition(item) {
|
|
|
195
196
|
pureName: item.pureName,
|
|
196
197
|
schemaName: item.schemaName,
|
|
197
198
|
},
|
|
199
|
+
alias,
|
|
198
200
|
},
|
|
199
201
|
},
|
|
200
202
|
right: {
|
|
@@ -204,7 +206,8 @@ function extractCondition(item) {
|
|
|
204
206
|
})),
|
|
205
207
|
};
|
|
206
208
|
}
|
|
207
|
-
|
|
209
|
+
exports.extractChangeSetCondition = extractChangeSetCondition;
|
|
210
|
+
function changeSetUpdateToSql(item) {
|
|
208
211
|
return {
|
|
209
212
|
from: {
|
|
210
213
|
name: {
|
|
@@ -214,10 +217,10 @@ function updateToSql(item) {
|
|
|
214
217
|
},
|
|
215
218
|
commandType: 'update',
|
|
216
219
|
fields: extractFields(item),
|
|
217
|
-
where:
|
|
220
|
+
where: extractChangeSetCondition(item),
|
|
218
221
|
};
|
|
219
222
|
}
|
|
220
|
-
function
|
|
223
|
+
function changeSetDeleteToSql(item) {
|
|
221
224
|
return {
|
|
222
225
|
from: {
|
|
223
226
|
name: {
|
|
@@ -226,14 +229,14 @@ function deleteToSql(item) {
|
|
|
226
229
|
},
|
|
227
230
|
},
|
|
228
231
|
commandType: 'delete',
|
|
229
|
-
where:
|
|
232
|
+
where: extractChangeSetCondition(item),
|
|
230
233
|
};
|
|
231
234
|
}
|
|
232
235
|
function changeSetToSql(changeSet, dbinfo) {
|
|
233
236
|
return lodash_1.default.compact(lodash_1.default.flatten([
|
|
234
|
-
...changeSet.inserts.map(item =>
|
|
235
|
-
...changeSet.updates.map(
|
|
236
|
-
...changeSet.deletes.map(
|
|
237
|
+
...changeSet.inserts.map(item => changeSetInsertToSql(item, dbinfo)),
|
|
238
|
+
...changeSet.updates.map(changeSetUpdateToSql),
|
|
239
|
+
...changeSet.deletes.map(changeSetDeleteToSql),
|
|
237
240
|
]));
|
|
238
241
|
}
|
|
239
242
|
exports.changeSetToSql = changeSetToSql;
|
|
@@ -3,6 +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.CollectionGridDisplay = exports.analyseCollectionDisplayColumns = void 0;
|
|
6
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
8
|
const GridDisplay_1 = require("./GridDisplay");
|
|
8
9
|
function getObjectKeys(obj) {
|
package/lib/FormViewDisplay.js
CHANGED
|
@@ -3,12 +3,12 @@ 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.FormViewDisplay = void 0;
|
|
6
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
8
|
const GridConfig_1 = require("./GridConfig");
|
|
8
9
|
const dbgate_filterparser_1 = require("dbgate-filterparser");
|
|
9
10
|
class FormViewDisplay {
|
|
10
11
|
constructor(config, setConfig, cache, setCache, driver, dbinfo = null, serverVersion = null) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
12
|
this.config = config;
|
|
13
13
|
this.setConfig = setConfig;
|
|
14
14
|
this.cache = cache;
|
|
@@ -17,7 +17,7 @@ class FormViewDisplay {
|
|
|
17
17
|
this.dbinfo = dbinfo;
|
|
18
18
|
this.serverVersion = serverVersion;
|
|
19
19
|
this.isLoadedCorrectly = true;
|
|
20
|
-
this.dialect = ((
|
|
20
|
+
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);
|
|
21
21
|
}
|
|
22
22
|
addFilterColumn(column) {
|
|
23
23
|
if (!column)
|
|
@@ -28,7 +28,7 @@ class FormViewDisplay {
|
|
|
28
28
|
if (!column || !rowData)
|
|
29
29
|
return;
|
|
30
30
|
const value = rowData[column.uniqueName];
|
|
31
|
-
const expr = dbgate_filterparser_1.getFilterValueExpression(value, column.dataType);
|
|
31
|
+
const expr = (0, dbgate_filterparser_1.getFilterValueExpression)(value, column.dataType);
|
|
32
32
|
if (expr) {
|
|
33
33
|
this.setConfig(cfg => (Object.assign(Object.assign({}, cfg), { filters: Object.assign(Object.assign({}, cfg.filters), { [column.uniqueName]: expr }), addedColumns: cfg.addedColumns.includes(column.uniqueName)
|
|
34
34
|
? cfg.addedColumns
|
|
@@ -47,7 +47,7 @@ class FormViewDisplay {
|
|
|
47
47
|
this.reload();
|
|
48
48
|
}
|
|
49
49
|
reload() {
|
|
50
|
-
this.setCache(cache => (Object.assign(Object.assign({}, GridConfig_1.createGridCache()), { refreshTime: new Date().getTime() })));
|
|
50
|
+
this.setCache(cache => (Object.assign(Object.assign({}, (0, GridConfig_1.createGridCache)()), { refreshTime: new Date().getTime() })));
|
|
51
51
|
}
|
|
52
52
|
getKeyValue(columnName) {
|
|
53
53
|
const { formViewKey, formViewKeyRequested } = this.config;
|
|
@@ -12,6 +12,7 @@ export declare class FreeTableGridDisplay extends GridDisplay {
|
|
|
12
12
|
headerText: string;
|
|
13
13
|
uniqueName: string;
|
|
14
14
|
uniquePath: string[];
|
|
15
|
+
pairingId?: string;
|
|
15
16
|
columnName: string;
|
|
16
17
|
notNull: boolean;
|
|
17
18
|
autoIncrement: boolean;
|
|
@@ -31,6 +32,7 @@ export declare class FreeTableGridDisplay extends GridDisplay {
|
|
|
31
32
|
headerText: string;
|
|
32
33
|
uniqueName: string;
|
|
33
34
|
uniquePath: string[];
|
|
35
|
+
pairingId?: string;
|
|
34
36
|
columnName: string;
|
|
35
37
|
notNull: boolean;
|
|
36
38
|
autoIncrement: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FreeTableGridDisplay = void 0;
|
|
3
4
|
const GridDisplay_1 = require("./GridDisplay");
|
|
4
5
|
class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
5
6
|
constructor(model, config, setConfig, cache, setCache) {
|
|
@@ -10,8 +11,8 @@ class FreeTableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
10
11
|
this.sortable = false;
|
|
11
12
|
}
|
|
12
13
|
getDisplayColumns(model) {
|
|
13
|
-
var _a, _b, _c
|
|
14
|
-
return (((
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
return (((_c = (_b = (_a = model === null || model === void 0 ? void 0 : model.structure) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.map(col => this.getDisplayColumn(col))) === null || _c === void 0 ? void 0 : _c.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
|
|
15
16
|
}
|
|
16
17
|
getDisplayColumn(col) {
|
|
17
18
|
const uniquePath = [col.columnName];
|
package/lib/FreeTableModel.js
CHANGED
package/lib/GridConfig.js
CHANGED
package/lib/GridDisplay.d.ts
CHANGED
package/lib/GridDisplay.js
CHANGED
|
@@ -3,6 +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.reloadDataCacheFunc = exports.GridDisplay = void 0;
|
|
6
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
8
|
const GridConfig_1 = require("./GridConfig");
|
|
8
9
|
const dbgate_filterparser_1 = require("dbgate-filterparser");
|
|
@@ -11,7 +12,6 @@ const dbgate_sqltree_1 = require("dbgate-sqltree");
|
|
|
11
12
|
const dbgate_tools_2 = require("dbgate-tools");
|
|
12
13
|
class GridDisplay {
|
|
13
14
|
constructor(config, setConfig, cache, setCache, driver, dbinfo = null, serverVersion = null) {
|
|
14
|
-
var _a, _b, _c;
|
|
15
15
|
this.config = config;
|
|
16
16
|
this.setConfig = setConfig;
|
|
17
17
|
this.cache = cache;
|
|
@@ -21,12 +21,13 @@ class GridDisplay {
|
|
|
21
21
|
this.serverVersion = serverVersion;
|
|
22
22
|
this.changeSetKeyFields = null;
|
|
23
23
|
this.sortable = false;
|
|
24
|
+
this.groupable = false;
|
|
24
25
|
this.filterable = false;
|
|
25
26
|
this.editable = false;
|
|
26
27
|
this.isLoadedCorrectly = true;
|
|
27
28
|
this.supportsReload = false;
|
|
28
29
|
this.isDynamicStructure = false;
|
|
29
|
-
this.dialect = ((
|
|
30
|
+
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);
|
|
30
31
|
}
|
|
31
32
|
get baseTableOrCollection() {
|
|
32
33
|
return this.baseTable || this.baseCollection;
|
|
@@ -95,7 +96,7 @@ class GridDisplay {
|
|
|
95
96
|
if (!column)
|
|
96
97
|
continue;
|
|
97
98
|
try {
|
|
98
|
-
const condition = dbgate_filterparser_1.parseFilter(filter, dbgate_filterparser_1.getFilterType(column.dataType));
|
|
99
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filter, (0, dbgate_filterparser_1.getFilterType)(column.dataType));
|
|
99
100
|
if (condition) {
|
|
100
101
|
conditions.push(lodash_1.default.cloneDeepWith(condition, (expr) => {
|
|
101
102
|
if (expr.exprType == 'placeholder')
|
|
@@ -202,7 +203,7 @@ class GridDisplay {
|
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
getColumns(columnFilter) {
|
|
205
|
-
return this.columns.filter(col => dbgate_tools_1.filterName(columnFilter, col.columnName));
|
|
206
|
+
return this.columns.filter(col => (0, dbgate_tools_1.filterName)(columnFilter, col.columnName));
|
|
206
207
|
}
|
|
207
208
|
getGridColumns() {
|
|
208
209
|
return this.getColumns(null).filter(x => this.isColumnChecked(x));
|
|
@@ -245,14 +246,13 @@ class GridDisplay {
|
|
|
245
246
|
this.reload();
|
|
246
247
|
}
|
|
247
248
|
getGrouping(uniqueName) {
|
|
248
|
-
var _a, _b;
|
|
249
249
|
if (this.isGrouped) {
|
|
250
250
|
if (this.config.grouping[uniqueName])
|
|
251
251
|
return this.config.grouping[uniqueName];
|
|
252
252
|
const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
|
|
253
|
-
if (dbgate_tools_2.isTypeLogical(
|
|
253
|
+
if ((0, dbgate_tools_2.isTypeLogical)(column === null || column === void 0 ? void 0 : column.dataType))
|
|
254
254
|
return 'COUNT DISTINCT';
|
|
255
|
-
if (
|
|
255
|
+
if (column === null || column === void 0 ? void 0 : column.autoIncrement)
|
|
256
256
|
return 'COUNT';
|
|
257
257
|
return 'MAX';
|
|
258
258
|
}
|
|
@@ -390,7 +390,7 @@ class GridDisplay {
|
|
|
390
390
|
select = this.getRowNumberOverSelect(select, offset, count);
|
|
391
391
|
else if (this.dialect.limitSelect)
|
|
392
392
|
select.topRecords = count;
|
|
393
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
393
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
394
394
|
return sql;
|
|
395
395
|
}
|
|
396
396
|
getExportQuery(postprocessSelect = null) {
|
|
@@ -399,7 +399,7 @@ class GridDisplay {
|
|
|
399
399
|
return null;
|
|
400
400
|
if (postprocessSelect)
|
|
401
401
|
postprocessSelect(select);
|
|
402
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
402
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
403
403
|
return sql;
|
|
404
404
|
}
|
|
405
405
|
resizeColumn(uniqueName, computedSize, diff) {
|
|
@@ -442,7 +442,7 @@ class GridDisplay {
|
|
|
442
442
|
},
|
|
443
443
|
];
|
|
444
444
|
}
|
|
445
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
445
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
446
446
|
return sql;
|
|
447
447
|
}
|
|
448
448
|
compileFilters() {
|
|
@@ -454,9 +454,9 @@ class GridDisplay {
|
|
|
454
454
|
const column = this.columns.find(x => (x.columnName = name));
|
|
455
455
|
if (!column)
|
|
456
456
|
continue;
|
|
457
|
-
const filterType = dbgate_filterparser_1.getFilterType(column.dataType);
|
|
457
|
+
const filterType = (0, dbgate_filterparser_1.getFilterType)(column.dataType);
|
|
458
458
|
try {
|
|
459
|
-
const condition = dbgate_filterparser_1.parseFilter(filters[name], filterType);
|
|
459
|
+
const condition = (0, dbgate_filterparser_1.parseFilter)(filters[name], filterType);
|
|
460
460
|
const replaced = lodash_1.default.cloneDeepWith(condition, (expr) => {
|
|
461
461
|
if (expr.exprType == 'placeholder')
|
|
462
462
|
return {
|
|
@@ -494,6 +494,6 @@ class GridDisplay {
|
|
|
494
494
|
}
|
|
495
495
|
exports.GridDisplay = GridDisplay;
|
|
496
496
|
function reloadDataCacheFunc(cache) {
|
|
497
|
-
return Object.assign(Object.assign({}, GridConfig_1.createGridCache()), { refreshTime: new Date().getTime() });
|
|
497
|
+
return Object.assign(Object.assign({}, (0, GridConfig_1.createGridCache)()), { refreshTime: new Date().getTime() });
|
|
498
498
|
}
|
|
499
499
|
exports.reloadDataCacheFunc = reloadDataCacheFunc;
|
package/lib/JslGridDisplay.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JslGridDisplay = void 0;
|
|
3
4
|
const GridDisplay_1 = require("./GridDisplay");
|
|
4
5
|
const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
|
|
5
6
|
class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
@@ -21,7 +22,7 @@ class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
21
22
|
}))) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })));
|
|
22
23
|
}
|
|
23
24
|
if (structure.__isDynamicStructure) {
|
|
24
|
-
this.columns = CollectionGridDisplay_1.analyseCollectionDisplayColumns(rows, this);
|
|
25
|
+
this.columns = (0, CollectionGridDisplay_1.analyseCollectionDisplayColumns)(rows, this);
|
|
25
26
|
}
|
|
26
27
|
if (!this.columns)
|
|
27
28
|
this.columns = [];
|
|
@@ -3,6 +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.TableFormViewDisplay = void 0;
|
|
6
7
|
const FormViewDisplay_1 = require("./FormViewDisplay");
|
|
7
8
|
const dbgate_sqltree_1 = require("dbgate-sqltree");
|
|
8
9
|
const TableGridDisplay_1 = require("./TableGridDisplay");
|
|
@@ -123,8 +124,8 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
|
|
|
123
124
|
const select = this.getSelect();
|
|
124
125
|
if (!select)
|
|
125
126
|
return null;
|
|
126
|
-
select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyEqualCondition());
|
|
127
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
127
|
+
select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyEqualCondition());
|
|
128
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
128
129
|
return sql;
|
|
129
130
|
}
|
|
130
131
|
getCountSelect() {
|
|
@@ -148,7 +149,7 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
|
|
|
148
149
|
const select = this.getCountSelect();
|
|
149
150
|
if (!select)
|
|
150
151
|
return null;
|
|
151
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
152
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
152
153
|
return sql;
|
|
153
154
|
}
|
|
154
155
|
getBeforeCountQuery() {
|
|
@@ -157,8 +158,8 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
|
|
|
157
158
|
const select = this.getCountSelect();
|
|
158
159
|
if (!select)
|
|
159
160
|
return null;
|
|
160
|
-
select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
|
161
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
161
|
+
select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
|
162
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
162
163
|
return sql;
|
|
163
164
|
}
|
|
164
165
|
navigate(row) {
|
|
@@ -169,7 +170,7 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
|
|
|
169
170
|
if (!row)
|
|
170
171
|
return false;
|
|
171
172
|
const formViewKey = this.extractKey(row);
|
|
172
|
-
return json_stable_stringify_1.default(formViewKey) == json_stable_stringify_1.default(this.config.formViewKey);
|
|
173
|
+
return (0, json_stable_stringify_1.default)(formViewKey) == (0, json_stable_stringify_1.default)(this.config.formViewKey);
|
|
173
174
|
}
|
|
174
175
|
navigateRowQuery(commmand) {
|
|
175
176
|
if (!this.driver)
|
|
@@ -195,14 +196,14 @@ class TableFormViewDisplay extends FormViewDisplay_1.FormViewDisplay {
|
|
|
195
196
|
break;
|
|
196
197
|
case 'previous':
|
|
197
198
|
select.orderBy = getOrderBy('DESC');
|
|
198
|
-
select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
|
199
|
+
select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
|
199
200
|
break;
|
|
200
201
|
case 'next':
|
|
201
202
|
select.orderBy = getOrderBy('ASC');
|
|
202
|
-
select.where = dbgate_sqltree_1.mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('>'));
|
|
203
|
+
select.where = (0, dbgate_sqltree_1.mergeConditions)(select.where, this.getPrimaryKeyOperatorCondition('>'));
|
|
203
204
|
break;
|
|
204
205
|
}
|
|
205
|
-
const sql = dbgate_sqltree_1.treeToSql(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
206
|
+
const sql = (0, dbgate_sqltree_1.treeToSql)(this.driver, select, dbgate_sqltree_1.dumpSqlSelect);
|
|
206
207
|
return sql;
|
|
207
208
|
}
|
|
208
209
|
getChangeSetRow(row) {
|
|
@@ -24,6 +24,7 @@ export declare class TableGridDisplay extends GridDisplay {
|
|
|
24
24
|
uniquePath: string[];
|
|
25
25
|
isPrimaryKey: boolean;
|
|
26
26
|
foreignKey: import("dbgate-types").ForeignKeyInfo;
|
|
27
|
+
pairingId?: string;
|
|
27
28
|
columnName: string;
|
|
28
29
|
notNull: boolean;
|
|
29
30
|
autoIncrement: boolean;
|
|
@@ -54,6 +55,7 @@ export declare class TableGridDisplay extends GridDisplay {
|
|
|
54
55
|
uniquePath: string[];
|
|
55
56
|
isPrimaryKey: boolean;
|
|
56
57
|
foreignKey: import("dbgate-types").ForeignKeyInfo;
|
|
58
|
+
pairingId?: string;
|
|
57
59
|
columnName: string;
|
|
58
60
|
notNull: boolean;
|
|
59
61
|
autoIncrement: boolean;
|
package/lib/TableGridDisplay.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableGridDisplay = void 0;
|
|
3
4
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
4
5
|
const GridDisplay_1 = require("./GridDisplay");
|
|
5
6
|
class TableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
@@ -20,6 +21,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
20
21
|
this.columns = this.getDisplayColumns(this.table, []);
|
|
21
22
|
this.filterable = true;
|
|
22
23
|
this.sortable = true;
|
|
24
|
+
this.groupable = true;
|
|
23
25
|
this.editable = true;
|
|
24
26
|
this.supportsReload = true;
|
|
25
27
|
this.baseTable = this.table;
|
|
@@ -35,8 +37,8 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
35
37
|
this.dbinfo.tables.find(x => x.pureName == pureName && x.schemaName == schemaName));
|
|
36
38
|
}
|
|
37
39
|
getDisplayColumns(table, parentPath) {
|
|
38
|
-
var _a, _b
|
|
39
|
-
return (((
|
|
40
|
+
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 })))) || []);
|
|
40
42
|
}
|
|
41
43
|
addJoinsFromExpandedColumns(select, columns, parentAlias, columnSources) {
|
|
42
44
|
for (const column of columns) {
|
|
@@ -94,7 +96,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
94
96
|
}
|
|
95
97
|
const table = this.getFkTarget(column);
|
|
96
98
|
if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
|
|
97
|
-
const hintColumn = table.columns.find(x => { var _a, _b
|
|
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'); });
|
|
98
100
|
if (hintColumn) {
|
|
99
101
|
const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
|
|
100
102
|
this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
|
|
@@ -147,7 +149,7 @@ class TableGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
147
149
|
return select;
|
|
148
150
|
}
|
|
149
151
|
getColumns(columnFilter) {
|
|
150
|
-
return this.enrichExpandedColumns(this.columns.filter(col => dbgate_tools_1.filterName(columnFilter, col.columnName)));
|
|
152
|
+
return this.enrichExpandedColumns(this.columns.filter(col => (0, dbgate_tools_1.filterName)(columnFilter, col.columnName)));
|
|
151
153
|
}
|
|
152
154
|
getDisplayColumn(table, col, parentPath) {
|
|
153
155
|
const uniquePath = [...parentPath, col.columnName];
|
package/lib/ViewGridDisplay.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class ViewGridDisplay extends GridDisplay {
|
|
|
11
11
|
headerText: string;
|
|
12
12
|
uniqueName: string;
|
|
13
13
|
uniquePath: string[];
|
|
14
|
+
pairingId?: string;
|
|
14
15
|
columnName: string;
|
|
15
16
|
notNull: boolean;
|
|
16
17
|
autoIncrement: boolean;
|
|
@@ -30,6 +31,7 @@ export declare class ViewGridDisplay extends GridDisplay {
|
|
|
30
31
|
headerText: string;
|
|
31
32
|
uniqueName: string;
|
|
32
33
|
uniquePath: string[];
|
|
34
|
+
pairingId?: string;
|
|
33
35
|
columnName: string;
|
|
34
36
|
notNull: boolean;
|
|
35
37
|
autoIncrement: boolean;
|
package/lib/ViewGridDisplay.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ViewGridDisplay = void 0;
|
|
3
4
|
const GridDisplay_1 = require("./GridDisplay");
|
|
4
5
|
class ViewGridDisplay extends GridDisplay_1.GridDisplay {
|
|
5
6
|
constructor(view, driver, config, setConfig, cache, setCache, serverVersion) {
|
|
@@ -8,12 +9,13 @@ class ViewGridDisplay extends GridDisplay_1.GridDisplay {
|
|
|
8
9
|
this.columns = this.getDisplayColumns(view);
|
|
9
10
|
this.filterable = true;
|
|
10
11
|
this.sortable = true;
|
|
12
|
+
this.groupable = true;
|
|
11
13
|
this.editable = false;
|
|
12
14
|
this.supportsReload = true;
|
|
13
15
|
}
|
|
14
16
|
getDisplayColumns(view) {
|
|
15
|
-
var _a, _b
|
|
16
|
-
return (((
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return (((_b = (_a = view === null || view === void 0 ? void 0 : view.columns) === null || _a === void 0 ? void 0 : _a.map(col => this.getDisplayColumn(view, col))) === null || _b === void 0 ? void 0 : _b.map(col => (Object.assign(Object.assign({}, col), { isChecked: this.isColumnChecked(col) })))) || []);
|
|
17
19
|
}
|
|
18
20
|
getDisplayColumn(view, col) {
|
|
19
21
|
const uniquePath = [col.columnName];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from 'dbgate-sqltree';
|
|
2
|
+
import { DatabaseInfo } from 'dbgate-types';
|
|
3
|
+
import { ChangeSet } from './ChangeSet';
|
|
4
|
+
export interface ChangeSetDeleteCascade {
|
|
5
|
+
title: string;
|
|
6
|
+
commands: Command[];
|
|
7
|
+
}
|
|
8
|
+
export declare function getDeleteCascades(changeSet: ChangeSet, dbinfo: DatabaseInfo): ChangeSetDeleteCascade[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDeleteCascades = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const ChangeSet_1 = require("./ChangeSet");
|
|
9
|
+
// function getDeleteScript()
|
|
10
|
+
function processDependencies(changeSet, result, allForeignKeys, fkPath, table, baseCmd, dbinfo) {
|
|
11
|
+
if (result.find(x => x.title == table.pureName))
|
|
12
|
+
return;
|
|
13
|
+
const dependencies = allForeignKeys.filter(x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName);
|
|
14
|
+
for (const fk of dependencies) {
|
|
15
|
+
const depTable = dbinfo.tables.find(x => x.pureName == fk.pureName && x.schemaName == fk.schemaName);
|
|
16
|
+
const subFkPath = [...fkPath, fk];
|
|
17
|
+
if (depTable && depTable.pureName != baseCmd.pureName) {
|
|
18
|
+
processDependencies(changeSet, result, allForeignKeys, subFkPath, depTable, baseCmd, dbinfo);
|
|
19
|
+
}
|
|
20
|
+
const refCmd = {
|
|
21
|
+
commandType: 'delete',
|
|
22
|
+
from: {
|
|
23
|
+
name: {
|
|
24
|
+
pureName: fk.pureName,
|
|
25
|
+
schemaName: fk.schemaName,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
where: {
|
|
29
|
+
conditionType: 'exists',
|
|
30
|
+
subQuery: {
|
|
31
|
+
commandType: 'select',
|
|
32
|
+
selectAll: true,
|
|
33
|
+
from: {
|
|
34
|
+
name: {
|
|
35
|
+
pureName: fk.pureName,
|
|
36
|
+
schemaName: fk.schemaName,
|
|
37
|
+
},
|
|
38
|
+
alias: 't0',
|
|
39
|
+
relations: subFkPath.map((fkItem, fkIndex) => ({
|
|
40
|
+
joinType: 'INNER JOIN',
|
|
41
|
+
alias: `t${fkIndex + 1}`,
|
|
42
|
+
name: {
|
|
43
|
+
pureName: fkItem.refTableName,
|
|
44
|
+
schemaName: fkItem.refSchemaName,
|
|
45
|
+
},
|
|
46
|
+
conditions: fkItem.columns.map(column => ({
|
|
47
|
+
conditionType: 'binary',
|
|
48
|
+
operator: '=',
|
|
49
|
+
left: {
|
|
50
|
+
exprType: 'column',
|
|
51
|
+
columnName: column.columnName,
|
|
52
|
+
source: { alias: `t${fkIndex}` },
|
|
53
|
+
},
|
|
54
|
+
right: {
|
|
55
|
+
exprType: 'column',
|
|
56
|
+
columnName: column.refColumnName,
|
|
57
|
+
source: { alias: `t${fkIndex + 1}` },
|
|
58
|
+
},
|
|
59
|
+
})),
|
|
60
|
+
})),
|
|
61
|
+
},
|
|
62
|
+
where: {
|
|
63
|
+
conditionType: 'and',
|
|
64
|
+
conditions: [
|
|
65
|
+
(0, ChangeSet_1.extractChangeSetCondition)(baseCmd, `t${subFkPath.length}`),
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
...table.primaryKey.columns.map(column => ({
|
|
68
|
+
conditionType: 'binary',
|
|
69
|
+
operator: '=',
|
|
70
|
+
left: {
|
|
71
|
+
exprType: 'column',
|
|
72
|
+
columnName: column.columnName,
|
|
73
|
+
source: { alias: 't0' },
|
|
74
|
+
},
|
|
75
|
+
right: {
|
|
76
|
+
exprType: 'column',
|
|
77
|
+
columnName: column.columnName,
|
|
78
|
+
source: {
|
|
79
|
+
name: fk,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
})),
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
let resItem = result.find(x => x.title == fk.pureName);
|
|
89
|
+
if (!resItem) {
|
|
90
|
+
resItem = {
|
|
91
|
+
title: fk.pureName,
|
|
92
|
+
commands: [],
|
|
93
|
+
};
|
|
94
|
+
result.push(resItem);
|
|
95
|
+
}
|
|
96
|
+
resItem.commands.push(refCmd);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function getDeleteCascades(changeSet, dbinfo) {
|
|
100
|
+
const result = [];
|
|
101
|
+
const allForeignKeys = lodash_1.default.flatten(dbinfo.tables.map(x => x.foreignKeys));
|
|
102
|
+
for (const baseCmd of changeSet.deletes) {
|
|
103
|
+
const table = dbinfo.tables.find(x => x.pureName == baseCmd.pureName && x.schemaName == baseCmd.schemaName);
|
|
104
|
+
if (!table.primaryKey)
|
|
105
|
+
continue;
|
|
106
|
+
processDependencies(changeSet, result, allForeignKeys, [], table, baseCmd, dbinfo);
|
|
107
|
+
// let resItem = result.find(x => x.title == baseCmd.pureName);
|
|
108
|
+
// if (!resItem) {
|
|
109
|
+
// resItem = {
|
|
110
|
+
// title: baseCmd.pureName,
|
|
111
|
+
// commands: [],
|
|
112
|
+
// };
|
|
113
|
+
// result.push(resItem);
|
|
114
|
+
// }
|
|
115
|
+
// resItem.commands.push(changeSetDeleteToSql(baseCmd));
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
exports.getDeleteCascades = getDeleteCascades;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__exportStar(require("./GridDisplay"), exports);
|
|
14
|
+
__exportStar(require("./GridConfig"), exports);
|
|
15
|
+
__exportStar(require("./TableGridDisplay"), exports);
|
|
16
|
+
__exportStar(require("./ViewGridDisplay"), exports);
|
|
17
|
+
__exportStar(require("./JslGridDisplay"), exports);
|
|
18
|
+
__exportStar(require("./ChangeSet"), exports);
|
|
19
|
+
__exportStar(require("./FreeTableGridDisplay"), exports);
|
|
20
|
+
__exportStar(require("./FreeTableModel"), exports);
|
|
21
|
+
__exportStar(require("./MacroDefinition"), exports);
|
|
22
|
+
__exportStar(require("./runMacro"), exports);
|
|
23
|
+
__exportStar(require("./FormViewDisplay"), exports);
|
|
24
|
+
__exportStar(require("./TableFormViewDisplay"), exports);
|
|
25
|
+
__exportStar(require("./CollectionGridDisplay"), exports);
|
|
26
|
+
__exportStar(require("./deleteCascade"), exports);
|
package/lib/runMacro.js
CHANGED
|
@@ -3,6 +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.runMacroOnChangeSet = exports.runMacroOnValue = exports.compileMacroFunction = exports.runMacro = void 0;
|
|
6
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
7
8
|
const v1_1 = __importDefault(require("uuid/v1"));
|
|
8
9
|
const v4_1 = __importDefault(require("uuid/v4"));
|
|
@@ -177,7 +178,7 @@ function runMacroOnChangeSet(macro, macroArgs, selectedCells, changeSet, display
|
|
|
177
178
|
for (const cell of selectedCells) {
|
|
178
179
|
const definition = display.getChangeSetField(cell.rowData, cell.column, undefined);
|
|
179
180
|
const macroResult = runMacroOnValue(compiledMacroFunc, macroArgs, cell.value, cell.row, cell.rowData, cell.column, errors);
|
|
180
|
-
res = ChangeSet_1.setChangeSetValue(res, definition, macroResult);
|
|
181
|
+
res = (0, ChangeSet_1.setChangeSetValue)(res, definition, macroResult);
|
|
181
182
|
}
|
|
182
183
|
return res;
|
|
183
184
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.3.1",
|
|
3
3
|
"name": "dbgate-datalib",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"lib"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"dbgate-sqltree": "^4.
|
|
15
|
-
"dbgate-filterparser": "^4.
|
|
14
|
+
"dbgate-sqltree": "^4.3.1",
|
|
15
|
+
"dbgate-filterparser": "^4.3.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"dbgate-types": "^4.
|
|
18
|
+
"dbgate-types": "^4.3.1",
|
|
19
19
|
"@types/node": "^13.7.0",
|
|
20
|
-
"typescript": "^
|
|
20
|
+
"typescript": "^4.4.3"
|
|
21
21
|
}
|
|
22
22
|
}
|