dbgate-api 5.1.2 → 5.1.4
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "5.1.
|
|
4
|
+
"version": "5.1.4",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"compare-versions": "^3.6.0",
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
27
|
"cross-env": "^6.0.3",
|
|
28
|
-
"dbgate-query-splitter": "^4.9.
|
|
29
|
-
"dbgate-sqltree": "^5.1.
|
|
30
|
-
"dbgate-tools": "^5.1.
|
|
28
|
+
"dbgate-query-splitter": "^4.9.2",
|
|
29
|
+
"dbgate-sqltree": "^5.1.4",
|
|
30
|
+
"dbgate-tools": "^5.1.4",
|
|
31
31
|
"debug": "^4.3.4",
|
|
32
32
|
"diff": "^5.0.0",
|
|
33
33
|
"diff2html": "^3.4.13",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@types/fs-extra": "^9.0.11",
|
|
67
67
|
"@types/lodash": "^4.14.149",
|
|
68
|
-
"dbgate-types": "^5.1.
|
|
68
|
+
"dbgate-types": "^5.1.4",
|
|
69
69
|
"env-cmd": "^10.1.0",
|
|
70
70
|
"node-loader": "^1.0.2",
|
|
71
71
|
"nodemon": "^2.0.2",
|
|
@@ -152,4 +152,13 @@ module.exports = {
|
|
|
152
152
|
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
|
153
153
|
return { status: 'ok' };
|
|
154
154
|
},
|
|
155
|
+
|
|
156
|
+
dropDatabase_meta: true,
|
|
157
|
+
async dropDatabase({ conid, name }, req) {
|
|
158
|
+
testConnectionPermission(conid, req);
|
|
159
|
+
const opened = await this.ensureOpened(conid);
|
|
160
|
+
if (opened.connection.isReadOnly) return false;
|
|
161
|
+
opened.subprocess.send({ msgtype: 'dropDatabase', name });
|
|
162
|
+
return { status: 'ok' };
|
|
163
|
+
},
|
|
155
164
|
};
|
package/src/currentVersion.js
CHANGED
|
@@ -2,7 +2,6 @@ const stableStringify = require('json-stable-stringify');
|
|
|
2
2
|
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
|
|
3
3
|
const childProcessChecker = require('../utility/childProcessChecker');
|
|
4
4
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
|
5
|
-
const { decryptConnection } = require('../utility/crypting');
|
|
6
5
|
const connectUtility = require('../utility/connectUtility');
|
|
7
6
|
const { handleProcessCommunication } = require('../utility/processComm');
|
|
8
7
|
|
|
@@ -81,14 +80,16 @@ function handlePing() {
|
|
|
81
80
|
lastPing = new Date().getTime();
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
async function
|
|
83
|
+
async function handleDatabaseOp(op, { name }) {
|
|
85
84
|
const driver = requireEngineDriver(storedConnection);
|
|
86
85
|
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
await driver.createDatabase(systemConnection, name);
|
|
86
|
+
if (driver[op]) {
|
|
87
|
+
await driver[op](systemConnection, name);
|
|
90
88
|
} else {
|
|
91
|
-
|
|
89
|
+
const dmp = driver.createDumper();
|
|
90
|
+
dmp[op](name);
|
|
91
|
+
console.log(`RUNNING SCRIPT: ${dmp.s}`);
|
|
92
|
+
await driver.query(systemConnection, dmp.s);
|
|
92
93
|
}
|
|
93
94
|
await handleRefresh();
|
|
94
95
|
}
|
|
@@ -96,7 +97,8 @@ async function handleCreateDatabase({ name }) {
|
|
|
96
97
|
const messageHandlers = {
|
|
97
98
|
connect: handleConnect,
|
|
98
99
|
ping: handlePing,
|
|
99
|
-
createDatabase:
|
|
100
|
+
createDatabase: props => handleDatabaseOp('createDatabase', props),
|
|
101
|
+
dropDatabase: props => handleDatabaseOp('dropDatabase', props),
|
|
100
102
|
};
|
|
101
103
|
|
|
102
104
|
async function handleMessage({ msgtype, ...other }) {
|
|
@@ -101,8 +101,9 @@ class TableWriter {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
class StreamHandler {
|
|
104
|
-
constructor(resultIndexHolder, resolve) {
|
|
104
|
+
constructor(resultIndexHolder, resolve, startLine) {
|
|
105
105
|
this.recordset = this.recordset.bind(this);
|
|
106
|
+
this.startLine = startLine;
|
|
106
107
|
this.row = this.row.bind(this);
|
|
107
108
|
// this.error = this.error.bind(this);
|
|
108
109
|
this.done = this.done.bind(this);
|
|
@@ -155,14 +156,21 @@ class StreamHandler {
|
|
|
155
156
|
this.resolve();
|
|
156
157
|
}
|
|
157
158
|
info(info) {
|
|
159
|
+
if (info && info.line != null) {
|
|
160
|
+
info = {
|
|
161
|
+
...info,
|
|
162
|
+
line: this.startLine + info.line,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
158
165
|
process.send({ msgtype: 'info', info });
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
function handleStream(driver, resultIndexHolder,
|
|
169
|
+
function handleStream(driver, resultIndexHolder, sqlItem) {
|
|
163
170
|
return new Promise((resolve, reject) => {
|
|
164
|
-
const
|
|
165
|
-
|
|
171
|
+
const start = sqlItem.trimStart || sqlItem.start;
|
|
172
|
+
const handler = new StreamHandler(resultIndexHolder, resolve, start && start.line);
|
|
173
|
+
driver.stream(systemConnection, sqlItem.text, handler);
|
|
166
174
|
});
|
|
167
175
|
}
|
|
168
176
|
|
|
@@ -221,7 +229,10 @@ async function handleExecuteQuery({ sql }) {
|
|
|
221
229
|
const resultIndexHolder = {
|
|
222
230
|
value: 0,
|
|
223
231
|
};
|
|
224
|
-
for (const sqlItem of splitQuery(sql,
|
|
232
|
+
for (const sqlItem of splitQuery(sql, {
|
|
233
|
+
...driver.getQuerySplitterOptions('stream'),
|
|
234
|
+
returnRichInfo: true,
|
|
235
|
+
})) {
|
|
225
236
|
await handleStream(driver, resultIndexHolder, sqlItem);
|
|
226
237
|
// const handler = new StreamHandler(resultIndex);
|
|
227
238
|
// const stream = await driver.stream(systemConnection, sqlItem, handler);
|
|
@@ -47,7 +47,7 @@ async function importDatabase({ connection = undefined, systemConnection = undef
|
|
|
47
47
|
const downloadedFile = await download(inputFile);
|
|
48
48
|
|
|
49
49
|
const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
|
|
50
|
-
const splittedStream = splitQueryStream(fileStream, driver.getQuerySplitterOptions());
|
|
50
|
+
const splittedStream = splitQueryStream(fileStream, driver.getQuerySplitterOptions('script'));
|
|
51
51
|
const importStream = new ImportStream(pool, driver);
|
|
52
52
|
// @ts-ignore
|
|
53
53
|
splittedStream.pipe(importStream);
|