dbgate-tools 6.1.6 → 6.2.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.
@@ -12,7 +12,7 @@ export declare class SqlDumper implements AlterProcessor {
12
12
  escapeString(value: any): string;
13
13
  putStringValue(value: any): void;
14
14
  putByteArrayValue(value: any): void;
15
- putValue(value: any): void;
15
+ putValue(value: any, dataType?: any): void;
16
16
  putCmd(format: any, ...args: any[]): void;
17
17
  putFormattedValue(c: any, value: any): void;
18
18
  putFormattedList(c: any, collection: any): void;
package/lib/SqlDumper.js CHANGED
@@ -50,7 +50,7 @@ class SqlDumper {
50
50
  putByteArrayValue(value) {
51
51
  this.put('^null');
52
52
  }
53
- putValue(value) {
53
+ putValue(value, dataType = null) {
54
54
  if (value === null)
55
55
  this.put('^null');
56
56
  else if (value === true)
@@ -106,6 +106,9 @@ class SqlDumper {
106
106
  case 'v':
107
107
  this.putValue(value);
108
108
  break;
109
+ case 'V':
110
+ this.putValue(value.value, value.dataType);
111
+ break;
109
112
  case 'c':
110
113
  value(this);
111
114
  break;
@@ -221,7 +224,7 @@ class SqlDumper {
221
224
  }
222
225
  }
223
226
  columnDefinition(column, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
224
- var _a, _b, _c;
227
+ var _a, _b, _c, _d;
225
228
  if (column.computedExpression) {
226
229
  this.put('^as %s', column.computedExpression);
227
230
  if (column.isPersisted)
@@ -229,15 +232,15 @@ class SqlDumper {
229
232
  return;
230
233
  }
231
234
  this.columnType(column.dataType);
232
- if (column.autoIncrement) {
235
+ if (column.autoIncrement && !((_a = this.dialect) === null || _a === void 0 ? void 0 : _a.disableAutoIncrement)) {
233
236
  this.autoIncrement();
234
237
  }
235
238
  this.putRaw(' ');
236
239
  this.specialColumnOptions(column);
237
- if (includeNullable && !((_a = this.dialect) === null || _a === void 0 ? void 0 : _a.specificNullabilityImplementation)) {
240
+ if (includeNullable && !((_b = this.dialect) === null || _b === void 0 ? void 0 : _b.specificNullabilityImplementation)) {
238
241
  this.put(column.notNull ? '^not ^null' : '^null');
239
242
  }
240
- if (includeDefault && ((_c = (_b = column.defaultValue) === null || _b === void 0 ? void 0 : _b.toString()) === null || _c === void 0 ? void 0 : _c.trim())) {
243
+ if (includeDefault && ((_d = (_c = column.defaultValue) === null || _c === void 0 ? void 0 : _c.toString()) === null || _d === void 0 ? void 0 : _d.trim())) {
241
244
  this.columnDefault(column);
242
245
  }
243
246
  }
@@ -24,6 +24,7 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
24
24
  const writable = new stream.Writable({
25
25
  objectMode: true,
26
26
  });
27
+ writable.fullNameQuoted = fullNameQuoted;
27
28
  writable.buffer = [];
28
29
  writable.structure = null;
29
30
  writable.columnNames = null;
@@ -39,7 +40,9 @@ function createBulkInsertStreamBase(driver, stream, dbhan, name, options) {
39
40
  });
40
41
  writable.checkStructure = () => __awaiter(this, void 0, void 0, function* () {
41
42
  let structure = yield driver.analyseSingleTable(dbhan, name);
42
- // console.log('ANALYSING', name, structure);
43
+ if (structure) {
44
+ writable.structure = structure;
45
+ }
43
46
  if (structure && options.dropIfExists) {
44
47
  logger.info(`Dropping table ${fullNameQuoted}`);
45
48
  yield driver.script(dbhan, `DROP TABLE ${fullNameQuoted}`);
@@ -3,6 +3,7 @@ import { EngineDriver, QueryResult, RunScriptOptions } from 'dbgate-types';
3
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
5
  export declare function formatQueryWithoutParams(driver: EngineDriver, sql: string): string;
6
+ export declare function runQueryFmt(driver: any, conn: any, query: any, ...args: any[]): Promise<void>;
6
7
  export declare const driverBase: {
7
8
  analyserClass: any;
8
9
  dumperClass: typeof SqlDumper;
@@ -33,7 +34,7 @@ export declare const driverBase: {
33
34
  label: string;
34
35
  sql: string;
35
36
  }[];
36
- loadFieldValues(pool: any, name: any, columnName: any, search: any): Promise<any>;
37
+ loadFieldValues(pool: any, name: any, columnName: any, search: any, dataType: any): Promise<any>;
37
38
  readJsonQuery(pool: any, select: any, structure: any): any;
38
39
  showConnectionField: (field: any, values: any) => boolean;
39
40
  showConnectionTab: (field: any) => boolean;
package/lib/driverBase.js CHANGED
@@ -12,7 +12,7 @@ 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.formatQueryWithoutParams = exports.runQueryOnDriver = exports.runCommandOnDriver = void 0;
15
+ exports.driverBase = exports.runQueryFmt = exports.formatQueryWithoutParams = exports.runQueryOnDriver = exports.runCommandOnDriver = void 0;
16
16
  const compact_1 = __importDefault(require("lodash/compact"));
17
17
  const isString_1 = __importDefault(require("lodash/isString"));
18
18
  const SqlDumper_1 = require("./SqlDumper");
@@ -72,6 +72,14 @@ function formatQueryWithoutParams(driver, sql) {
72
72
  return dmp.s;
73
73
  }
74
74
  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
+ });
81
+ }
82
+ exports.runQueryFmt = runQueryFmt;
75
83
  exports.driverBase = {
76
84
  analyserClass: null,
77
85
  dumperClass: SqlDumper_1.SqlDumper,
@@ -147,30 +155,41 @@ exports.driverBase = {
147
155
  }
148
156
  return [];
149
157
  },
150
- loadFieldValues(pool, name, columnName, search) {
158
+ loadFieldValues(pool, name, columnName, search, dataType) {
151
159
  return __awaiter(this, void 0, void 0, function* () {
152
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 = {
167
+ exprType: 'column',
168
+ columnName,
169
+ alias: 'value',
170
+ };
171
+ }
153
172
  const select = {
154
173
  commandType: 'select',
155
174
  distinct: true,
156
- topRecords: 100,
157
175
  from: {
158
176
  name,
159
177
  },
160
- columns: [
161
- {
162
- exprType: 'column',
163
- columnName,
164
- alias: 'value',
165
- },
166
- ],
178
+ columns: [expr],
167
179
  orderBy: [
168
180
  {
169
181
  exprType: 'column',
170
182
  columnName,
183
+ direction: 'ASC',
171
184
  },
172
185
  ],
173
186
  };
187
+ if (this.dialect.topRecords) {
188
+ select.topRecords = 100;
189
+ }
190
+ else {
191
+ select.range = { offset: 0, limit: 100 };
192
+ }
174
193
  if (search) {
175
194
  const tokens = (0, compact_1.default)(search.split(' ').map(x => x.trim()));
176
195
  if (tokens.length > 0) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.1.6",
2
+ "version": "6.2.0",
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.1.6",
28
+ "dbgate-types": "^6.2.0",
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.3",
35
- "dbgate-sqltree": "^6.1.6",
35
+ "dbgate-sqltree": "^6.2.0",
36
36
  "debug": "^4.3.4",
37
37
  "json-stable-stringify": "^1.0.1",
38
38
  "lodash": "^4.17.21",