mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 19:33:59 +00:00
Shell: Run script
This commit is contained in:
@@ -14,6 +14,7 @@ const logger = getLogger('execQuery');
|
|||||||
* @param {string} [options.sql] - SQL query
|
* @param {string} [options.sql] - SQL query
|
||||||
* @param {string} [options.sqlFile] - SQL file
|
* @param {string} [options.sqlFile] - SQL file
|
||||||
* @param {boolean} [options.logScriptItems] - whether to log script items instead of whole script
|
* @param {boolean} [options.logScriptItems] - whether to log script items instead of whole script
|
||||||
|
* @param {boolean} [options.skipLogging] - whether to skip logging
|
||||||
*/
|
*/
|
||||||
async function executeQuery({
|
async function executeQuery({
|
||||||
connection = undefined,
|
connection = undefined,
|
||||||
@@ -22,8 +23,9 @@ async function executeQuery({
|
|||||||
sql,
|
sql,
|
||||||
sqlFile = undefined,
|
sqlFile = undefined,
|
||||||
logScriptItems = false,
|
logScriptItems = false,
|
||||||
|
skipLogging = false,
|
||||||
}) {
|
}) {
|
||||||
if (!logScriptItems) {
|
if (!logScriptItems && !skipLogging) {
|
||||||
logger.info({ sql: getLimitedQuery(sql) }, `Execute query`);
|
logger.info({ sql: getLimitedQuery(sql) }, `Execute query`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +38,9 @@ async function executeQuery({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!skipLogging) {
|
||||||
logger.debug(`Running SQL query, length: ${sql.length}`);
|
logger.debug(`Running SQL query, length: ${sql.length}`);
|
||||||
|
}
|
||||||
|
|
||||||
await driver.script(dbhan, sql, { logScriptItems });
|
await driver.script(dbhan, sql, { logScriptItems });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -330,6 +330,29 @@ await dbgateApi.dropAllDbObjects(${JSON.stringify(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGenerateRunScript = () => {
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: 'Shell #',
|
||||||
|
icon: 'img shell',
|
||||||
|
tabComponent: 'ShellTab',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
editor: `// @require ${extractPackageName(connection.engine)}
|
||||||
|
|
||||||
|
await dbgateApi.executeQuery(${JSON.stringify(
|
||||||
|
{
|
||||||
|
connection: extractShellConnection(connection, name),
|
||||||
|
sql: 'your script here',
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
2
|
||||||
|
)});
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const handleShowDataDeployer = () => {
|
const handleShowDataDeployer = () => {
|
||||||
showModal(ChooseArchiveFolderModal, {
|
showModal(ChooseArchiveFolderModal, {
|
||||||
message: 'Choose archive folder for data deployer',
|
message: 'Choose archive folder for data deployer',
|
||||||
@@ -439,6 +462,11 @@ await dbgateApi.dropAllDbObjects(${JSON.stringify(
|
|||||||
text: 'Shell: Drop all objects',
|
text: 'Shell: Drop all objects',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
onClick: handleGenerateRunScript,
|
||||||
|
text: 'Shell: Run script',
|
||||||
|
},
|
||||||
|
|
||||||
driver?.databaseEngineTypes?.includes('sql') &&
|
driver?.databaseEngineTypes?.includes('sql') &&
|
||||||
hasPermission(`dbops/import`) && {
|
hasPermission(`dbops/import`) && {
|
||||||
onClick: handleShowDataDeployer,
|
onClick: handleShowDataDeployer,
|
||||||
|
|||||||
Reference in New Issue
Block a user