dbgate-api 4.8.4 → 4.8.7

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": "4.8.4",
4
+ "version": "4.8.7",
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.8.3",
29
- "dbgate-sqltree": "^4.8.4",
30
- "dbgate-tools": "^4.8.4",
28
+ "dbgate-query-splitter": "^4.9.0",
29
+ "dbgate-sqltree": "^4.8.7",
30
+ "dbgate-tools": "^4.8.7",
31
31
  "diff": "^5.0.0",
32
32
  "diff2html": "^3.4.13",
33
33
  "eslint": "^6.8.0",
@@ -63,7 +63,7 @@
63
63
  "devDependencies": {
64
64
  "@types/fs-extra": "^9.0.11",
65
65
  "@types/lodash": "^4.14.149",
66
- "dbgate-types": "^4.8.4",
66
+ "dbgate-types": "^4.8.7",
67
67
  "env-cmd": "^10.1.0",
68
68
  "node-loader": "^1.0.2",
69
69
  "nodemon": "^2.0.2",
@@ -37,6 +37,7 @@ module.exports = {
37
37
  // hideAppEditor: !!process.env.HIDE_APP_EDITOR,
38
38
  allowShellConnection: platformInfo.allowShellConnection,
39
39
  allowShellScripting: platformInfo.allowShellConnection,
40
+ isDocker: platformInfo.isDocker,
40
41
  permissions,
41
42
  login,
42
43
  ...currentVersion,
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '4.8.4',
4
- buildTime: '2022-04-14T13:28:48.297Z'
3
+ version: '4.8.7',
4
+ buildTime: '2022-04-22T18:29:21.643Z'
5
5
  };
@@ -0,0 +1,38 @@
1
+ const requireEngineDriver = require('../utility/requireEngineDriver');
2
+ const connectUtility = require('../utility/connectUtility');
3
+
4
+ function doDump(dumper) {
5
+ return new Promise((resolve, reject) => {
6
+ dumper.once('end', () => {
7
+ resolve(true);
8
+ });
9
+ dumper.once('error', err => {
10
+ reject(err);
11
+ });
12
+ dumper.run();
13
+ });
14
+ }
15
+
16
+ async function dumpDatabase({
17
+ connection = undefined,
18
+ systemConnection = undefined,
19
+ driver = undefined,
20
+ outputFile,
21
+ databaseName,
22
+ schemaName,
23
+ }) {
24
+ console.log(`Dumping database`);
25
+
26
+ if (!driver) driver = requireEngineDriver(connection);
27
+ const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
28
+ console.log(`Connected.`);
29
+
30
+ const dumper = await driver.createBackupDumper(pool, {
31
+ outputFile,
32
+ databaseName,
33
+ schemaName,
34
+ });
35
+ await doDump(dumper);
36
+ }
37
+
38
+ module.exports = dumpDatabase;
@@ -0,0 +1,57 @@
1
+ const fs = require('fs');
2
+ const requireEngineDriver = require('../utility/requireEngineDriver');
3
+ const connectUtility = require('../utility/connectUtility');
4
+ const { splitQueryStream } = require('dbgate-query-splitter/lib/splitQueryStream');
5
+ const download = require('./download');
6
+ const stream = require('stream');
7
+
8
+ class ImportStream extends stream.Transform {
9
+ constructor(pool, driver) {
10
+ super({ objectMode: true });
11
+ this.pool = pool;
12
+ this.driver = driver;
13
+ }
14
+ async _transform(chunk, encoding, cb) {
15
+ try {
16
+ await this.driver.script(this.pool, chunk);
17
+ } catch (err) {
18
+ this.emit('error', err.message);
19
+ }
20
+ cb();
21
+ }
22
+ _flush(cb) {
23
+ this.push('finish');
24
+ cb();
25
+ this.emit('end');
26
+ }
27
+ }
28
+
29
+ function awaitStreamEnd(stream) {
30
+ return new Promise((resolve, reject) => {
31
+ stream.once('end', () => {
32
+ resolve(true);
33
+ });
34
+ stream.once('error', err => {
35
+ reject(err);
36
+ });
37
+ });
38
+ }
39
+
40
+ async function importDatabase({ connection = undefined, systemConnection = undefined, driver = undefined, inputFile }) {
41
+ console.log(`Importing database`);
42
+
43
+ if (!driver) driver = requireEngineDriver(connection);
44
+ const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
45
+ console.log(`Connected.`);
46
+
47
+ const downloadedFile = await download(inputFile);
48
+
49
+ const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
50
+ const splittedStream = splitQueryStream(fileStream, driver.getQuerySplitterOptions());
51
+ const importStream = new ImportStream(pool, driver);
52
+ // @ts-ignore
53
+ splittedStream.pipe(importStream);
54
+ await awaitStreamEnd(importStream);
55
+ }
56
+
57
+ module.exports = importDatabase;
@@ -21,6 +21,8 @@ const executeQuery = require('./executeQuery');
21
21
  const loadFile = require('./loadFile');
22
22
  const deployDb = require('./deployDb');
23
23
  const initializeApiEnvironment = require('./initializeApiEnvironment');
24
+ const dumpDatabase = require('./dumpDatabase');
25
+ const importDatabase = require('./importDatabase');
24
26
 
25
27
  const dbgateApi = {
26
28
  queryReader,
@@ -45,6 +47,8 @@ const dbgateApi = {
45
47
  loadFile,
46
48
  deployDb,
47
49
  initializeApiEnvironment,
50
+ dumpDatabase,
51
+ importDatabase,
48
52
  };
49
53
 
50
54
  requirePlugin.initializeDbgateApi(dbgateApi);
@@ -39,7 +39,7 @@ async function loadConnection(driver, storedConnection, connectionMode) {
39
39
  return storedConnection;
40
40
  }
41
41
 
42
- async function connectUtility(driver, storedConnection, connectionMode) {
42
+ async function connectUtility(driver, storedConnection, connectionMode, additionalOptions = null) {
43
43
  const connectionLoaded = await loadConnection(driver, storedConnection, connectionMode);
44
44
 
45
45
  const connection = {
@@ -93,7 +93,7 @@ async function connectUtility(driver, storedConnection, connectionMode) {
93
93
  }
94
94
  }
95
95
 
96
- const conn = await driver.connect(connection);
96
+ const conn = await driver.connect({ ...connection, ...additionalOptions });
97
97
  return conn;
98
98
  }
99
99