dbgate-api 5.5.4-alpha.2 → 5.5.4-alpha.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.5.4-alpha.2",
4
+ "version": "5.5.4-alpha.4",
5
5
  "homepage": "https://dbgate.org/",
6
6
  "repository": {
7
7
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "compare-versions": "^3.6.0",
27
27
  "cors": "^2.8.5",
28
28
  "cross-env": "^6.0.3",
29
- "dbgate-datalib": "^5.5.4-alpha.2",
29
+ "dbgate-datalib": "^5.5.4-alpha.4",
30
30
  "dbgate-query-splitter": "^4.10.5",
31
- "dbgate-sqltree": "^5.5.4-alpha.2",
32
- "dbgate-tools": "^5.5.4-alpha.2",
31
+ "dbgate-sqltree": "^5.5.4-alpha.4",
32
+ "dbgate-tools": "^5.5.4-alpha.4",
33
33
  "debug": "^4.3.4",
34
34
  "diff": "^5.0.0",
35
35
  "diff2html": "^3.4.13",
@@ -75,7 +75,7 @@
75
75
  "devDependencies": {
76
76
  "@types/fs-extra": "^9.0.11",
77
77
  "@types/lodash": "^4.14.149",
78
- "dbgate-types": "^5.5.4-alpha.2",
78
+ "dbgate-types": "^5.5.4-alpha.4",
79
79
  "env-cmd": "^10.1.0",
80
80
  "node-loader": "^1.0.2",
81
81
  "nodemon": "^2.0.2",
@@ -6,7 +6,7 @@ const { archivedir, clearArchiveLinksCache, resolveArchiveFolder } = require('..
6
6
  const socket = require('../utility/socket');
7
7
  const loadFilesRecursive = require('../utility/loadFilesRecursive');
8
8
  const getJslFileName = require('../utility/getJslFileName');
9
- const { getLogger } = require('dbgate-tools');
9
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
10
10
  const dbgateApi = require('../shell');
11
11
  const jsldata = require('./jsldata');
12
12
  const platformInfo = require('../utility/platformInfo');
@@ -74,7 +74,7 @@ module.exports = {
74
74
  ...fileType('.matview.sql', 'matview.sql'),
75
75
  ];
76
76
  } catch (err) {
77
- logger.error({ err }, 'Error reading archive files');
77
+ logger.error(extractErrorLogData(err), 'Error reading archive files');
78
78
  return [];
79
79
  }
80
80
  },
@@ -1,7 +1,7 @@
1
1
  const axios = require('axios');
2
2
  const jwt = require('jsonwebtoken');
3
3
  const getExpressPath = require('../utility/getExpressPath');
4
- const { getLogger } = require('dbgate-tools');
4
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
5
5
  const AD = require('activedirectory2').promiseWrapper;
6
6
  const crypto = require('crypto');
7
7
  const { getTokenSecret, getTokenLifetime } = require('../auth/authCommon');
@@ -71,7 +71,7 @@ function authMiddleware(req, res, next) {
71
71
  return next();
72
72
  }
73
73
 
74
- logger.error({ err }, 'Sending invalid token error');
74
+ logger.error(extractErrorLogData(err), 'Sending invalid token error');
75
75
 
76
76
  return unauthorizedResponse(req, res, 'invalid token');
77
77
  }
@@ -12,7 +12,7 @@ const { pickSafeConnectionInfo } = require('../utility/crypting');
12
12
  const JsonLinesDatabase = require('../utility/JsonLinesDatabase');
13
13
 
14
14
  const processArgs = require('../utility/processArgs');
15
- const { safeJsonParse, getLogger } = require('dbgate-tools');
15
+ const { safeJsonParse, getLogger, extractErrorLogData } = require('dbgate-tools');
16
16
  const platformInfo = require('../utility/platformInfo');
17
17
  const { connectionHasPermission, testConnectionPermission } = require('../utility/hasPermission');
18
18
  const pipeForkLogs = require('../utility/pipeForkLogs');
