mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 09:36:00 +00:00
sql generator in connection process
This commit is contained in:
@@ -153,6 +153,17 @@ module.exports = {
|
|||||||
// };
|
// };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sqlPreview_meta: 'post',
|
||||||
|
async sqlPreview({ conid, database, objects, options }) {
|
||||||
|
// wait for structure
|
||||||
|
await this.structure({ conid, database })
|
||||||
|
|
||||||
|
const opened = await this.ensureOpened(conid, database);
|
||||||
|
const res = await this.sendRequest(opened, { msgtype: 'sqlPreview', objects, options });
|
||||||
|
return res.sql;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// runCommand_meta: 'post',
|
// runCommand_meta: 'post',
|
||||||
// async runCommand({ conid, database, sql }) {
|
// async runCommand({ conid, database, sql }) {
|
||||||
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const childProcessChecker = require('../utility/childProcessChecker');
|
|||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
|
const { SqlGenerator } = require('dbgate-tools')
|
||||||
|
|
||||||
let systemConnection;
|
let systemConnection;
|
||||||
let storedConnection;
|
let storedConnection;
|
||||||
@@ -93,6 +94,17 @@ async function handleQueryData({ msgid, sql }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function handleSqlPreview({ msgid, objects, options }) {
|
||||||
|
await waitConnected();
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
const generator = new SqlGenerator(analysedStructure, options, objects, dmp);
|
||||||
|
await generator.dump();
|
||||||
|
process.send({ msgtype: 'response', msgid, sql: dmp.s });
|
||||||
|
}
|
||||||
|
|
||||||
// async function handleRunCommand({ msgid, sql }) {
|
// async function handleRunCommand({ msgid, sql }) {
|
||||||
// await waitConnected();
|
// await waitConnected();
|
||||||
// const driver = engines(storedConnection);
|
// const driver = engines(storedConnection);
|
||||||
@@ -107,6 +119,7 @@ function handlePing() {
|
|||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
queryData: handleQueryData,
|
queryData: handleQueryData,
|
||||||
|
sqlPreview: handleSqlPreview,
|
||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
// runCommand: handleRunCommand,
|
// runCommand: handleRunCommand,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
async function generatePreview(options, objects) {
|
async function generatePreview(options, objects) {
|
||||||
busy = true;
|
busy = true;
|
||||||
const response = await axiosInstance.post('sqlgen/preview', { conid, database, objects, options });
|
const response = await axiosInstance.post('database-connections/sql-preview', { conid, database, objects, options });
|
||||||
if (_.isString(response.data)) {
|
if (_.isString(response.data)) {
|
||||||
sqlPreview = response.data;
|
sqlPreview = response.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user