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/diffTools.js CHANGED
@@ -18,7 +18,38 @@ function generateTablePairingId(table) {
18
18
  if (!table)
19
19
  return table;
20
20
  if (!table.pairingId) {
21
- return Object.assign(Object.assign({}, table), { primaryKey: table.primaryKey && Object.assign(Object.assign({}, table.primaryKey), { pairingId: table.primaryKey.pairingId || (0, v1_1.default)() }), sortingKey: table.sortingKey && Object.assign(Object.assign({}, table.sortingKey), { pairingId: table.sortingKey.pairingId || (0, v1_1.default)() }), columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { pairingId: col.pairingId || (0, v1_1.default)() }))), foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: cnt.pairingId || (0, v1_1.default)() }))), pairingId: table.pairingId || (0, v1_1.default)() });
21
+ return {
22
+ ...table,
23
+ primaryKey: table.primaryKey && {
24
+ ...table.primaryKey,
25
+ pairingId: table.primaryKey.pairingId || (0, v1_1.default)(),
26
+ },
27
+ sortingKey: table.sortingKey && {
28
+ ...table.sortingKey,
29
+ pairingId: table.sortingKey.pairingId || (0, v1_1.default)(),
30
+ },
31
+ columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => ({
32
+ ...col,
33
+ pairingId: col.pairingId || (0, v1_1.default)(),
34
+ })),
35
+ foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => ({
36
+ ...cnt,
37
+ pairingId: cnt.pairingId || (0, v1_1.default)(),
38
+ })),
39
+ checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => ({
40
+ ...cnt,
41
+ pairingId: cnt.pairingId || (0, v1_1.default)(),
42
+ })),
43
+ indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => ({
44
+ ...cnt,
45
+ pairingId: cnt.pairingId || (0, v1_1.default)(),
46
+ })),
47
+ uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => ({
48
+ ...cnt,
49
+ pairingId: cnt.pairingId || (0, v1_1.default)(),
50
+ })),
51
+ pairingId: table.pairingId || (0, v1_1.default)(),
52
+ };
22
53
  }
23
54
  return table;
24
55
  }
@@ -27,7 +58,30 @@ function removeTablePairingId(table) {
27
58
  var _a, _b, _c, _d, _e;
28
59
  if (!table)
29
60
  return table;
30
- return Object.assign(Object.assign({}, table), { columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { pairingId: undefined }))), foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: undefined }))), checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: undefined }))), indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: undefined }))), uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => (Object.assign(Object.assign({}, cnt), { pairingId: undefined }))), pairingId: undefined });
61
+ return {
62
+ ...table,
63
+ columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => ({
64
+ ...col,
65
+ pairingId: undefined,
66
+ })),
67
+ foreignKeys: (_b = table.foreignKeys) === null || _b === void 0 ? void 0 : _b.map(cnt => ({
68
+ ...cnt,
69
+ pairingId: undefined,
70
+ })),
71
+ checks: (_c = table.checks) === null || _c === void 0 ? void 0 : _c.map(cnt => ({
72
+ ...cnt,
73
+ pairingId: undefined,
74
+ })),
75
+ indexes: (_d = table.indexes) === null || _d === void 0 ? void 0 : _d.map(cnt => ({
76
+ ...cnt,
77
+ pairingId: undefined,
78
+ })),
79
+ uniques: (_e = table.uniques) === null || _e === void 0 ? void 0 : _e.map(cnt => ({
80
+ ...cnt,
81
+ pairingId: undefined,
82
+ })),
83
+ pairingId: undefined,
84
+ };
31
85
  }
32
86
  exports.removeTablePairingId = removeTablePairingId;
