dbgate-tools 6.4.3-alpha.1 → 6.5.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/DatabaseAnalyser.js +147 -154
- package/lib/ScriptWriter.js +62 -87
- package/lib/SqlDumper.js +7 -7
- package/lib/SqlGenerator.js +85 -95
- package/lib/alterPlan.js +11 -2
- package/lib/computeDiffRows.js +22 -2
- package/lib/createAsyncWriteStream.js +3 -12
- package/lib/createBulkInsertStreamBase.js +26 -35
- package/lib/dbKeysLoader.js +49 -8
- package/lib/diffTools.js +74 -6
- package/lib/driverBase.js +130 -155
- package/lib/getLogger.js +7 -1
- package/lib/preloadedRowsTools.js +35 -39
- package/lib/schemaEditorTools.js +89 -26
- package/lib/stringTools.d.ts +6 -0
- package/lib/stringTools.js +52 -16
- package/lib/structureTools.js +156 -13
- package/package.json +3 -3
package/lib/SqlGenerator.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -41,66 +32,64 @@ class SqlGenerator {
|
|
|
41
32
|
this.triggers = this.extract('triggers');
|
|
42
33
|
this.schedulerEvents = this.extract('schedulerEvents');
|
|
43
34
|
}
|
|
44
|
-
dump() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
});
|
|
35
|
+
async dump() {
|
|
36
|
+
try {
|
|
37
|
+
process.on('uncaughtException', this.handleException);
|
|
38
|
+
this.dropObjects(this.procedures, 'Procedure');
|
|
39
|
+
if (this.checkDumper())
|
|
40
|
+
return;
|
|
41
|
+
this.dropObjects(this.functions, 'Function');
|
|
42
|
+
if (this.checkDumper())
|
|
43
|
+
return;
|
|
44
|
+
this.dropObjects(this.views, 'View');
|
|
45
|
+
if (this.checkDumper())
|
|
46
|
+
return;
|
|
47
|
+
this.dropObjects(this.matviews, 'Matview');
|
|
48
|
+
if (this.checkDumper())
|
|
49
|
+
return;
|
|
50
|
+
this.dropObjects(this.triggers, 'Trigger');
|
|
51
|
+
if (this.checkDumper())
|
|
52
|
+
return;
|
|
53
|
+
this.dropObjects(this.schedulerEvents, 'SchedulerEvent');
|
|
54
|
+
if (this.checkDumper())
|
|
55
|
+
return;
|
|
56
|
+
this.dropTables();
|
|
57
|
+
if (this.checkDumper())
|
|
58
|
+
return;
|
|
59
|
+
this.createTables();
|
|
60
|
+
if (this.checkDumper())
|
|
61
|
+
return;
|
|
62
|
+
this.truncateTables();
|
|
63
|
+
if (this.checkDumper())
|
|
64
|
+
return;
|
|
65
|
+
await this.insertData();
|
|
66
|
+
if (this.checkDumper())
|
|
67
|
+
return;
|
|
68
|
+
this.createForeignKeys();
|
|
69
|
+
if (this.checkDumper())
|
|
70
|
+
return;
|
|
71
|
+
this.createObjects(this.procedures, 'Procedure');
|
|
72
|
+
if (this.checkDumper())
|
|
73
|
+
return;
|
|
74
|
+
this.createObjects(this.functions, 'Function');
|
|
75
|
+
if (this.checkDumper())
|
|
76
|
+
return;
|
|
77
|
+
this.createObjects(this.views, 'View');
|
|
78
|
+
if (this.checkDumper())
|
|
79
|
+
return;
|
|
80
|
+
this.createObjects(this.matviews, 'Matview');
|
|
81
|
+
if (this.checkDumper())
|
|
82
|
+
return;
|
|
83
|
+
this.createObjects(this.triggers, 'Trigger');
|
|
84
|
+
if (this.checkDumper())
|
|
85
|
+
return;
|
|
86
|
+
this.createObjects(this.schedulerEvents, 'SchedulerEvent');
|
|
87
|
+
if (this.checkDumper())
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
process.off('uncaughtException', this.handleException);
|
|
92
|
+
}
|
|
104
93
|
}
|
|
105
94
|
createForeignKeys() {
|
|
106
95
|
const fks = [];
|
|
@@ -126,7 +115,12 @@ class SqlGenerator {
|
|
|
126
115
|
createTables() {
|
|
127
116
|
if (this.options.createTables) {
|
|
128
117
|
for (const table of this.tables) {
|
|
129
|
-
this.dmp.createTable(
|
|
118
|
+
this.dmp.createTable({
|
|
119
|
+
...table,
|
|
120
|
+
foreignKeys: [],
|
|
121
|
+
dependencies: [],
|
|
122
|
+
indexes: [],
|
|
123
|
+
});
|
|
130
124
|
if (this.checkDumper())
|
|
131
125
|
return;
|
|
132
126
|
}
|
|
@@ -137,18 +131,16 @@ class SqlGenerator {
|
|
|
137
131
|
}
|
|
138
132
|
}
|
|
139
133
|
}
|
|
140
|
-
insertData() {
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
async insertData() {
|
|
135
|
+
if (!this.options.insert)
|
|
136
|
+
return;
|
|
137
|
+
this.enableConstraints(false);
|
|
138
|
+
for (const table of this.tables) {
|
|
139
|
+
await this.insertTableData(table);
|
|
140
|
+
if (this.checkDumper())
|
|
143
141
|
return;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
yield this.insertTableData(table);
|
|
147
|
-
if (this.checkDumper())
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
this.enableConstraints(true);
|
|
151
|
-
});
|
|
142
|
+
}
|
|
143
|
+
this.enableConstraints(true);
|
|
152
144
|
}
|
|
153
145
|
checkDumper() {
|
|
154
146
|
if (this.dmp.s.length > 4000000) {
|
|
@@ -192,20 +184,18 @@ class SqlGenerator {
|
|
|
192
184
|
}
|
|
193
185
|
}
|
|
194
186
|
}
|
|
195
|
-
insertTableData(table) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
});
|
|
187
|
+
async insertTableData(table) {
|
|
188
|
+
const dmpLocal = this.driver.createDumper();
|
|
189
|
+
dmpLocal.put('^select * ^from %f', table);
|
|
190
|
+
const autoinc = table.columns.find(x => x.autoIncrement);
|
|
191
|
+
if (autoinc && !this.options.skipAutoincrementColumn) {
|
|
192
|
+
this.dmp.allowIdentityInsert(table, true);
|
|
193
|
+
}
|
|
194
|
+
const readable = await this.driver.readQuery(this.pool, dmpLocal.s, table);
|
|
195
|
+
await this.processReadable(table, readable);
|
|
196
|
+
if (autoinc && !this.options.skipAutoincrementColumn) {
|
|
197
|
+
this.dmp.allowIdentityInsert(table, false);
|
|
198
|
+
}
|
|
209
199
|
}
|
|
210
200
|
processReadable(table, readable) {
|
|
211
201
|
const columnsFiltered = this.options.skipAutoincrementColumn
|
package/lib/alterPlan.js
CHANGED
|
@@ -337,7 +337,10 @@ class AlterPlan {
|
|
|
337
337
|
existingRecreate.operations.push(...op.operations);
|
|
338
338
|
}
|
|
339
339
|
else {
|
|
340
|
-
const recreate =
|
|
340
|
+
const recreate = {
|
|
341
|
+
...op,
|
|
342
|
+
operations: [...op.operations],
|
|
343
|
+
};
|
|
341
344
|
res.push(recreate);
|
|
342
345
|
recreates[`${op.table.schemaName}||${op.table.pureName}`] = recreate;
|
|
343
346
|
}
|
|
@@ -367,7 +370,13 @@ class AlterPlan {
|
|
|
367
370
|
.map(op => {
|
|
368
371
|
if (op.operationType == 'createTable') {
|
|
369
372
|
fks.push(...(op.newObject.foreignKeys || []));
|
|
370
|
-
return
|
|
373
|
+
return {
|
|
374
|
+
...op,
|
|
375
|
+
newObject: {
|
|
376
|
+
...op.newObject,
|
|
377
|
+
foreignKeys: [],
|
|
378
|
+
},
|
|
379
|
+
};
|
|
371
380
|
}
|
|
372
381
|
return op;
|
|
373
382
|
});
|
package/lib/computeDiffRows.js
CHANGED
|
@@ -82,7 +82,17 @@ function computeDbDiffRows(sourceDb, targetDb, opts, driver) {
|
|
|
82
82
|
const defs = exports.DbDiffCompareDefs[objectTypeField];
|
|
83
83
|
res.push(...lodash_1.default.sortBy(computeDiffRowsCore(sourceDb[objectTypeField], targetDb[objectTypeField], (a, b) => defs.test(a, b, opts, sourceDb, targetDb, driver)).map(row => {
|
|
84
84
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
85
|
-
return (
|
|
85
|
+
return ({
|
|
86
|
+
...row,
|
|
87
|
+
sourceSchemaName: (_a = row === null || row === void 0 ? void 0 : row.source) === null || _a === void 0 ? void 0 : _a.schemaName,
|
|
88
|
+
sourcePureName: (_b = row === null || row === void 0 ? void 0 : row.source) === null || _b === void 0 ? void 0 : _b.pureName,
|
|
89
|
+
targetSchemaName: (_c = row === null || row === void 0 ? void 0 : row.target) === null || _c === void 0 ? void 0 : _c.schemaName,
|
|
90
|
+
targetPureName: (_d = row === null || row === void 0 ? void 0 : row.target) === null || _d === void 0 ? void 0 : _d.pureName,
|
|
91
|
+
typeName: defs.name,
|
|
92
|
+
typeIcon: defs.icon,
|
|
93
|
+
identifier: `${((_e = row === null || row === void 0 ? void 0 : row.source) === null || _e === void 0 ? void 0 : _e.schemaName) || ((_f = row === null || row === void 0 ? void 0 : row.target) === null || _f === void 0 ? void 0 : _f.schemaName)}.${((_g = row === null || row === void 0 ? void 0 : row.source) === null || _g === void 0 ? void 0 : _g.pureName) || ((_h = row === null || row === void 0 ? void 0 : row.target) === null || _h === void 0 ? void 0 : _h.pureName)}`,
|
|
94
|
+
objectTypeField,
|
|
95
|
+
});
|
|
86
96
|
}), 'identifier'));
|
|
87
97
|
}
|
|
88
98
|
return res;
|
|
@@ -93,7 +103,17 @@ function computeTableDiffColumns(sourceTable, targetTable, opts, driver) {
|
|
|
93
103
|
return [];
|
|
94
104
|
return computeDiffRowsCore((sourceTable === null || sourceTable === void 0 ? void 0 : sourceTable.columns) || [], (targetTable === null || targetTable === void 0 ? void 0 : targetTable.columns) || [], (a, b) => (0, diffTools_1.testEqualColumns)(a, b, true, true, opts)).map(row => {
|
|
95
105
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
96
|
-
return (
|
|
106
|
+
return ({
|
|
107
|
+
...row,
|
|
108
|
+
sourceColumnName: (_a = row === null || row === void 0 ? void 0 : row.source) === null || _a === void 0 ? void 0 : _a.columnName,
|
|
109
|
+
targetColumnName: (_b = row === null || row === void 0 ? void 0 : row.target) === null || _b === void 0 ? void 0 : _b.columnName,
|
|
110
|
+
sourceDataType: (_c = row === null || row === void 0 ? void 0 : row.source) === null || _c === void 0 ? void 0 : _c.dataType,
|
|
111
|
+
targetDataType: (_d = row === null || row === void 0 ? void 0 : row.target) === null || _d === void 0 ? void 0 : _d.dataType,
|
|
112
|
+
sourceAutoIncrement: (_e = row === null || row === void 0 ? void 0 : row.source) === null || _e === void 0 ? void 0 : _e.autoIncrement,
|
|
113
|
+
targetAutoIncrement: (_f = row === null || row === void 0 ? void 0 : row.target) === null || _f === void 0 ? void 0 : _f.autoIncrement,
|
|
114
|
+
sourceNotNull: (_g = row === null || row === void 0 ? void 0 : row.source) === null || _g === void 0 ? void 0 : _g.notNull,
|
|
115
|
+
targetNotNull: (_h = row === null || row === void 0 ? void 0 : row.target) === null || _h === void 0 ? void 0 : _h.notNull,
|
|
116
|
+
});
|
|
97
117
|
});
|
|
98
118
|
}
|
|
99
119
|
exports.computeTableDiffColumns = computeTableDiffColumns;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.createAsyncWriteStream = void 0;
|
|
13
4
|
const getLogger_1 = require("./getLogger");
|
|
@@ -16,15 +7,15 @@ function createAsyncWriteStream(stream, options) {
|
|
|
16
7
|
const writable = new stream.Writable({
|
|
17
8
|
objectMode: true,
|
|
18
9
|
});
|
|
19
|
-
writable._write = (chunk, encoding, callback) =>
|
|
10
|
+
writable._write = async (chunk, encoding, callback) => {
|
|
20
11
|
try {
|
|
21
|
-
|
|
12
|
+
await options.processItem(chunk);
|
|
22
13
|
callback(null);
|
|
23
14
|
}
|
|
24
15
|
catch (err) {
|
|
25
16
|
callback(err);
|
|
26
17
|
}
|
|
27
|
-
}
|
|
18
|
+
};
|
|
28
19
|
// writable._final = async callback => {
|
|
29
20
|
// callback();
|
|
30
21
|
// };
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -34,40 +25,40 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
34
25
|
writable.columnDataTypes = null;
|
|
35
26
|
writable.requireFixedStructure = driver.databaseEngineTypes.includes('sql');
|
|
36
27
|
writable.rowsReporter = new rowProgressReporter_1.RowProgressReporter(options.progressName);
|
|
37
|
-
writable.addRow = (row) =>
|
|
28
|
+
writable.addRow = async (row) => {
|
|
38
29
|
if (writable.structure) {
|
|
39
30
|
writable.buffer.push(row);
|
|
40
31
|
}
|
|
41
32
|
else {
|
|
42
33
|
writable.structure = row;
|
|
43
|
-
|
|
34
|
+
await writable.checkStructure();
|
|
44
35
|
}
|
|
45
|
-
}
|
|
46
|
-
writable.checkStructure = () =>
|
|
36
|
+
};
|
|
37
|
+
writable.checkStructure = async () => {
|
|
47
38
|
var _a;
|
|
48
39
|
try {
|
|
49
|
-
let structure = (_a = options.targetTableStructure) !== null && _a !== void 0 ? _a : (
|
|
40
|
+
let structure = (_a = options.targetTableStructure) !== null && _a !== void 0 ? _a : (await driver.analyseSingleTable(dbhan, name));
|
|
50
41
|
if (structure) {
|
|
51
42
|
writable.structure = structure;
|
|
52
43
|
}
|
|
53
44
|
if (structure && options.dropIfExists) {
|
|
54
45
|
logger.info(`Dropping table ${fullNameQuoted}`);
|
|
55
|
-
|
|
46
|
+
await driver.script(dbhan, `DROP TABLE ${fullNameQuoted}`);
|
|
56
47
|
}
|
|
57
48
|
if (options.createIfNotExists && (!structure || options.dropIfExists)) {
|
|
58
49
|
const dmp = driver.createDumper();
|
|
59
|
-
const createdTableInfo = driver.adaptTableInfo((0, tableTransforms_1.prepareTableForImport)(
|
|
50
|
+
const createdTableInfo = driver.adaptTableInfo((0, tableTransforms_1.prepareTableForImport)({ ...writable.structure, ...name }));
|
|
60
51
|
dmp.createTable(createdTableInfo);
|
|
61
52
|
logger.info({ sql: dmp.s }, `Creating table ${fullNameQuoted}`);
|
|
62
|
-
|
|
63
|
-
structure =
|
|
53
|
+
await driver.script(dbhan, dmp.s);
|
|
54
|
+
structure = await driver.analyseSingleTable(dbhan, name);
|
|
64
55
|
writable.structure = structure;
|
|
65
56
|
}
|
|
66
57
|
if (!writable.structure) {
|
|
67
58
|
throw new Error(`Error importing table - ${fullNameQuoted} not found`);
|
|
68
59
|
}
|
|
69
60
|
if (options.truncate) {
|
|
70
|
-
|
|
61
|
+
await driver.script(dbhan, `TRUNCATE TABLE ${fullNameQuoted}`);
|
|
71
62
|
}
|
|
72
63
|
writable.columnNames = (0, intersection_1.default)(structure.columns.map(x => x.columnName), writable.structure.columns.map(x => x.columnName));
|
|
73
64
|
writable.columnDataTypes = (0, fromPairs_1.default)(writable.columnNames.map(colName => {
|
|
@@ -82,8 +73,8 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
82
73
|
logger.error((0, stringTools_1.extractErrorLogData)(err), 'Error during preparing bulk insert table, stopped');
|
|
83
74
|
writable.destroy(err);
|
|
84
75
|
}
|
|
85
|
-
}
|
|
86
|
-
writable.send = () =>
|
|
76
|
+
};
|
|
77
|
+
writable.send = async () => {
|
|
87
78
|
const rows = writable.buffer;
|
|
88
79
|
writable.buffer = [];
|
|
89
80
|
try {
|
|
@@ -105,7 +96,7 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
105
96
|
// require('fs').writeFileSync('/home/jena/test.sql', dmp.s);
|
|
106
97
|
// console.log(dmp.s);
|
|
107
98
|
if (rows.length > 0) {
|
|
108
|
-
|
|
99
|
+
await driver.query(dbhan, dmp.s, { discardResult: true });
|
|
109
100
|
}
|
|
110
101
|
writable.rowsReporter.add(rows.length);
|
|
111
102
|
}
|
|
@@ -119,36 +110,36 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
|
|
|
119
110
|
dmp.putCollection(',', writable.columnNames, col => { var _a; return dmp.putValue(row[col], (_a = writable.columnDataTypes) === null || _a === void 0 ? void 0 : _a[col]); });
|
|
120
111
|
dmp.putRaw(')');
|
|
121
112
|
// console.log(dmp.s);
|
|
122
|
-
|
|
113
|
+
await driver.query(dbhan, dmp.s, { discardResult: true });
|
|
123
114
|
writable.rowsReporter.add(1);
|
|
124
115
|
}
|
|
125
116
|
}
|
|
126
117
|
if (options.commitAfterInsert) {
|
|
127
118
|
const dmp = driver.createDumper();
|
|
128
119
|
dmp.commitTransaction();
|
|
129
|
-
|
|
120
|
+
await driver.query(dbhan, dmp.s, { discardResult: true });
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
123
|
catch (err) {
|
|
133
124
|
logger.error((0, stringTools_1.extractErrorLogData)(err), 'Error during base bulk insert, insert stopped');
|
|
134
125
|
writable.destroy(err);
|
|
135
126
|
}
|
|
136
|
-
}
|
|
137
|
-
writable.sendIfFull = () =>
|
|
127
|
+
};
|
|
128
|
+
writable.sendIfFull = async () => {
|
|
138
129
|
if (writable.buffer.length > 100) {
|
|
139
|
-
|
|
130
|
+
await writable.send();
|
|
140
131
|
}
|
|
141
|
-
}
|
|
142
|
-
writable._write = (chunk, encoding, callback) =>
|
|
143
|
-
|
|
144
|
-
|
|
132
|
+
};
|
|
133
|
+
writable._write = async (chunk, encoding, callback) => {
|
|
134
|
+
await writable.addRow(chunk);
|
|
135
|
+
await writable.sendIfFull();
|
|
145
136
|
callback();
|
|
146
|
-
}
|
|
147
|
-
writable._final = (callback) =>
|
|
148
|
-
|
|
137
|
+
};
|
|
138
|
+
writable._final = async (callback) => {
|
|
139
|
+
await writable.send();
|
|
149
140
|
writable.rowsReporter.finish();
|
|
150
141
|
callback();
|
|
151
|
-
}
|
|
142
|
+
};
|
|
152
143
|
return writable;
|
|
153
144
|
}
|
|
154
145
|
exports.createBulkInsertStreamBase = createBulkInsertStreamBase;
|
package/lib/dbKeysLoader.js
CHANGED
|
@@ -86,10 +86,17 @@ exports.DB_KEYS_SHOW_INCREMENT = 100;
|
|
|
86
86
|
// };
|
|
87
87
|
// }
|
|
88
88
|
function dbKeys_mergeNextPage(tree, nextPage) {
|
|
89
|
-
const keyObjectsByKey =
|
|
89
|
+
const keyObjectsByKey = { ...tree.keyObjectsByKey };
|
|
90
90
|
for (const keyObj of nextPage.keys) {
|
|
91
91
|
const keyPath = keyObj.key.split(tree.treeKeySeparator);
|
|
92
|
-
keyObjectsByKey[keyObj.key] =
|
|
92
|
+
keyObjectsByKey[keyObj.key] = {
|
|
93
|
+
...keyObj,
|
|
94
|
+
level: keyPath.length,
|
|
95
|
+
text: keyPath[keyPath.length - 1],
|
|
96
|
+
sortKey: keyPath[keyPath.length - 1],
|
|
97
|
+
keyPath,
|
|
98
|
+
parentKey: keyPath.slice(0, -1).join(tree.treeKeySeparator),
|
|
99
|
+
};
|
|
93
100
|
}
|
|
94
101
|
const dirsByKey = {};
|
|
95
102
|
const childrenByKey = {};
|
|
@@ -133,20 +140,45 @@ function dbKeys_mergeNextPage(tree, nextPage) {
|
|
|
133
140
|
for (const key in childrenByKey) {
|
|
134
141
|
childrenByKey[key] = (0, sortBy_1.default)(childrenByKey[key], 'sortKey');
|
|
135
142
|
}
|
|
136
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
...tree,
|
|
145
|
+
cursor: nextPage.nextCursor,
|
|
146
|
+
dirsByKey,
|
|
137
147
|
childrenByKey,
|
|
138
|
-
keyObjectsByKey,
|
|
148
|
+
keyObjectsByKey,
|
|
149
|
+
scannedKeys: tree.scannedKeys + tree.loadCount,
|
|
150
|
+
loadedAll: nextPage.nextCursor == '0',
|
|
151
|
+
dbsize: nextPage.dbsize,
|
|
152
|
+
};
|
|
139
153
|
}
|
|
140
154
|
exports.dbKeys_mergeNextPage = dbKeys_mergeNextPage;
|
|
141
155
|
function dbKeys_markNodeExpanded(tree, root, isExpanded) {
|
|
142
156
|
const node = tree.dirStateByKey[root];
|
|
143
|
-
return
|
|
157
|
+
return {
|
|
158
|
+
...tree,
|
|
159
|
+
dirStateByKey: {
|
|
160
|
+
...tree.dirStateByKey,
|
|
161
|
+
[root]: {
|
|
162
|
+
...node,
|
|
163
|
+
isExpanded,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
};
|
|
144
167
|
}
|
|
145
168
|
exports.dbKeys_markNodeExpanded = dbKeys_markNodeExpanded;
|
|
146
169
|
function dbKeys_showNextItems(tree, root) {
|
|
147
170
|
var _a;
|
|
148
171
|
const node = tree.dirStateByKey[root];
|
|
149
|
-
return
|
|
172
|
+
return {
|
|
173
|
+
...tree,
|
|
174
|
+
dirStateByKey: {
|
|
175
|
+
...tree.dirStateByKey,
|
|
176
|
+
[root]: {
|
|
177
|
+
...node,
|
|
178
|
+
visibleCount: ((_a = node === null || node === void 0 ? void 0 : node.visibleCount) !== null && _a !== void 0 ? _a : exports.DB_KEYS_SHOW_INCREMENT) + exports.DB_KEYS_SHOW_INCREMENT,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
150
182
|
}
|
|
151
183
|
exports.dbKeys_showNextItems = dbKeys_showNextItems;
|
|
152
184
|
function dbKeys_createNewModel(treeKeySeparator) {
|
|
@@ -182,9 +214,18 @@ function dbKeys_createNewModel(treeKeySeparator) {
|
|
|
182
214
|
}
|
|
183
215
|
exports.dbKeys_createNewModel = dbKeys_createNewModel;
|
|
184
216
|
function dbKeys_clearLoadedData(tree) {
|
|
185
|
-
return
|
|
217
|
+
return {
|
|
218
|
+
...tree,
|
|
219
|
+
childrenByKey: {},
|
|
220
|
+
keyObjectsByKey: {},
|
|
221
|
+
dirsByKey: {
|
|
186
222
|
'': tree.root,
|
|
187
|
-
},
|
|
223
|
+
},
|
|
224
|
+
scannedKeys: 0,
|
|
225
|
+
dbsize: 0,
|
|
226
|
+
cursor: '0',
|
|
227
|
+
loadedAll: false,
|
|
228
|
+
};
|
|
188
229
|
}
|
|
189
230
|
exports.dbKeys_clearLoadedData = dbKeys_clearLoadedData;
|
|
190
231
|
// export function dbKeys_reloadFolder(tree: DbKeysTreeModel, root: string): DbKeysTreeModel {
|