dbgate-tools 4.6.1 → 4.6.2

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.
@@ -21,6 +21,7 @@ export declare class DatabaseAnalyser {
21
21
  getDeletedObjectsForField(snapshot: any, objectTypeField: any): any;
22
22
  getDeletedObjects(snapshot: any): any[];
23
23
  getModifications(): Promise<any[]>;
24
+ safeQuery(sql: any): Promise<import("dbgate-types").QueryResult>;
24
25
  static createEmptyStructure(): DatabaseInfo;
25
26
  static byTableFilter(table: any): (x: any) => boolean;
26
27
  static extractPrimaryKeys(table: any, pkColumns: any): {
@@ -231,6 +231,19 @@ class DatabaseAnalyser {
231
231
  return [...(0, compact_1.default)(res), ...this.getDeletedObjects(snapshot)];
232
232
  });
233
233
  }
234
+ safeQuery(sql) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ try {
237
+ return yield this.driver.query(this.pool, sql);
238
+ }
239
+ catch (err) {
240
+ console.log('Error running analyser query', err.message);
241
+ return {
242
+ rows: [],
243
+ };
244
+ }
245
+ });
246
+ }
234
247
  static createEmptyStructure() {
235
248
  return {
236
249
  tables: [],
@@ -9,6 +9,7 @@ export declare class SqlDumper implements AlterProcessor {
9
9
  putRaw(text: any): void;
10
10
  escapeString(value: any): string;
11
11
  putStringValue(value: any): void;
12
+ putByteArrayValue(value: any): void;
12
13
  putValue(value: any): void;
13
14
  putCmd(format: any, ...args: any[]): void;
14
15
  putFormattedValue(c: any, value: any): void;
package/lib/SqlDumper.js CHANGED
@@ -8,6 +8,8 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const isString_1 = __importDefault(require("lodash/isString"));
9
9
  const isNumber_1 = __importDefault(require("lodash/isNumber"));
10
10
  const isDate_1 = __importDefault(require("lodash/isDate"));
11
+ const isArray_1 = __importDefault(require("lodash/isArray"));
12
+ const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
11
13
  const v1_1 = __importDefault(require("uuid/v1"));
12
14
  class SqlDumper {
13
15
  constructor(driver) {
@@ -39,6 +41,9 @@ class SqlDumper {
39
41
  this.putRaw(this.escapeString(value));
40
42
  this.putRaw("'");
41
43
  }
44
+ putByteArrayValue(value) {
45
+ this.putRaw('NULL');
46
+ }
42
47
  putValue(value) {
43
48
  if (value === null)
44
49
  this.putRaw('NULL');
@@ -52,6 +57,10 @@ class SqlDumper {
52
57
  this.putRaw(value.toString());
53
58
  else if ((0, isDate_1.default)(value))
54
59
  this.putStringValue(new Date(value).toISOString());
60
+ else if ((value === null || value === void 0 ? void 0 : value.type) == 'Buffer' && (0, isArray_1.default)(value === null || value === void 0 ? void 0 : value.data))
61
+ this.putByteArrayValue(value === null || value === void 0 ? void 0 : value.data);
62
+ else if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value))
63
+ this.putStringValue(JSON.stringify(value));
55
64
  else
56
65
  this.putRaw('NULL');
57
66
  }
@@ -1,2 +1,4 @@
1
1
  export declare function arrayToHexString(byteArray: any): any;
2
2
  export declare function hexStringToArray(inputString: any): any[];
3
+ export declare function parseCellValue(value: any): any;
4
+ export declare function stringifyCellValue(value: any): any;
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hexStringToArray = exports.arrayToHexString = void 0;
6
+ exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
7
+ const isString_1 = __importDefault(require("lodash/isString"));
8
+ const isArray_1 = __importDefault(require("lodash/isArray"));
9
+ const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
4
10
  function arrayToHexString(byteArray) {
5
- return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '');
11
+ return byteArray.reduce((output, elem) => output + ('0' + elem.toString(16)).slice(-2), '').toUpperCase();
6
12
  }
7
13
  exports.arrayToHexString = arrayToHexString;
8
14
  function hexStringToArray(inputString) {
@@ -14,3 +20,36 @@ function hexStringToArray(inputString) {
14
20
  return res;
15
21
  }
16
22
  exports.hexStringToArray = hexStringToArray;
23
+ function parseCellValue(value) {
24
+ if (!(0, isString_1.default)(value))
25
+ return value;
26
+ if (value == '(NULL)')
27
+ return null;
28
+ const mHex = value.match(/^0x([0-9a-fA-F][0-9a-fA-F])+$/);
29
+ if (mHex) {
30
+ return {
31
+ type: 'Buffer',
32
+ data: hexStringToArray(value.substring(2)),
33
+ };
34
+ }
35
+ const mOid = value.match(/^ObjectId\("([0-9a-f]{24})"\)$/);
36
+ if (mOid) {
37
+ return { $oid: mOid[1] };
38
+ }
39
+ return value;
40
+ }
41
+ exports.parseCellValue = parseCellValue;
42
+ function stringifyCellValue(value) {
43
+ if (value === null)
44
+ return '(NULL)';
45
+ if (value === undefined)
46
+ return '(NoField)';
47
+ if ((value === null || value === void 0 ? void 0 : value.type) == 'Buffer' && (0, isArray_1.default)(value.data))
48
+ return '0x' + arrayToHexString(value.data);
49
+ if (value === null || value === void 0 ? void 0 : value.$oid)
50
+ return `ObjectId("${value === null || value === void 0 ? void 0 : value.$oid}")`;
51
+ if ((0, isPlainObject_1.default)(value) || (0, isArray_1.default)(value))
52
+ return JSON.stringify(value);
53
+ return value;
54
+ }
55
+ exports.stringifyCellValue = stringifyCellValue;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.6.1",
2
+ "version": "4.6.2",
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": "^4.6.1",
28
+ "dbgate-types": "^4.6.2",
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
  "lodash": "^4.17.21",
35
- "dbgate-query-splitter": "^4.6.1",
35
+ "dbgate-query-splitter": "^4.6.2",
36
36
  "uuid": "^3.4.0"
37
37
  }
38
38
  }