33
87
  function simplifySqlExpression(sql) {
@@ -38,16 +92,27 @@ function simplifySqlExpression(sql) {
38
92
  }
39
93
  function generateObjectPairingId(obj) {
40
94
  if (obj.objectTypeField)
41
- return Object.assign(Object.assign({}, obj), { pairingId: obj.pairingId || (0, v1_1.default)() });
95
+ return {
96
+ ...obj,
97
+ pairingId: obj.pairingId || (0, v1_1.default)(),
98
+ };
42
99
  return obj;
43
100
  }
44
101
  function generateDbPairingId(db) {
45
102
  var _a, _b, _c, _d, _e, _f, _g;
46
103
  if (!db)
47
104
  return db;
48
- return Object.assign(Object.assign({}, db), {
105
+ return {
106
+ ...db,
49
107
  // ..._.mapValues(db, v => (_.isArray(v) ? v.map(generateObjectPairingId) : v)),
50
- tables: (_a = db.tables) === null || _a === void 0 ? void 0 : _a.map(generateTablePairingId), views: (_b = db.views) === null || _b === void 0 ? void 0 : _b.map(generateObjectPairingId), procedures: (_c = db.procedures) === null || _c === void 0 ? void 0 : _c.map(generateObjectPairingId), functions: (_d = db.functions) === null || _d === void 0 ? void 0 : _d.map(generateObjectPairingId), triggers: (_e = db.triggers) === null || _e === void 0 ? void 0 : _e.map(generateObjectPairingId), schedulerEvents: (_f = db.schedulerEvents) === null || _f === void 0 ? void 0 : _f.map(generateObjectPairingId), matviews: (_g = db.matviews) === null || _g === void 0 ? void 0 : _g.map(generateObjectPairingId) });
108
+ tables: (_a = db.tables) === null || _a === void 0 ? void 0 : _a.map(generateTablePairingId),
109
+ views: (_b = db.views) === null || _b === void 0 ? void 0 : _b.map(generateObjectPairingId),
110
+ procedures: (_c = db.procedures) === null || _c === void 0 ? void 0 : _c.map(generateObjectPairingId),
111
+ functions: (_d = db.functions) === null || _d === void 0 ? void 0 : _d.map(generateObjectPairingId),
112
+ triggers: (_e = db.triggers) === null || _e === void 0 ? void 0 : _e.map(generateObjectPairingId),
113
+ schedulerEvents: (_f = db.schedulerEvents) === null || _f === void 0 ? void 0 : _f.map(generateObjectPairingId),
114
+ matviews: (_g = db.matviews) === null || _g === void 0 ? void 0 : _g.map(generateObjectPairingId),
115
+ };
51
116
  }
52
117
  exports.generateDbPairingId = generateDbPairingId;
53
118
  function getNameWithoutDeletedPrefix(name, opts, deletedPrefix) {
@@ -409,7 +474,10 @@ function planAlterTable(plan, oldTable, newTable, opts) {
409
474
  if (hasDeletedPrefix(srccol.columnName, opts, opts.deletedColumnPrefix)) {
410
475
  plan.renameColumn(srccol, dstcol.columnName);
411
476
  // rename is already done
412
- srccol = Object.assign(Object.assign({}, srccol), { columnName: dstcol.columnName });
477
+ srccol = {
478
+ ...srccol,
479
+ columnName: dstcol.columnName,
480
+ };
413
481
  }
414
482
  if (!testEqualColumns(srccol, dstcol, true, true, opts)) {
415
483
  if (testEqualColumns(srccol, dstcol, false, true, opts) && !opts.noRenameColumn) {
package/lib/driverBase.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
  };
@@ -38,32 +29,28 @@ const dialect = {
38
29
  },
39
30
  defaultSchemaName: null,
40
31
  };
41
- function runCommandOnDriver(pool, driver, cmd) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const dmp = driver.createDumper();
44
- if ((0, isString_1.default)(cmd)) {
45
- dmp.put(cmd);
46
- }
47
- else {
48
- cmd(dmp);
49
- }
50
- // console.log('CMD:', dmp.s);
51
- yield driver.query(pool, dmp.s, { discardResult: true });
52
- });
32
+ async function runCommandOnDriver(pool, driver, cmd) {
33
+ const dmp = driver.createDumper();
34
+ if ((0, isString_1.default)(cmd)) {
35
+ dmp.put(cmd);
36
+ }
37
+ else {
38
+ cmd(dmp);
39
+ }
40
+ // console.log('CMD:', dmp.s);
41
+ await driver.query(pool, dmp.s, { discardResult: true });
53
42
  }
54
43
  exports.runCommandOnDriver = runCommandOnDriver;
55
- function runQueryOnDriver(pool, driver, cmd) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const dmp = driver.createDumper();
58
- if ((0, isString_1.default)(cmd)) {
59
- dmp.put(cmd);
60
- }
61
- else {
62
- cmd(dmp);
63
- }
64
- // console.log('QUERY:', dmp.s);
65
- return yield driver.query(pool, dmp.s);
66
- });
44
+ async function runQueryOnDriver(pool, driver, cmd) {
45
+ const dmp = driver.createDumper();
46
+ if ((0, isString_1.default)(cmd)) {
47
+ dmp.put(cmd);
48
+ }
49
+ else {
50
+ cmd(dmp);
51
+ }
52
+ // console.log('QUERY:', dmp.s);
53
+ return await driver.query(pool, dmp.s);
67
54
  }
