dbgate-tools 5.1.1 → 5.1.3
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/SqlDumper.js +1 -1
- package/lib/stringTools.d.ts +2 -0
- package/lib/stringTools.js +21 -1
- package/package.json +3 -3
package/lib/SqlDumper.js
CHANGED
|
@@ -475,7 +475,7 @@ class SqlDumper {
|
|
|
475
475
|
this.putCmd('^select * ^into %f ^from %f', targetName, sourceName);
|
|
476
476
|
}
|
|
477
477
|
truncateTable(name) {
|
|
478
|
-
this.putCmd('^
|
|
478
|
+
this.putCmd('^truncate ^table %f', name);
|
|
479
479
|
}
|
|
480
480
|
dropConstraints(table, dropReferences = false) {
|
|
481
481
|
if (dropReferences && this.dialect.dropForeignKey) {
|
package/lib/stringTools.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export declare function safeJsonParse(json: any, defaultValue?: any, logError?:
|
|
|
6
6
|
export declare function isJsonLikeLongString(value: any): RegExpMatchArray;
|
|
7
7
|
export declare function getIconForRedisType(type: any): "img folder" | "img type-string" | "img type-hash" | "img type-set" | "img type-list" | "img type-zset" | "img type-stream" | "img type-binary" | "img type-rejson";
|
|
8
8
|
export declare function isWktGeometry(s: any): boolean;
|
|
9
|
+
export declare function arrayBufferToBase64(buffer: any): string;
|
|
10
|
+
export declare function getAsImageSrc(obj: any): string;
|
package/lib/stringTools.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
|
|
6
|
+
exports.getAsImageSrc = exports.arrayBufferToBase64 = exports.isWktGeometry = exports.getIconForRedisType = exports.isJsonLikeLongString = exports.safeJsonParse = exports.stringifyCellValue = exports.parseCellValue = exports.hexStringToArray = exports.arrayToHexString = void 0;
|
|
7
7
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
8
8
|
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
9
9
|
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
|
@@ -54,6 +54,9 @@ function stringifyCellValue(value) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.stringifyCellValue = stringifyCellValue;
|
|
56
56
|
function safeJsonParse(json, defaultValue, logError = false) {
|
|
57
|
+
if ((0, isArray_1.default)(json) || (0, isPlainObject_1.default)(json)) {
|
|
58
|
+
return json;
|
|
59
|
+
}
|
|
57
60
|
try {
|
|
58
61
|
return JSON.parse(json);
|
|
59
62
|
}
|
|
@@ -101,3 +104,20 @@ function isWktGeometry(s) {
|
|
|
101
104
|
return !!s.match(/^POINT\s*\(|^LINESTRING\s*\(|^POLYGON\s*\(|^MULTIPOINT\s*\(|^MULTILINESTRING\s*\(|^MULTIPOLYGON\s*\(|^GEOMCOLLECTION\s*\(|^GEOMETRYCOLLECTION\s*\(/);
|
|
102
105
|
}
|
|
103
106
|
exports.isWktGeometry = isWktGeometry;
|
|
107
|
+
function arrayBufferToBase64(buffer) {
|
|
108
|
+
var binary = '';
|
|
109
|
+
var bytes = [].slice.call(new Uint8Array(buffer));
|
|
110
|
+
bytes.forEach(b => (binary += String.fromCharCode(b)));
|
|
111
|
+
return btoa(binary);
|
|
112
|
+
}
|
|
113
|
+
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
114
|
+
function getAsImageSrc(obj) {
|
|
115
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.type) == 'Buffer' && (0, isArray_1.default)(obj === null || obj === void 0 ? void 0 : obj.data)) {
|
|
116
|
+
return `data:image/png;base64, ${arrayBufferToBase64(obj === null || obj === void 0 ? void 0 : obj.data)}`;
|
|
117
|
+
}
|
|
118
|
+
if ((0, isString_1.default)(obj) && (obj.startsWith('http://') || obj.startsWith('https://'))) {
|
|
119
|
+
return obj;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
exports.getAsImageSrc = getAsImageSrc;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "5.1.
|
|
2
|
+
"version": "5.1.3",
|
|
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": "^5.1.
|
|
28
|
+
"dbgate-types": "^5.1.3",
|
|
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.9.0",
|
|
35
|
-
"dbgate-sqltree": "^5.1.
|
|
35
|
+
"dbgate-sqltree": "^5.1.3",
|
|
36
36
|
"debug": "^4.3.4",
|
|
37
37
|
"json-stable-stringify": "^1.0.1",
|
|
38
38
|
"lodash": "^4.17.21",
|