@@ -430,7 +430,7 @@ module.exports = {
430
430
  socket.emit('got-volatile-token', { strmid, savedConId: conid, volatileConId: volatile._id });
431
431
  return { success: true };
432
432
  } catch (err) {
433
- logger.error({ err }, 'Error getting DB token');
433
+ logger.error(extractErrorLogData(err), 'Error getting DB token');
434
434
  return { error: err.message };
435
435
  }
436
436
  },
@@ -446,7 +446,7 @@ module.exports = {
446
446
  const resp = await authProvider.login(null, null, { conid: volatile._id });
447
447
  return resp;
448
448
  } catch (err) {
449
- logger.error({ err }, 'Error getting DB token');
449
+ logger.error(extractErrorLogData(err), 'Error getting DB token');
450
450
  return { error: err.message };
451
451
  }
452
452
  },
@@ -12,6 +12,7 @@ const {
12
12
  extendDatabaseInfo,
13
13
  modelCompareDbDiffOptions,
14
14
  getLogger,
15
+ extractErrorLogData,
15
16
  } = require('dbgate-tools');
16
17
  const { html, parse } = require('diff2html');
17
18
  const { handleProcessCommunication } = require('../utility/processComm');
@@ -146,7 +147,7 @@ module.exports = {
146
147
  try {
147
148
  conn.subprocess.send({ msgid, ...message });
148
149
  } catch (err) {
149
- logger.error({ err }, 'Error sending request do process');
150
+ logger.error(extractErrorLogData(err), 'Error sending request do process');
150
151
  this.close(conn.conid, conn.database);
151
152
  }
152
153
  });