68
55
  exports.runQueryOnDriver = runQueryOnDriver;
69
56
  function formatQueryWithoutParams(driver, sql) {
@@ -72,12 +59,10 @@ function formatQueryWithoutParams(driver, sql) {
72
59
  return dmp.s;
73
60
  }
74
61
  exports.formatQueryWithoutParams = formatQueryWithoutParams;
75
- function runQueryFmt(driver, conn, query, ...args) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- const dmp = driver.createDumper();
78
- dmp.put(query, ...args);
79
- yield driver.query(conn, dmp.s);
80
- });
62
+ async function runQueryFmt(driver, conn, query, ...args) {
63
+ const dmp = driver.createDumper();
64
+ dmp.put(query, ...args);
65
+ await driver.query(conn, dmp.s);
81
66
  }
82
67
  exports.runQueryFmt = runQueryFmt;
83
68
  exports.driverBase = {
@@ -86,68 +71,58 @@ exports.driverBase = {
86
71
  dialect,
87
72
  databaseEngineTypes: ['sql'],
88
73
  supportedCreateDatabase: true,
89
- analyseFull(pool, version) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const analyser = new this.analyserClass(pool, this, version);
92
- return analyser.fullAnalysis();
93
- });
74
+ async analyseFull(pool, version) {
75
+ const analyser = new this.analyserClass(pool, this, version);
76
+ return analyser.fullAnalysis();
94
77
  },
95
- analyseSingleObject(pool, name, typeField = 'tables') {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- const analyser = new this.analyserClass(pool, this);
98
- return analyser.singleObjectAnalysis(name, typeField);
99
- });
78
+ async analyseSingleObject(pool, name, typeField = 'tables') {
79
+ const analyser = new this.analyserClass(pool, this);
80
+ return analyser.singleObjectAnalysis(name, typeField);
100
81
  },
101
82
  analyseSingleTable(pool, name) {
102
83
  return this.analyseSingleObject(pool, name, 'tables');
103
84
  },
104
- analyseIncremental(pool, structure, version) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const analyser = new this.analyserClass(pool, this, version);
107
- return analyser.incrementalAnalysis(structure);
108
- });
85
+ async analyseIncremental(pool, structure, version) {
86
+ const analyser = new this.analyserClass(pool, this, version);
87
+ return analyser.incrementalAnalysis(structure);
109
88
  },
110
89
  createDumper(options = null) {
111
90
  return new this.dumperClass(this, options);
112
91
  },
113
- script(pool, sql, options) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
116
- runCommandOnDriver(pool, this, dmp => dmp.beginTransaction());
117
- }
118
- for (const sqlItem of (0, dbgate_query_splitter_1.splitQuery)(sql, this.getQuerySplitterOptions('script'))) {
119
- try {
120
- if (options === null || options === void 0 ? void 0 : options.logScriptItems) {
121
- logger.info({ sql: (0, stringTools_1.getLimitedQuery)(sqlItem) }, 'Execute script item');
122
- }
123
- yield this.query(pool, sqlItem, Object.assign({ discardResult: true }, options === null || options === void 0 ? void 0 : options.queryOptions));
124
- }
125
- catch (err) {
126
- if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
127
- runCommandOnDriver(pool, this, dmp => dmp.rollbackTransaction());
128
- }
129
- throw err;
92
+ async script(pool, sql, options) {
93
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
94
+ runCommandOnDriver(pool, this, dmp => dmp.beginTransaction());
95
+ }
96
+ for (const sqlItem of (0, dbgate_query_splitter_1.splitQuery)(sql, this.getQuerySplitterOptions('script'))) {
97
+ try {
98
+ if (options === null || options === void 0 ? void 0 : options.logScriptItems) {
99
+ logger.info({ sql: (0, stringTools_1.getLimitedQuery)(sqlItem) }, 'Execute script item');
130
100
  }
101
+ await this.query(pool, sqlItem, { discardResult: true, ...options === null || options === void 0 ? void 0 : options.queryOptions });
131
102
  }
132
- if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
133
- runCommandOnDriver(pool, this, dmp => dmp.commitTransaction());
103
+ catch (err) {
104
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
105
+ runCommandOnDriver(pool, this, dmp => dmp.rollbackTransaction());
106
+ }
107
+ throw err;
134
108
  }
135
- });
109
+ }
110
+ if ((options === null || options === void 0 ? void 0 : options.useTransaction) && this.supportsTransactions) {
111
+ runCommandOnDriver(pool, this, dmp => dmp.commitTransaction());
112
+ }
136
113
  },
