sql template => script template

This commit is contained in:
Jan Prochazka 2021-04-10 16:58:16 +02:00
parent 88b4c9daff
commit 90169a7624
3 changed files with 22 additions and 22 deletions

View File

@ -61,11 +61,11 @@
}, },
{ {
label: 'SQL: CREATE TABLE', label: 'SQL: CREATE TABLE',
sqlTemplate: 'CREATE TABLE', scriptTemplate: 'CREATE TABLE',
}, },
{ {
label: 'SQL: SELECT', label: 'SQL: SELECT',
sqlTemplate: 'SELECT', scriptTemplate: 'SELECT',
}, },
{ {
label: 'SQL Generator: CREATE TABLE', label: 'SQL Generator: CREATE TABLE',
@ -123,15 +123,15 @@
}, },
{ {
label: 'SQL: CREATE VIEW', label: 'SQL: CREATE VIEW',
sqlTemplate: 'CREATE OBJECT', scriptTemplate: 'CREATE OBJECT',
}, },
{ {
label: 'SQL: CREATE TABLE', label: 'SQL: CREATE TABLE',
sqlTemplate: 'CREATE TABLE', scriptTemplate: 'CREATE TABLE',
}, },
{ {
label: 'SQL: SELECT', label: 'SQL: SELECT',
sqlTemplate: 'SELECT', scriptTemplate: 'SELECT',
}, },
{ {
label: 'SQL Generator: CREATE VIEW', label: 'SQL Generator: CREATE VIEW',
@ -149,11 +149,11 @@
procedures: [ procedures: [
{ {
label: 'SQL: CREATE PROCEDURE', label: 'SQL: CREATE PROCEDURE',
sqlTemplate: 'CREATE OBJECT', scriptTemplate: 'CREATE OBJECT',
}, },
{ {
label: 'SQL: EXECUTE', label: 'SQL: EXECUTE',
sqlTemplate: 'EXECUTE PROCEDURE', scriptTemplate: 'EXECUTE PROCEDURE',
}, },
{ {
label: 'SQL Generator: CREATE PROCEDURE', label: 'SQL Generator: CREATE PROCEDURE',
@ -171,7 +171,7 @@
functions: [ functions: [
{ {
label: 'SQL: CREATE FUNCTION', label: 'SQL: CREATE FUNCTION',
sqlTemplate: 'CREATE OBJECT', scriptTemplate: 'CREATE OBJECT',
}, },
{ {
label: 'SQL Generator: CREATE FUNCTION', label: 'SQL Generator: CREATE FUNCTION',
@ -211,7 +211,7 @@
export async function openDatabaseObjectDetail( export async function openDatabaseObjectDetail(
tabComponent, tabComponent,
sqlTemplate, scriptTemplate,
{ schemaName, pureName, conid, database, objectTypeField }, { schemaName, pureName, conid, database, objectTypeField },
forceNewTab, forceNewTab,
initialData initialData
@ -224,17 +224,17 @@
openNewTab( openNewTab(
{ {
title: sqlTemplate ? 'Query #' : pureName, title: scriptTemplate ? 'Query #' : pureName,
tooltip, tooltip,
icon: sqlTemplate ? 'img sql-file' : icons[objectTypeField], icon: scriptTemplate ? 'img sql-file' : icons[objectTypeField],
tabComponent: sqlTemplate ? 'QueryTab' : tabComponent, tabComponent: scriptTemplate ? 'QueryTab' : tabComponent,
props: { props: {
schemaName, schemaName,
pureName, pureName,
conid, conid,
database, database,
objectTypeField, objectTypeField,
initialArgs: sqlTemplate ? { sqlTemplate } : null, initialArgs: scriptTemplate ? { scriptTemplate } : null,
}, },
}, },
initialData, initialData,
@ -387,7 +387,7 @@
database: data.database, database: data.database,
}); });
} else { } else {
openDatabaseObjectDetail(menu.tab, menu.sqlTemplate, data, menu.forceNewTab, menu.initialData); openDatabaseObjectDetail(menu.tab, menu.scriptTemplate, data, menu.forceNewTab, menu.initialData);
} }
}, },
}; };

View File

@ -40,7 +40,7 @@
import SqlEditor from '../query/SqlEditor.svelte'; import SqlEditor from '../query/SqlEditor.svelte';
import useEditorData from '../query/useEditorData'; import useEditorData from '../query/useEditorData';
import { extensions } from '../stores'; import { extensions } from '../stores';
import applySqlTemplate from '../utility/applySqlTemplate'; import applyScriptTemplate from '../utility/applyScriptTemplate';
import axiosInstance from '../utility/axiosInstance'; import axiosInstance from '../utility/axiosInstance';
import { changeTab } from '../utility/common'; import { changeTab } from '../utility/common';
import { getDatabaseInfo, useConnectionInfo } from '../utility/metadataLoaders'; import { getDatabaseInfo, useConnectionInfo } from '../utility/metadataLoaders';
@ -207,8 +207,8 @@
const { editorState, editorValue, setEditorData } = useEditorData({ const { editorState, editorValue, setEditorData } = useEditorData({
tabid, tabid,
loadFromArgs: loadFromArgs:
initialArgs && initialArgs.sqlTemplate initialArgs && initialArgs.scriptTemplate
? () => applySqlTemplate(initialArgs.sqlTemplate, $extensions, $$props) ? () => applyScriptTemplate(initialArgs.scriptTemplate, $extensions, $$props)
: null, : null,
}); });

View File

@ -11,11 +11,11 @@ async function generateTableSql(extensions, props, dumpProc, format = false) {
return format ? sqlFormatter.format(dmp.s) : dmp.s; return format ? sqlFormatter.format(dmp.s) : dmp.s;
} }
export default async function applySqlTemplate(sqlTemplate, extensions, props) { export default async function applyScriptTemplate(scriptTemplate, extensions, props) {
if (sqlTemplate == 'CREATE TABLE') { if (scriptTemplate == 'CREATE TABLE') {
return generateTableSql(extensions, props, (dmp, tableInfo) => dmp.createTable(tableInfo)); return generateTableSql(extensions, props, (dmp, tableInfo) => dmp.createTable(tableInfo));
} }
if (sqlTemplate == 'SELECT') { if (scriptTemplate == 'SELECT') {
return generateTableSql( return generateTableSql(
extensions, extensions,
props, props,
@ -29,14 +29,14 @@ export default async function applySqlTemplate(sqlTemplate, extensions, props) {
true true
); );
} }
if (sqlTemplate == 'CREATE OBJECT') { if (scriptTemplate == 'CREATE OBJECT') {
const objectInfo = await getSqlObjectInfo(props); const objectInfo = await getSqlObjectInfo(props);
if (objectInfo) { if (objectInfo) {
if (objectInfo.requiresFormat && objectInfo.createSql) return sqlFormatter.format(objectInfo.createSql); if (objectInfo.requiresFormat && objectInfo.createSql) return sqlFormatter.format(objectInfo.createSql);
else return objectInfo.createSql; else return objectInfo.createSql;
} }
} }
if (sqlTemplate == 'EXECUTE PROCEDURE') { if (scriptTemplate == 'EXECUTE PROCEDURE') {
const procedureInfo = await getSqlObjectInfo(props); const procedureInfo = await getSqlObjectInfo(props);
const connection = await getConnectionInfo(props); const connection = await getConnectionInfo(props);