@@ -318,7 +319,7 @@ module.exports = {
318
319
  try {
319
320
  existing.subprocess.send({ msgtype: 'ping' });
320
321
  } catch (err) {
321
- logger.error({ err }, 'Error pinging DB connection');
322
+ logger.error(extractErrorLogData(err), 'Error pinging DB connection');
322
323
  this.close(conid, database);
323
324
 
324
325
  return {
@@ -362,7 +363,7 @@ module.exports = {
362
363
  try {
363
364
  existing.subprocess.kill();
364
365
  } catch (err) {
365
- logger.error({ err }, 'Error killing subprocess');
366
+ logger.error(extractErrorLogData(err), 'Error killing subprocess');
366
367
  }
367
368
  }
368
369
  this.opened = this.opened.filter(x => x.conid != conid || x.database != database);
@@ -11,7 +11,7 @@ const processArgs = require('../utility/processArgs');
11
11
  const { testConnectionPermission } = require('../utility/hasPermission');
12
12
  const { MissingCredentialsError } = require('../utility/exceptions');
13
13
  const pipeForkLogs = require('../utility/pipeForkLogs');
14
- const { getLogger } = require('dbgate-tools');
14
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
15
15
 
16
16
  const logger = getLogger('serverConnection');
17
17
 
@@ -112,7 +112,7 @@ module.exports = {
112
112
  try {
113
113
  existing.subprocess.kill();
114
114
  } catch (err) {
115
- logger.error({ err }, 'Error killing subprocess');
115
+ logger.error(extractErrorLogData(err), 'Error killing subprocess');
116
116
  }
117
117
  }
118
118
  this.opened = this.opened.filter(x => x.conid != conid);
@@ -167,7 +167,7 @@ module.exports = {
167
167
  try {
168
168
  opened.subprocess.send({ msgtype: 'ping' });
169
169
  } catch (err) {
170
- logger.error({ err }, 'Error pinging server connection');
170
+ logger.error(extractErrorLogData(err), 'Error pinging server connection');
171
171
  this.close(conid);
172
172
  }
173
173
  })
@@ -217,7 +217,7 @@ module.exports = {
217
217
  try {
218
218
  conn.subprocess.send({ msgid, ...message });
219
219
  } catch (err) {
220
- logger.error({ err }, 'Error sending request');
220
+ logger.error(extractErrorLogData(err), 'Error sending request');
221
221
  this.close(conn.conid);
222
222
  }
223
223
  });
@@ -8,7 +8,7 @@ const path = require('path');
8
8
  const { handleProcessCommunication } = require('../utility/processComm');
9
9
  const processArgs = require('../utility/processArgs');
10
10
  const { appdir } = require('../utility/directories');
11
- const { getLogger } = require('dbgate-tools');
11
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
12
12
  const pipeForkLogs = require('../utility/pipeForkLogs');
13
13
  const config = require('./config');
14
14
 
@@ -222,7 +222,7 @@ module.exports = {
222
222
  try {
223
223
  session.subprocess.send({ msgtype: 'ping' });
224
224
  } catch (err) {
225
- logger.error({ err }, 'Error pinging session');
225
+ logger.error(extractErrorLogData(err), 'Error pinging session');
226
226
 
227
227
  return {
228
228
  status: 'error',
@@ -1,7 +1,7 @@
1
1
  const crypto = require('crypto');
2
2
  const path = require('path');
3
3
  const { uploadsdir, getLogsFilePath } = require('../utility/directories');
4
- const { getLogger } = require('dbgate-tools');
4
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
5
5
  const logger = getLogger('uploads');
6
6
  const axios = require('axios');
7
7
  const os = require('os');
@@ -110,7 +110,7 @@ module.exports = {
110
110
 
111
111
  return response.data;
112
112
  } catch (err) {
113
- logger.error({ err }, 'Error uploading gist');
113
+ logger.error(extractErrorLogData(err), 'Error uploading gist');
114
114
 
115
115
  return {
116
116
  apiErrorMessage: err.message,
@@ -1,5 +1,5 @@
1
1
 
2
2
  module.exports = {
3
- version: '5.5.4-alpha.2',
4
- buildTime: '2024-10-01T08:41:09.234Z'
3
+ version: '5.5.4-alpha.4',
4
+ buildTime: '2024-10-01T10:23:19.199Z'
5
5
  };
@@ -7,6 +7,8 @@ const {
7
7
  getLogger,
8
8
  isCompositeDbName,
9
9
  dbNameLogCategory,
10
+ extractErrorMessage,
11
+ extractErrorLogData,
10
12
  } = require('dbgate-tools');
11
13
  const requireEngineDriver = require('../utility/requireEngineDriver');
12
14
  const connectUtility = require('../utility/connectUtility');
@@ -34,25 +36,6 @@ function getStatusCounter() {
34
36
  return statusCounter;
35
37
  }
36
38
 
37
- function extractErrorMessage(err, defaultMessage) {
38
- if (!err) {
39
- return defaultMessage;
40
- }
41
- if (err.errors) {
42
- try {
43
- return err.errors.map(x => x.message).join('\n');
44
- } catch (e2) {}
45
- }
46
- if (err.message) {
47
- return err.message;
48
- }
49
- const s = `${err}`;
50
- if (s && (!s.endsWith('Error') || s.includes(' '))) {
51
- return s;
52
- }
53
- return defaultMessage;
54
- }
55
-
56
39
  async function checkedAsyncCall(promise) {
57
40
  try {
58
41
  const res = await promise;
@@ -261,7 +244,7 @@ async function handleDriverDataCore(msgid, callMethod, { logName }) {
261
244
  const result = await callMethod(driver);
262
245
  process.send({ msgtype: 'response', msgid, result });
263
246
  } catch (err) {
264
- logger.error(err, `Error when handling message ${logName}`);
247
+ logger.error(extractErrorLogData(err, { logName }), `Error when handling message ${logName}`);
265
248
  process.send({ msgtype: 'response', msgid, errorMessage: extractErrorMessage(err, 'Error executing DB data') });
266
249
  }
267
250
  }
@@ -436,7 +419,7 @@ function start() {
436
419
  try {
437
420
  await handleMessage(message);
438
421
  } catch (err) {
439
- logger.error({ err }, 'Error in DB connection');
422
+ logger.error(extractErrorLogData(err), 'Error in DB connection');
440
423
  process.send({ msgtype: 'error', error: extractErrorMessage(err, 'Error processing message') });
441
424
  }
442
425
  });
@@ -3,7 +3,7 @@ const platformInfo = require('../utility/platformInfo');
3
3
  const childProcessChecker = require('../utility/childProcessChecker');
4
4
  const { handleProcessCommunication } = require('../utility/processComm');
5
5
  const { SSHConnection } = require('../utility/SSHConnection');
6
- const { getLogger } = require('dbgate-tools');
6
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
7
7
 
8
8
  const logger = getLogger('sshProcess');
9
9
 
@@ -40,7 +40,7 @@ async function handleStart({ connection, tunnelConfig }) {
40
40
  tunnelConfig,
41
41
  });
42
42
  } catch (err) {
43
- logger.error({ err }, 'Error creating SSH tunnel connection:');
43
+ logger.error(extractErrorLogData(err), 'Error creating SSH tunnel connection:');
44
44
 
45
45
  process.send({
46
46
  msgtype: 'error',
@@ -19,32 +19,39 @@ async function dataDuplicator({
19
19
  systemConnection,
20
20
  }) {
21
21
  if (!driver) driver = requireEngineDriver(connection);
22
- const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
22
+
23
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
23
24
 
24
- logger.info(`Connected.`);
25
+ try {
26
+ logger.info(`Connected.`);
25
27
 
26
- if (!analysedStructure) {
27
- analysedStructure = await driver.analyseFull(pool);
28
- }
28
+ if (!analysedStructure) {
29
+ analysedStructure = await driver.analyseFull(dbhan);
30
+ }
29
31
 
30
- const dupl = new DataDuplicator(
31
- pool,
32
- driver,
33
- analysedStructure,
34
- items.map(item => ({
35
- name: item.name,
36
- operation: item.operation,
37
- matchColumns: item.matchColumns,
38
- openStream:
39
- item.openStream ||
40
- (() => jsonLinesReader({ fileName: path.join(resolveArchiveFolder(archive), `${item.name}.jsonl`) })),
41
- })),
42
- stream,
43
- copyStream,
44
- options
45
- );
32
+ const dupl = new DataDuplicator(
33
+ dbhan,
34
+ driver,
35
+ analysedStructure,
36
+ items.map(item => ({
37
+ name: item.name,
38
+ operation: item.operation,
39
+ matchColumns: item.matchColumns,
40
+ openStream:
41
+ item.openStream ||
42
+ (() => jsonLinesReader({ fileName: path.join(resolveArchiveFolder(archive), `${item.name}.jsonl`) })),
43
+ })),
44
+ stream,
45
+ copyStream,
46
+ options
47
+ );
46
48
 
47
- await dupl.run();
49
+ await dupl.run();
50
+ } finally {
51
+ if (!systemConnection) {
52
+ await driver.close(dbhan);
53
+ }
54
+ }
48
55
  }
49
56
 
50
57
  module.exports = dataDuplicator;
@@ -27,15 +27,23 @@ async function dumpDatabase({
27
27
  logger.info(`Dumping database`);
28
28
 
29
29
  if (!driver) driver = requireEngineDriver(connection);
30
- const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
31
- logger.info(`Connected.`);
32
30
 
33
- const dumper = await driver.createBackupDumper(pool, {
34
- outputFile,
35
- databaseName,
36
- schemaName,
37
- });
38
- await doDump(dumper);
31
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
32
+
33
+ try {
34
+ logger.info(`Connected.`);
35
+
36
+ const dumper = await driver.createBackupDumper(dbhan, {
37
+ outputFile,
38
+ databaseName,
39
+ schemaName,
40
+ });
41
+ await doDump(dumper);
42
+ } finally {
43
+ if (!systemConnection) {
44
+ await driver.close(dbhan);
45
+ }
46
+ }
39
47
  }
40
48
 
41
49
  module.exports = dumpDatabase;
@@ -9,12 +9,15 @@ async function executeQuery({ connection = undefined, systemConnection = undefin
9
9
 
10
10
  if (!driver) driver = requireEngineDriver(connection);
11
11
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'script'));
12
- logger.info(`Connected.`);
13
12
 
14
- await driver.script(dbhan, sql);
13
+ try {
14
+ logger.info(`Connected.`);
15
15
 
16
- if (!systemConnection) {
17
- await driver.close(dbhan);
16
+ await driver.script(dbhan, sql);
17
+ } finally {
18
+ if (!systemConnection) {
19
+ await driver.close(dbhan);
20
+ }
18
21
  }
19
22
  }
20
23
 
@@ -22,44 +22,48 @@ async function generateDeploySql({
22
22
  if (!driver) driver = requireEngineDriver(connection);
23
23
 
24
24
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
25
- if (!analysedStructure) {
26
- analysedStructure = await driver.analyseFull(dbhan);
27
- }
28
25
 
29
- const deployedModel = generateDbPairingId(
30
- extendDatabaseInfo(loadedDbModel ? databaseInfoFromYamlModel(loadedDbModel) : await importDbModel(modelFolder))
31
- );
32
- const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
33
- const opts = {
34
- ...modelCompareDbDiffOptions,
26
+ try {
27
+ if (!analysedStructure) {
28
+ analysedStructure = await driver.analyseFull(dbhan);
29
+ }
35
30
 
36
- noDropTable: true,
37
- noDropColumn: true,
38
- noDropConstraint: true,
39
- noDropSqlObject: true,
40
- noRenameTable: true,
41
- noRenameColumn: true,
42
- };
43
- const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
44
- const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
31
+ const deployedModel = generateDbPairingId(
32
+ extendDatabaseInfo(loadedDbModel ? databaseInfoFromYamlModel(loadedDbModel) : await importDbModel(modelFolder))
33
+ );
34
+ const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
35
+ const opts = {
36
+ ...modelCompareDbDiffOptions,
45
37
 
46
- // console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
47
- // console.log('deployedModel', deployedModel.tables[0]);
48
- // console.log('currentModel', currentModel.tables[0]);
49
- // console.log('currentModelPaired', currentModelPaired.tables[0]);
50
- const res = getAlterDatabaseScript(
51
- currentModelPairedPreloaded,
52
- deployedModel,
53
- opts,
54
- currentModelPairedPreloaded,
55
- deployedModel,
56
- driver
57
- );
38
+ noDropTable: true,
39
+ noDropColumn: true,
40
+ noDropConstraint: true,
41
+ noDropSqlObject: true,
42
+ noRenameTable: true,
43
+ noRenameColumn: true,
44
+ };
45
+ const currentModelPaired = matchPairedObjects(deployedModel, currentModel, opts);
46
+ const currentModelPairedPreloaded = await enrichWithPreloadedRows(deployedModel, currentModelPaired, dbhan, driver);
58
47
 
59
- if (!systemConnection) {
60
- await driver.close(dbhan);
48
+ // console.log('currentModelPairedPreloaded', currentModelPairedPreloaded.tables[0]);
49
+ // console.log('deployedModel', deployedModel.tables[0]);
50
+ // console.log('currentModel', currentModel.tables[0]);
51
+ // console.log('currentModelPaired', currentModelPaired.tables[0]);
52
+ const res = getAlterDatabaseScript(
53
+ currentModelPairedPreloaded,
54
+ deployedModel,
55
+ opts,
56
+ currentModelPairedPreloaded,
57
+ deployedModel,
58
+ driver
59
+ );
60
+
61
+ return res;
62
+ } finally {
63
+ if (!systemConnection) {
64
+ await driver.close(dbhan);
65
+ }
61
66
  }
62
- return res;
63
67
  }
64
68
 
65
69
  module.exports = generateDeploySql;
@@ -59,21 +59,27 @@ async function importDatabase({ connection = undefined, systemConnection = undef
59
59
 
60
60
  if (!driver) driver = requireEngineDriver(connection);
61
61
  const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
62
- logger.info(`Connected.`);
62
+ try {
63
+ logger.info(`Connected.`);
63
64
 
64
- logger.info(`Input file: ${inputFile}`);
65
- const downloadedFile = await download(inputFile);
66
- logger.info(`Downloaded file: ${downloadedFile}`);
65
+ logger.info(`Input file: ${inputFile}`);
66
+ const downloadedFile = await download(inputFile);
67
+ logger.info(`Downloaded file: ${downloadedFile}`);
67
68
 
68
- const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
69
- const splittedStream = splitQueryStream(fileStream, {
70
- ...driver.getQuerySplitterOptions('import'),
71
- returnRichInfo: true,
72
- });
73
- const importStream = new ImportStream(dbhan, driver);
74
- // @ts-ignore
75
- splittedStream.pipe(importStream);
76
- await awaitStreamEnd(importStream);
69
+ const fileStream = fs.createReadStream(downloadedFile, 'utf-8');
70
+ const splittedStream = splitQueryStream(fileStream, {
71
+ ...driver.getQuerySplitterOptions('import'),
72
+ returnRichInfo: true,
73
+ });
74
+ const importStream = new ImportStream(dbhan, driver);
75
+ // @ts-ignore
76
+ splittedStream.pipe(importStream);
77
+ await awaitStreamEnd(importStream);
78
+ } finally {
79
+ if (!systemConnection) {
80
+ await driver.close(dbhan);
81
+ }
82
+ }
77
83
  }
78
84
 
79
85
  module.exports = importDatabase;
@@ -9,13 +9,19 @@ async function loadDatabase({ connection = undefined, systemConnection = undefin
9
9
  logger.info(`Analysing database`);
10
10
 
11
11
  if (!driver) driver = requireEngineDriver(connection);
12
- const pool = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
13
- logger.info(`Connected.`);
12
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'read', { forceRowsAsObjects: true }));
13
+ try {
14
+ logger.info(`Connected.`);
14
15
 
15
- const dbInfo = await driver.analyseFull(pool);
16
- logger.info(`Analyse finished`);
16
+ const dbInfo = await driver.analyseFull(dbhan);
17
+ logger.info(`Analyse finished`);
17
18
 
18
- await exportDbModel(dbInfo, outputDir);
19
+ await exportDbModel(dbInfo, outputDir);
20
+ } finally {
21
+ if (!systemConnection) {
22
+ await driver.close(dbhan);
23
+ }
24
+ }
19
25
  }
20
26
 
21
27
  module.exports = loadDatabase;
@@ -1,4 +1,4 @@
1
- const { getLogger } = require('dbgate-tools');
1
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
2
2
  const childProcessChecker = require('../utility/childProcessChecker');
3
3
  const processArgs = require('../utility/processArgs');
4
4
  const logger = getLogger();
@@ -11,7 +11,7 @@ async function runScript(func) {
11
11
  await func();
12
12
  process.exit(0);
13
13
  } catch (err) {
14
- logger.error({ err }, `Error running script: ${err.message || err}`);
14
+ logger.error(extractErrorLogData(err), `Error running script`);
15
15
  process.exit(1);
16
16
  }
17
17
  }
@@ -3,9 +3,9 @@ const requireEngineDriver = require('../utility/requireEngineDriver');
3
3
  const connectUtility = require('../utility/connectUtility');
4
4
  const logger = getLogger('tableReader');
5
5
 
6
- async function tableReader({ connection, pureName, schemaName }) {
6
+ async function tableReader({ connection, systemConnection, pureName, schemaName }) {
7
7
  const driver = requireEngineDriver(connection);
8
- const pool = await connectUtility(driver, connection, 'read');
8
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'read'));
9
9
  logger.info(`Connected.`);
10
10
 
11
11
  const fullName = { pureName, schemaName };
@@ -14,26 +14,26 @@ async function tableReader({ connection, pureName, schemaName }) {
14
14
  // @ts-ignore
15
15
  logger.info(`Reading collection ${fullNameToString(fullName)}`);
16
16
  // @ts-ignore
17
- return await driver.readQuery(pool, JSON.stringify(fullName));
17
+ return await driver.readQuery(dbhan, JSON.stringify(fullName));
18
18
  }
19
19
 
20
- const table = await driver.analyseSingleObject(pool, fullName, 'tables');
20
+ const table = await driver.analyseSingleObject(dbhan, fullName, 'tables');
21
21
  const query = `select * from ${quoteFullName(driver.dialect, fullName)}`;
22
22
  if (table) {
23
23
  // @ts-ignore
24
24
  logger.info(`Reading table ${fullNameToString(table)}`);
25
25
  // @ts-ignore
26
- return await driver.readQuery(pool, query, table);
26
+ return await driver.readQuery(dbhan, query, table);
27
27
  }
28
- const view = await driver.analyseSingleObject(pool, fullName, 'views');
28
+ const view = await driver.analyseSingleObject(dbhan, fullName, 'views');
29
29
  if (view) {
30
30
  // @ts-ignore
31
31
  logger.info(`Reading view ${fullNameToString(view)}`);
32
32
  // @ts-ignore
33
- return await driver.readQuery(pool, query, view);
33
+ return await driver.readQuery(dbhan, query, view);
34
34
  }
35
35
 
36
- return await driver.readQuery(pool, query);
36
+ return await driver.readQuery(dbhan, query);
37
37
  }
38
38
 
39
39
  module.exports = tableReader;
@@ -9,10 +9,16 @@ async function tableWriter({ connection, schemaName, pureName, driver, systemCon
9
9
  if (!driver) {
10
10
  driver = requireEngineDriver(connection);
11
11
  }
12
- const pool = systemConnection || (await connectUtility(driver, connection, 'write'));
12
+ const dbhan = systemConnection || (await connectUtility(driver, connection, 'write'));
13
13
 
14
- logger.info(`Connected.`);
15
- return await driver.writeTable(pool, { schemaName, pureName }, options);
14
+ try {
15
+ logger.info(`Connected.`);
16
+ return await driver.writeTable(dbhan, { schemaName, pureName }, options);
17
+ } finally {
18
+ if (!systemConnection) {
19
+ await driver.close(dbhan);
20
+ }
21
+ }
16
22
  }
17
23
 
18
24
  module.exports = tableWriter;
@@ -3,7 +3,7 @@ const { fork } = require('child_process');
3
3
  const { handleProcessCommunication } = require('./processComm');
4
4
  const processArgs = require('../utility/processArgs');
5
5
  const pipeForkLogs = require('./pipeForkLogs');
6
- const { getLogger } = require('dbgate-tools');
6
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
7
7
  const logger = getLogger('DatastoreProxy');
8
8
 
9
9
  class DatastoreProxy {
@@ -73,7 +73,7 @@ class DatastoreProxy {
73
73
  try {
74
74
  this.subprocess.send({ msgtype: 'read', msgid, offset, limit });
75
75
  } catch (err) {
76
- logger.error({ err }, 'Error getting rows');
76
+ logger.error(extractErrorLogData(err), 'Error getting rows');
77
77
  this.subprocess = null;
78
78
  }
79
79
  });
@@ -87,7 +87,7 @@ class DatastoreProxy {
87
87
  try {
88
88
  this.subprocess.send({ msgtype: 'notify', msgid });
89
89
  } catch (err) {
90
- logger.error({ err }, 'Error notifying subprocess');
90
+ logger.error(extractErrorLogData(err), 'Error notifying subprocess');
91
91
  this.subprocess = null;
92
92
  }
93
93
  });
@@ -1,4 +1,4 @@
1
- const { getLogger } = require('dbgate-tools');
1
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
2
2
 
3
3
  const logger = getLogger('childProcessChecked');
4
4
 
@@ -12,7 +12,7 @@ function childProcessChecker() {
12
12
  // This will come once parent dies.
13
13
  // One way can be to check for error code ERR_IPC_CHANNEL_CLOSED
14
14
  // and call process.exit()
15
- logger.error({ err }, 'parent died');
15
+ logger.error(extractErrorLogData(err), 'parent died');
16
16
  process.exit(1);
17
17
  }
18
18
  }, 1000);
@@ -3,9 +3,10 @@ const { decryptConnection } = require('./crypting');
3
3
  const { getSshTunnelProxy } = require('./sshTunnelProxy');
4
4
  const platformInfo = require('../utility/platformInfo');
5
5
  const connections = require('../controllers/connections');
6
+ const _ = require('lodash');
6
7
 
7
8
  async function loadConnection(driver, storedConnection, connectionMode) {
8
- const { allowShellConnection } = platformInfo;
9
+ const { allowShellConnection, allowConnectionFromEnvVariables } = platformInfo;
9
10
 
10
11
  if (connectionMode == 'app') {
11
12
  return storedConnection;
@@ -33,6 +34,16 @@ async function loadConnection(driver, storedConnection, connectionMode) {
33
34
  }
34
35
  return loadedWithDb;
35
36
  }
37
+
38
+ if (allowConnectionFromEnvVariables) {
39
+ return _.mapValues(storedConnection, (value, key) => {
40
+ if (_.isString(value) && value.startsWith('${') && value.endsWith('}')) {
41
+ return process.env[value.slice(2, -1)];
42
+ }
43
+ return value;
44
+ });
45
+ }
46
+
36
47
  return storedConnection;
37
48
  }
38
49
 
@@ -44,6 +44,7 @@ const platformInfo = {
44
44
  (!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_CONNECTION || !!isElectron() || !!isDbModel,
45
45
  allowShellScripting:
46
46
  (!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_SCRIPTING || !!isElectron() || !!isDbModel,
47
+ allowConnectionFromEnvVariables: !!isDbModel,
47
48
  defaultKeyfile: path.join(os.homedir(), '.ssh/id_rsa'),
48
49
  };
49
50
 
@@ -5,7 +5,7 @@ const AsyncLock = require('async-lock');
5
5
  const lock = new AsyncLock();
6
6
  const { fork } = require('child_process');
7
7
  const processArgs = require('../utility/processArgs');
8
- const { getLogger } = require('dbgate-tools');
8
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
9
9
  const pipeForkLogs = require('./pipeForkLogs');
10
10
  const logger = getLogger('sshTunnel');
11
11
 
@@ -40,7 +40,7 @@ function callForwardProcess(connection, tunnelConfig, tunnelCacheKey) {
40
40
  tunnelConfig,
41
41
  });
42
42
  } catch (err) {
43
- logger.error({ err }, 'Error connecting SSH');
43
+ logger.error(extractErrorLogData(err), 'Error connecting SSH');
44
44
  }
45
45
  return new Promise((resolve, reject) => {
46
46
  subprocess.on('message', resp => {
@@ -1,5 +1,5 @@
1
1
  const crypto = require('crypto');
2
- const { getLogger } = require('dbgate-tools');
2
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
3
3
  const { getSshTunnel } = require('./sshTunnel');
4
4
  const logger = getLogger('sshTunnelProxy');
5
5
 
@@ -10,7 +10,7 @@ async function handleGetSshTunnelRequest({ msgid, connection }, subprocess) {
10
10
  try {
11
11
  subprocess.send({ msgtype: 'getsshtunnel-response', msgid, response });
12
12
  } catch (err) {
13
- logger.error({ err }, 'Error sending to SSH tunnel');
13
+ logger.error(extractErrorLogData(err), 'Error sending to SSH tunnel');
14
14
  }
15
15
  }
16
16
 
@@ -2,7 +2,7 @@ const _ = require('lodash');
2
2
  const express = require('express');
3
3
  const getExpressPath = require('./getExpressPath');
4
4
  const { MissingCredentialsError } = require('./exceptions');
5
- const { getLogger } = require('dbgate-tools');
5
+ const { getLogger, extractErrorLogData } = require('dbgate-tools');
6
6
 
7
7
  const logger = getLogger('useController');
8
8
  /**
@@ -16,7 +16,7 @@ module.exports = function useController(app, electron, route, controller) {
16
16
  try {
17
17
  controller._init();
18
18
  } catch (err) {
19
- logger.error({ err }, `Error initializing controller, exiting application`);
19
+ logger.error(extractErrorLogData(err), `Error initializing controller, exiting application`);
20
20
  process.exit(1);
21
21
  }
22
22
  }
@@ -78,7 +78,7 @@ module.exports = function useController(app, electron, route, controller) {
78
78
  const data = await controller[key]({ ...req.body, ...req.query }, req);
79
79
  res.json(data);
80
80
  } catch (err) {
81
- logger.error({ err }, `Error when processing route ${route}/${key}`);
81
+ logger.error(extractErrorLogData(err), `Error when processing route ${route}/${key}`);
82
82
  if (err instanceof MissingCredentialsError) {
83
83
  res.json({
84
84
  missingCredentials: true,