137
- operation(pool, operation, options) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const { type } = operation;
140
- switch (type) {
141
- case 'createSchema':
142
- yield runCommandOnDriver(pool, this, dmp => dmp.createSchema(operation.schemaName));
143
- break;
144
- case 'dropSchema':
145
- yield runCommandOnDriver(pool, this, dmp => dmp.dropSchema(operation.schemaName));
146
- break;
147
- default:
148
- throw new Error(`Operation type ${type} not supported`);
149
- }
150
- });
114
+ async operation(pool, operation, options) {
115
+ const { type } = operation;
116
+ switch (type) {
117
+ case 'createSchema':
118
+ await runCommandOnDriver(pool, this, dmp => dmp.createSchema(operation.schemaName));
119
+ break;
120
+ case 'dropSchema':
121
+ await runCommandOnDriver(pool, this, dmp => dmp.dropSchema(operation.schemaName));
122
+ break;
123
+ default:
124
+ throw new Error(`Operation type ${type} not supported`);
125
+ }
151
126
  },
152
127
  getNewObjectTemplates() {
153
128
  if (this.databaseEngineTypes.includes('sql')) {
@@ -155,66 +130,64 @@ exports.driverBase = {
155
130
  }
156
131
  return [];
157
132
  },
158
- loadFieldValues(pool, name, columnName, search, dataType) {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- const dmp = this.createDumper();
161
- let expr;
162
- if (this.dialect.createColumnViewExpression) {
163
- expr = this.dialect.createColumnViewExpression(columnName, dataType, { name }, 'value');
164
- }
165
- if (!expr) {
166
- expr = {
133
+ async loadFieldValues(pool, name, columnName, search, dataType) {
134
+ const dmp = this.createDumper();
135
+ let expr;
136
+ if (this.dialect.createColumnViewExpression) {
137
+ expr = this.dialect.createColumnViewExpression(columnName, dataType, { name }, 'value');
138
+ }
139
+ if (!expr) {
140
+ expr = {
141
+ exprType: 'column',
142
+ columnName,
143
+ alias: 'value',
144
+ };
145
+ }
146
+ const select = {
147
+ commandType: 'select',
148
+ distinct: true,
149
+ from: {
150
+ name,
151
+ },
152
+ columns: [expr],
153
+ orderBy: [
154
+ {
167
155
  exprType: 'column',
168
156
  columnName,
169
- alias: 'value',
170
- };
171
- }
172
- const select = {
173
- commandType: 'select',
174
- distinct: true,
175
- from: {
176
- name,
157
+ direction: 'ASC',
177
158
  },
178
- columns: [expr],
179
- orderBy: [
180
- {
181
- exprType: 'column',
182
- columnName,
183
- direction: 'ASC',
184
- },
185
- ],
186
- };
187
- if (this.dialect.topRecords) {
188
- select.topRecords = 100;
189
- }
190
- else {
191
- select.range = { offset: 0, limit: 100 };
192
- }
193
- if (search) {
194
- const tokens = (0, compact_1.default)(search.split(' ').map(x => x.trim()));
195
- if (tokens.length > 0) {
196
- // @ts-ignore
197
- select.where = {
198
- conditionType: 'and',
199
- conditions: tokens.map(token => ({
200
- conditionType: 'like',
201
- left: {
202
- exprType: 'column',
203
- columnName,
204
- },
205
- right: {
206
- exprType: 'value',
207
- value: `%${token}%`,
208
- },
209
- })),
210
- };
211
- }
159
+ ],
160
+ };
161
+ if (this.dialect.topRecords) {
162
+ select.topRecords = 100;
163
+ }
164
+ else {
165
+ select.range = { offset: 0, limit: 100 };
166
+ }
167
+ if (search) {
168
+ const tokens = (0, compact_1.default)(search.split(' ').map(x => x.trim()));
169
+ if (tokens.length > 0) {
170
+ // @ts-ignore
171
+ select.where = {
172
+ conditionType: 'and',
173
+ conditions: tokens.map(token => ({
174
+ conditionType: 'like',
175
+ left: {
176
+ exprType: 'column',
177
+ columnName,
178
+ },
179
+ right: {
180
+ exprType: 'value',
181
+ value: `%${token}%`,
182
+ },
183
+ })),
184
+ };
212
185
  }
213
- // @ts-ignore
214
- (0, dbgate_sqltree_1.dumpSqlSelect)(dmp, select);
215
- const resp = yield this.query(pool, dmp.s);
216
- return resp.rows;
217
- });
186
+ }
187
+ // @ts-ignore
188
+ (0, dbgate_sqltree_1.dumpSqlSelect)(dmp, select);
189
+ const resp = await this.query(pool, dmp.s);
190
+ return resp.rows;
218
191
  },
219
192
  readJsonQuery(pool, select, structure) {
220
193
  const dmp = this.createDumper();
@@ -223,7 +196,7 @@ exports.driverBase = {
223
196
  },
224
197
  showConnectionField: (field, values) => false,
225
198
  showConnectionTab: field => true,
226
- getAccessTokenFromAuth: (connection, req) => __awaiter(void 0, void 0, void 0, function* () { return null; }),
199
+ getAccessTokenFromAuth: async (connection, req) => null,
227
200
  getFilterBehaviour(dataType, standardFilterBehaviours) {
228
201
  return (0, detectSqlFilterBehaviour_1.detectSqlFilterBehaviour)(dataType);
229
202
  },
@@ -251,16 +224,18 @@ exports.driverBase = {
251
224
  },
252
225
  adaptTableInfo(table) {
253
226
  var _a;
254
- return Object.assign(Object.assign({}, table), { columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => (Object.assign(Object.assign({}, col), { dataType: this.adaptDataType(col.dataType) }))) });
255
- },
256
- listSchemas(pool) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- return null;
259
- });
227
+ return {
228
+ ...table,
229
+ columns: (_a = table.columns) === null || _a === void 0 ? void 0 : _a.map(col => ({
230
+ ...col,
231
+ dataType: this.adaptDataType(col.dataType),
232
+ })),
233
+ };
234
+ },
235
+ async listSchemas(pool) {
236
+ return null;
260
237
  },
