dbgate-tools 6.0.0 → 6.1.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.
@@ -339,7 +339,7 @@ class DatabaseAnalyser {
339
339
  };
340
340
  }
341
341
  static byTableFilter(table) {
342
- return x => x.pureName == table.pureName && x.schemaName == x.schemaName;
342
+ return x => x.pureName == table.pureName && x.schemaName == table.schemaName;
343
343
  }
344
344
  static extractPrimaryKeys(table, pkColumns) {
345
345
  const filtered = pkColumns.filter(DatabaseAnalyser.byTableFilter(table));
package/lib/diffTools.js CHANGED
@@ -519,7 +519,7 @@ function sortViewsByDependency(views) {
519
519
  }
520
520
  function createAlterDatabasePlan(oldDb, newDb, opts, wholeOldDb, wholeNewDb, driver) {
521
521
  const plan = new alterPlan_1.AlterPlan(wholeOldDb, wholeNewDb, driver.dialect, opts);
522
- for (const objectTypeField of ['tables', 'views', 'procedures', 'matviews', 'functions']) {
522
+ for (const objectTypeField of ['tables', 'views', 'procedures', 'matviews', 'functions', 'triggers']) {
523
523
  for (const oldobj of oldDb[objectTypeField] || []) {
524
524
  const newobj = (newDb[objectTypeField] || []).find(x => x.pairingId == oldobj.pairingId);
525
525
  if (objectTypeField == 'tables') {
@@ -1,7 +1,8 @@
1
1
  import { SqlDumper } from './SqlDumper';
2
2
  import { EngineDriver, QueryResult, RunScriptOptions } from 'dbgate-types';
3
- export declare function runCommandOnDriver(pool: any, driver: EngineDriver, cmd: (dmp: SqlDumper) => void): Promise<void>;
3
+ export declare function runCommandOnDriver(pool: any, driver: EngineDriver, cmd: (dmp: SqlDumper) => void | string): Promise<void>;
4
4
  export declare function runQueryOnDriver(pool: any, driver: EngineDriver, cmd: (dmp: SqlDumper) => void): Promise<QueryResult>;
5
+ export declare function formatQueryWithoutParams(driver: EngineDriver, sql: string): string;
5
6
  export declare const driverBase: {
6
7
  analyserClass: any;
7
8
  dumperClass: typeof SqlDumper;
package/lib/driverBase.js CHANGED
@@ -12,8 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.driverBase = exports.runQueryOnDriver = exports.runCommandOnDriver = void 0;
15
+ exports.driverBase = exports.formatQueryWithoutParams = exports.runQueryOnDriver = exports.runCommandOnDriver = void 0;
16
16
  const compact_1 = __importDefault(require("lodash/compact"));
17
+ const isString_1 = __importDefault(require("lodash/isString"));
17
18
  const SqlDumper_1 = require("./SqlDumper");
18
19
  const dbgate_query_splitter_1 = require("dbgate-query-splitter");
19
20
  const dbgate_sqltree_1 = require("dbgate-sqltree");
@@ -40,7 +41,12 @@ const dialect = {
40
41
  function runCommandOnDriver(pool, driver, cmd) {
41
42
  return __awaiter(this, void 0, void 0, function* () {
42
43
  const dmp = driver.createDumper();
43
- cmd(dmp);
44
+ if ((0, isString_1.default)(cmd)) {
45
+ dmp.put(cmd);
46
+ }
47
+ else {
48
+ cmd(dmp);
49
+ }
44
50
  // console.log('CMD:', dmp.s);
45
51
  yield driver.query(pool, dmp.s, { discardResult: true });
46
52
  });
@@ -49,12 +55,23 @@ exports.runCommandOnDriver = runCommandOnDriver;
49
55
  function runQueryOnDriver(pool, driver, cmd) {
50
56
  return __awaiter(this, void 0, void 0, function* () {
51
57
  const dmp = driver.createDumper();
52
- cmd(dmp);
58
+ if ((0, isString_1.default)(cmd)) {
59
+ dmp.put(cmd);
60
+ }
61
+ else {
62
+ cmd(dmp);
63
+ }
53
64
  // console.log('QUERY:', dmp.s);
54
65
  return yield driver.query(pool, dmp.s);
55
66
  });
56
67
  }
57
68
  exports.runQueryOnDriver = runQueryOnDriver;
69
+ function formatQueryWithoutParams(driver, sql) {
70
+ const dmp = driver.createDumper();
71
+ dmp.put(sql);
72
+ return dmp.s;
73
+ }
74
+ exports.formatQueryWithoutParams = formatQueryWithoutParams;
58
75
  exports.driverBase = {
59
76
  analyserClass: null,
60
77
  dumperClass: SqlDumper_1.SqlDumper,
@@ -1,4 +1,6 @@
1
- export interface FilterNameDefinition {
2
- childName: string;
3
- }
4
- export declare function filterName(filter: string, ...names: (string | FilterNameDefinition)[]): boolean;
1
+ export declare function filterName(filter: string, ...names: string[]): boolean;
2
+ export declare function filterNameCompoud(filter: string, namesMain: string[], namesChild: string[]): 'main' | 'child' | 'both' | 'none';
3
+ export declare function tokenizeBySearchFilter(text: string, filter: string): {
4
+ text: string;
5
+ isMatch: boolean;
6
+ }[];
package/lib/filterName.js CHANGED
@@ -3,10 +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.filterName = void 0;
6
+ exports.tokenizeBySearchFilter = exports.filterNameCompoud = exports.filterName = void 0;
7
7
  const compact_1 = __importDefault(require("lodash/compact"));
8
- const isString_1 = __importDefault(require("lodash/isString"));
9
8
  const startCase_1 = __importDefault(require("lodash/startCase"));
9
+ // export interface FilterNameDefinition {
10
+ // childName: string;
11
+ // }
10
12
  function camelMatch(filter, text) {
11
13
  if (!text)
12
14
  return false;
@@ -28,24 +30,129 @@ function filterName(filter, ...names) {
28
30
  // const camelVariants = [name.replace(/[^A-Z]/g, '')]
29
31
  const tokens = filter.split(' ').map(x => x.trim());
30
32
  const namesCompacted = (0, compact_1.default)(names);
31
- // @ts-ignore
32
- const namesOwn = namesCompacted.filter(x => (0, isString_1.default)(x));
33
- // @ts-ignore
34
- const namesChild = namesCompacted.filter(x => x.childName).map(x => x.childName);
35
33
  for (const token of tokens) {
36
- // const tokenUpper = token.toUpperCase();
37
- if (token.startsWith('#')) {
38
- // const tokenUpperSub = tokenUpper.substring(1);
39
- const found = namesChild.find(name => camelMatch(token.substring(1), name));
40
- if (!found)
41
- return false;
34
+ const found = namesCompacted.find(name => camelMatch(token, name));
35
+ if (!found)
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+ exports.filterName = filterName;
41
+ function filterNameCompoud(filter, namesMain, namesChild) {
42
+ if (!filter)
43
+ return 'both';
44
+ // const camelVariants = [name.replace(/[^A-Z]/g, '')]
45
+ const tokens = filter.split(' ').map(x => x.trim());
46
+ const namesCompactedMain = (0, compact_1.default)(namesMain);
47
+ const namesCompactedChild = (0, compact_1.default)(namesChild);
48
+ let isMainOnly = true;
49
+ let isChildOnly = true;
50
+ for (const token of tokens) {
51
+ const foundMain = namesCompactedMain.find(name => camelMatch(token, name));
52
+ const foundChild = namesCompactedChild.find(name => camelMatch(token, name));
53
+ if (!foundMain && !foundChild)
54
+ return 'none';
55
+ if (!foundMain)
56
+ isMainOnly = false;
57
+ if (!foundChild)
58
+ isChildOnly = false;
59
+ }
60
+ if (isMainOnly && isChildOnly)
61
+ return 'both';
62
+ if (isMainOnly)
63
+ return 'main';
64
+ if (isChildOnly)
65
+ return 'child';
66
+ return 'none';
67
+ }
68
+ exports.filterNameCompoud = filterNameCompoud;
69
+ function tokenizeBySearchFilter(text, filter) {
70
+ var _a, _b;
71
+ const camelTokens = [];
72
+ const stdTokens = [];
73
+ for (const token of filter.split(' ').map(x => x.trim())) {
74
+ if (token.replace(/[A-Z]/g, '').length == 0) {
75
+ camelTokens.push(token);
42
76
  }
43
77
  else {
44
- const found = namesOwn.find(name => camelMatch(token, name));
45
- if (!found)
46
- return false;
78
+ stdTokens.push(token.toUpperCase());
47
79
  }
48
80
  }
49
- return true;
81
+ let res = [
82
+ {
83
+ text,
84
+ isMatch: false,
85
+ },
86
+ ];
87
+ for (const token of camelTokens) {
88
+ const nextres = [];
89
+ for (const item of res) {
90
+ const indexes = [];
91
+ for (const char of token) {
92
+ if (indexes.length == 0 && char == ((_a = item.text[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase())) {
93
+ // handle first letter of camelcase
94
+ indexes.push(0);
95
+ }
96
+ else {
97
+ const index = item.text.indexOf(char, indexes.length > 0 ? indexes[indexes.length - 1] + 1 : 0);
98
+ if (index < 0) {
99
+ indexes.push(-1);
100
+ }
101
+ else {
102
+ indexes.push(index);
103
+ }
104
+ }
105
+ }
106
+ if (indexes.some(x => x < 0)) {
107
+ nextres.push(item);
108
+ }
109
+ else {
110
+ let lastIndex = 0;
111
+ for (let i = 0; i < indexes.length; i++) {
112
+ if (indexes[i] > lastIndex) {
113
+ nextres.push({ text: item.text.substring(lastIndex, indexes[i]), isMatch: false });
114
+ }
115
+ nextres.push({ text: item.text.substring(indexes[i], indexes[i] + 1), isMatch: true });
116
+ lastIndex = indexes[i] + 1;
117
+ }
118
+ nextres.push({ text: item.text.substring(lastIndex), isMatch: false });
119
+ }
120
+ }
121
+ res = nextres;
122
+ }
123
+ for (const token of stdTokens) {
124
+ const nextres = [];
125
+ for (const item of res) {
126
+ const index = (_b = item.text) === null || _b === void 0 ? void 0 : _b.toUpperCase().indexOf(token);
127
+ if (index < 0) {
128
+ nextres.push(item);
129
+ }
130
+ else {
131
+ nextres.push({ text: item.text.substring(0, index), isMatch: false });
132
+ nextres.push({ text: item.text.substring(index, index + token.length), isMatch: true });
133
+ nextres.push({ text: item.text.substring(index + token.length), isMatch: false });
134
+ }
135
+ }
136
+ res = nextres;
137
+ }
138
+ res = res.filter(x => x.text.length > 0);
139
+ if (res.length == 1 && !res[0].isMatch) {
140
+ return null;
141
+ }
142
+ return res;
143
+ // const result = [];
144
+ // let lastMatch = 0;
145
+ // for (const token of tokens) {
146
+ // const index = text.indexOf(token, lastMatch);
147
+ // if (index < 0) {
148
+ // result.push({ token, isMatch: false });
149
+ // continue;
150
+ // }
151
+ // result.push({ token: text.substring(lastMatch, index), isMatch: false });
152
+ // result.push({ token: text.substring(index, index + token.length), isMatch: true });
153
+ // lastMatch = index + token.length;
154
+ // }
155
+ // result.push({ token: text.substring(lastMatch), isMatch: false });
156
+ // return result;
50
157
  }
51
- exports.filterName = filterName;
158
+ exports.tokenizeBySearchFilter = tokenizeBySearchFilter;
@@ -175,6 +175,7 @@ function databaseInfoFromYamlModel(filesOrDbInfo) {
175
175
  }
176
176
  if (file.name.endsWith('.trigger.sql')) {
177
177
  model.triggers.push({
178
+ objectId: `triggers:${file.name.slice(0, -'.trigger.sql'.length)}`,
178
179
  pureName: file.name.slice(0, -'.trigger.sql'.length),
179
180
  createSql: file.text,
180
181
  });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.0.0",
2
+ "version": "6.1.1",
3
3
  "name": "dbgate-tools",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "devDependencies": {
27
27
  "@types/node": "^13.7.0",
28
- "dbgate-types": "^6.0.0",
28
+ "dbgate-types": "^6.1.1",
29
29
  "jest": "^24.9.0",
30
30
  "ts-jest": "^25.2.1",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {
34
34
  "dbgate-query-splitter": "^4.11.2",
35
- "dbgate-sqltree": "^6.0.0",
35
+ "dbgate-sqltree": "^6.1.1",
36
36
  "debug": "^4.3.4",
37
37
  "json-stable-stringify": "^1.0.1",
38
38
  "lodash": "^4.17.21",