261
- writeQueryFromStream(dbhan, sql) {
262
- return __awaiter(this, void 0, void 0, function* () {
263
- return null;
264
- });
238
+ async writeQueryFromStream(dbhan, sql) {
239
+ return null;
265
240
  },
266
241
  };
package/lib/getLogger.js CHANGED
@@ -29,7 +29,13 @@ function getLogger(caller) {
29
29
  if (_name) {
30
30
  props['name'] = _name;
31
31
  }
32
- return Object.assign(Object.assign({}, config), { base: Object.assign(Object.assign({}, config.base), props) });
32
+ return {
33
+ ...config,
34
+ base: {
35
+ ...config.base,
36
+ ...props,
37
+ },
38
+ };
33
39
  }
34
40
  return config;
35
41
  },
@@ -1,50 +1,46 @@
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
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.enrichWithPreloadedRows = void 0;
16
7
  const lodash_1 = __importDefault(require("lodash"));
17
- function enrichWithPreloadedRows(dbModel, dbTarget, conn, driver) {
8
+ async function enrichWithPreloadedRows(dbModel, dbTarget, conn, driver) {
18
9
  var _a, _b, _c;
19
- return __awaiter(this, void 0, void 0, function* () {
20
- // const res = { ...dbTarget, tables: [...(dbTarget.tables || [])] };
21
- const repl = {};
22
- for (const tableTarget of dbTarget.tables) {
23
- const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId);
24
- if ((((_a = tableModel === null || tableModel === void 0 ? void 0 : tableModel.preloadedRows) === null || _a === void 0 ? void 0 : _a.length) || 0) == 0)
25
- continue;
26
- const keyColumns = tableModel.preloadedRowsKey || ((_c = (_b = tableModel.primaryKey) === null || _b === void 0 ? void 0 : _b.columns) === null || _c === void 0 ? void 0 : _c.map(x => x.columnName));
27
- if (((keyColumns === null || keyColumns === void 0 ? void 0 : keyColumns.length) || 0) == 0)
28
- continue;
29
- const dmp = driver.createDumper();
30
- if (keyColumns.length == 1) {
31
- dmp.putCmd('^select * ^from %f ^where %i ^in (%,v)', tableTarget, keyColumns[0], tableModel.preloadedRows.map(x => x[keyColumns[0]]));
32
- }
33
- else {
34
- dmp.put('^select * ^from %f ^where', tableTarget);
35
- dmp.putCollection(' ^or ', tableModel.preloadedRows, row => {
36
- dmp.put('(');
37
- dmp.putCollection(' ^and ', keyColumns, col => dmp.put('%i=%v', col, row[col]));
38
- dmp.put(')');
39
- });
40
- dmp.endCommand();
41
- }
42
- const resp = yield driver.query(conn, dmp.s);
43
- repl[tableTarget.pairingId] = Object.assign(Object.assign({}, tableTarget), { preloadedRows: resp.rows, preloadedRowsKey: keyColumns });
10
+ // const res = { ...dbTarget, tables: [...(dbTarget.tables || [])] };
11
+ const repl = {};
12
+ for (const tableTarget of dbTarget.tables) {
13
+ const tableModel = dbModel.tables.find(x => x.pairingId == tableTarget.pairingId);
14
+ if ((((_a = tableModel === null || tableModel === void 0 ? void 0 : tableModel.preloadedRows) === null || _a === void 0 ? void 0 : _a.length) || 0) == 0)
15
+ continue;
16
+ const keyColumns = tableModel.preloadedRowsKey || ((_c = (_b = tableModel.primaryKey) === null || _b === void 0 ? void 0 : _b.columns) === null || _c === void 0 ? void 0 : _c.map(x => x.columnName));
17
+ if (((keyColumns === null || keyColumns === void 0 ? void 0 : keyColumns.length) || 0) == 0)
18
+ continue;
19
+ const dmp = driver.createDumper();
20
+ if (keyColumns.length == 1) {
21
+ dmp.putCmd('^select * ^from %f ^where %i ^in (%,v)', tableTarget, keyColumns[0], tableModel.preloadedRows.map(x => x[keyColumns[0]]));
22
+ }
23
+ else {
24
+ dmp.put('^select * ^from %f ^where', tableTarget);
25
+ dmp.putCollection(' ^or ', tableModel.preloadedRows, row => {
26
+ dmp.put('(');
27
+ dmp.putCollection(' ^and ', keyColumns, col => dmp.put('%i=%v', col, row[col]));
28
+ dmp.put(')');
29
+ });
30
+ dmp.endCommand();
44
31
  }
45
- if (lodash_1.default.isEmpty(repl))
46
- return dbTarget;
47
- return Object.assign(Object.assign({}, dbTarget), { tables: dbTarget.tables.map(x => repl[x.pairingId] || x) });
48
- });
32
+ const resp = await driver.query(conn, dmp.s);
33
+ repl[tableTarget.pairingId] = {
34
+ ...tableTarget,
35
+ preloadedRows: resp.rows,
36
+ preloadedRowsKey: keyColumns,
37
+ };
38
+ }
39
+ if (lodash_1.default.isEmpty(repl))
40
+ return dbTarget;
41
+ return {
42
+ ...dbTarget,
43
+ tables: dbTarget.tables.map(x => repl[x.pairingId] || x),
44
+ };
49
45
  }
50
46
  exports.enrichWithPreloadedRows = enrichWithPreloadedRows;