mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 17:46:00 +00:00
use editor data hook
This commit is contained in:
@@ -42,8 +42,7 @@ export function SavedSqlFileAppObject({ data, commonProps }) {
|
|||||||
onLoad={(data) => {
|
onLoad={(data) => {
|
||||||
newQuery({
|
newQuery({
|
||||||
title: file,
|
title: file,
|
||||||
// @ts-ignore
|
initialData: data,
|
||||||
initialScript: data,
|
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -60,14 +59,15 @@ export function SavedShellFileAppObject({ data, commonProps }) {
|
|||||||
format="text"
|
format="text"
|
||||||
icon="img shell"
|
icon="img shell"
|
||||||
onLoad={(data) => {
|
onLoad={(data) => {
|
||||||
openNewTab(setOpenedTabs, {
|
openNewTab(
|
||||||
title: file,
|
setOpenedTabs,
|
||||||
icon: 'img shell',
|
{
|
||||||
tabComponent: 'ShellTab',
|
title: file,
|
||||||
props: {
|
icon: 'img shell',
|
||||||
initialScript: data,
|
tabComponent: 'ShellTab',
|
||||||
},
|
},
|
||||||
});
|
data
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import ModalContent from './ModalContent';
|
|||||||
import ModalFooter from './ModalFooter';
|
import ModalFooter from './ModalFooter';
|
||||||
// import FormikForm from '../utility/FormikForm';
|
// import FormikForm from '../utility/FormikForm';
|
||||||
|
|
||||||
export default function SaveFileModal({ getData, folder, format, modalState, name, onSave = undefined }) {
|
export default function SaveFileModal({ data, folder, format, modalState, name, onSave = undefined }) {
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values) => {
|
||||||
const { name } = values;
|
const { name } = values;
|
||||||
await axios.post('files/save', { folder, file: name, data: getData(), format });
|
await axios.post('files/save', { folder, file: name, data, format });
|
||||||
modalState.close();
|
modalState.close();
|
||||||
if (onSave) onSave(name);
|
if (onSave) onSave(name);
|
||||||
};
|
};
|
||||||
|
|||||||
16
packages/web/src/modals/SaveTabModal.js
Normal file
16
packages/web/src/modals/SaveTabModal.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { changeTab } from '../utility/common';
|
||||||
|
import { useOpenedTabs, useSetOpenedTabs } from '../utility/globalState';
|
||||||
|
import SaveFileModal from './SaveFileModal';
|
||||||
|
|
||||||
|
export default function SaveTabModal({ data, folder, format, modalState, tabid }) {
|
||||||
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
|
const openedTabs = useOpenedTabs();
|
||||||
|
|
||||||
|
const name = openedTabs.find((x) => x.tabid == tabid).title;
|
||||||
|
const onSave = (name) => changeTab(tabid, setOpenedTabs, (tab) => ({ ...tab, title: name }));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SaveFileModal data={data} folder={folder} format={format} modalState={modalState} name={name} onSave={onSave} />
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -11,16 +11,20 @@ export default function useNewQuery() {
|
|||||||
|
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${database}`;
|
const tooltip = `${connection.displayName || connection.server}\n${database}`;
|
||||||
|
|
||||||
return ({ title = undefined, ...props } = {}) =>
|
return ({ title = undefined, initialData = undefined, ...props } = {}) =>
|
||||||
openNewTab(setOpenedTabs, {
|
openNewTab(
|
||||||
title: title || 'Query',
|
setOpenedTabs,
|
||||||
icon: 'img sql-file',
|
{
|
||||||
tooltip,
|
title: title || 'Query',
|
||||||
tabComponent: 'QueryTab',
|
icon: 'img sql-file',
|
||||||
props: {
|
tooltip,
|
||||||
...props,
|
tabComponent: 'QueryTab',
|
||||||
conid: connection._id,
|
props: {
|
||||||
database,
|
...props,
|
||||||
|
conid: connection._id,
|
||||||
|
database,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
initialData
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
|
|
||||||
import { useConnectionInfo, getDbCore, getConnectionInfo, getSqlObjectInfo } from '../utility/metadataLoaders';
|
import { useConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import SqlEditor from '../sqleditor/SqlEditor';
|
import SqlEditor from '../sqleditor/SqlEditor';
|
||||||
import { useUpdateDatabaseForTab, useSetOpenedTabs, useOpenedTabs } from '../utility/globalState';
|
import { useUpdateDatabaseForTab, useSetOpenedTabs } from '../utility/globalState';
|
||||||
import QueryToolbar from '../query/QueryToolbar';
|
import QueryToolbar from '../query/QueryToolbar';
|
||||||
import SocketMessagesView from '../query/SocketMessagesView';
|
import SocketMessagesView from '../query/SocketMessagesView';
|
||||||
import { TabPage } from '../widgets/TabControl';
|
import { TabPage } from '../widgets/TabControl';
|
||||||
@@ -14,103 +14,38 @@ import { VerticalSplitter } from '../widgets/Splitter';
|
|||||||
import keycodes from '../utility/keycodes';
|
import keycodes from '../utility/keycodes';
|
||||||
import { changeTab } from '../utility/common';
|
import { changeTab } from '../utility/common';
|
||||||
import useSocket from '../utility/SocketProvider';
|
import useSocket from '../utility/SocketProvider';
|
||||||
import SaveFileModal from '../modals/SaveFileModal';
|
import SaveTabModal from '../modals/SaveTabModal';
|
||||||
import useModalState from '../modals/useModalState';
|
import useModalState from '../modals/useModalState';
|
||||||
import sqlFormatter from 'sql-formatter';
|
import sqlFormatter from 'sql-formatter';
|
||||||
import useExtensions from '../utility/useExtensions';
|
import useEditorData from '../utility/useEditorData';
|
||||||
import { driverBase, findEngineDriver } from 'dbgate-tools';
|
import useSqlTemplate from '../utility/useSqlTemplate';
|
||||||
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
|
|
||||||
function useSqlTemplate(sqlTemplate, props) {
|
export default function QueryTab({ tabid, conid, database, initialArgs, tabVisible, toolbarPortalRef, ...other }) {
|
||||||
const [sql, setSql] = React.useState('');
|
|
||||||
const extensions = useExtensions();
|
|
||||||
|
|
||||||
async function loadTemplate() {
|
|
||||||
if (sqlTemplate == 'CREATE TABLE') {
|
|
||||||
const tableInfo = await getDbCore(props, props.objectTypeField || 'tables');
|
|
||||||
const connection = await getConnectionInfo(props);
|
|
||||||
const driver = findEngineDriver(connection, extensions) || driverBase;
|
|
||||||
const dmp = driver.createDumper();
|
|
||||||
if (tableInfo) dmp.createTable(tableInfo);
|
|
||||||
setSql(dmp.s);
|
|
||||||
}
|
|
||||||
if (sqlTemplate == 'CREATE OBJECT') {
|
|
||||||
const objectInfo = await getSqlObjectInfo(props);
|
|
||||||
if (objectInfo) {
|
|
||||||
if (objectInfo.requiresFormat && objectInfo.createSql) setSql(sqlFormatter.format(objectInfo.createSql));
|
|
||||||
else setSql(objectInfo.createSql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sqlTemplate == 'EXECUTE PROCEDURE') {
|
|
||||||
const procedureInfo = await getSqlObjectInfo(props);
|
|
||||||
const connection = await getConnectionInfo(props);
|
|
||||||
|
|
||||||
const driver = findEngineDriver(connection, extensions) || driverBase;
|
|
||||||
const dmp = driver.createDumper();
|
|
||||||
if (procedureInfo) dmp.put('^execute %f', procedureInfo);
|
|
||||||
setSql(dmp.s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (sqlTemplate) {
|
|
||||||
loadTemplate();
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function QueryTab({
|
|
||||||
tabid,
|
|
||||||
conid,
|
|
||||||
database,
|
|
||||||
initialArgs,
|
|
||||||
tabVisible,
|
|
||||||
toolbarPortalRef,
|
|
||||||
initialScript,
|
|
||||||
storageKey,
|
|
||||||
...other
|
|
||||||
}) {
|
|
||||||
const loadingText = 'Loading SQL template...';
|
|
||||||
const localStorageKey = storageKey || `tabdata_sql_${tabid}`;
|
|
||||||
const { sqlTemplate } = initialArgs || {};
|
const { sqlTemplate } = initialArgs || {};
|
||||||
const [queryText, setQueryText] = React.useState(
|
|
||||||
() => localStorage.getItem(localStorageKey) || initialScript || (sqlTemplate ? loadingText : '')
|
|
||||||
);
|
|
||||||
const queryTextRef = React.useRef(queryText);
|
|
||||||
const [sessionId, setSessionId] = React.useState(null);
|
const [sessionId, setSessionId] = React.useState(null);
|
||||||
const [executeNumber, setExecuteNumber] = React.useState(0);
|
const [executeNumber, setExecuteNumber] = React.useState(0);
|
||||||
const setOpenedTabs = useSetOpenedTabs();
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
const openedTabs = useOpenedTabs();
|
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
const saveFileModalState = useModalState();
|
const saveFileModalState = useModalState();
|
||||||
|
const { editorData, setEditorData, isLoading } = useEditorData(tabid);
|
||||||
|
|
||||||
|
const [sqlFromTemplate, isLoadingTemplate] = useSqlTemplate(sqlTemplate, { conid, database, ...other });
|
||||||
|
const editorRef = React.useRef(null);
|
||||||
|
|
||||||
const sqlFromTemplate = useSqlTemplate(sqlTemplate, { conid, database, ...other });
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (sqlFromTemplate && queryText == loadingText) {
|
if (sqlFromTemplate && sqlTemplate) {
|
||||||
editorRef.current.editor.setValue(sqlFromTemplate);
|
setEditorData(sqlFromTemplate);
|
||||||
editorRef.current.editor.clearSelection();
|
// editorRef.current.editor.setValue(sqlFromTemplate);
|
||||||
|
// editorRef.current.editor.clearSelection();
|
||||||
|
changeTab(tabid, setOpenedTabs, (tab) => ({
|
||||||
|
...tab,
|
||||||
|
props: _.omit(tab.props, ['initialArgs']),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}, [sqlFromTemplate]);
|
}, [sqlFromTemplate]);
|
||||||
|
|
||||||
const saveToStorage = React.useCallback(() => {
|
|
||||||
try {
|
|
||||||
localStorage.setItem(localStorageKey, queryTextRef.current);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}, [localStorageKey, queryTextRef]);
|
|
||||||
const saveToStorageDebounced = React.useMemo(() => _.debounce(saveToStorage, 5000), [saveToStorage]);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
window.addEventListener('beforeunload', saveToStorage);
|
|
||||||
return () => {
|
|
||||||
saveToStorage();
|
|
||||||
window.removeEventListener('beforeunload', saveToStorage);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSessionDone = React.useCallback(() => {
|
const handleSessionDone = React.useCallback(() => {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -124,32 +59,13 @@ export default function QueryTab({
|
|||||||
}
|
}
|
||||||
}, [sessionId, socket]);
|
}, [sessionId, socket]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!storageKey)
|
|
||||||
changeTab(tabid, setOpenedTabs, (tab) => ({
|
|
||||||
...tab,
|
|
||||||
props: {
|
|
||||||
...tab.props,
|
|
||||||
storageKey: localStorageKey,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
}, [storageKey]);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
changeTab(tabid, setOpenedTabs, (tab) => ({ ...tab, busy }));
|
changeTab(tabid, setOpenedTabs, (tab) => ({ ...tab, busy }));
|
||||||
}, [busy]);
|
}, [busy]);
|
||||||
|
|
||||||
const editorRef = React.useRef(null);
|
|
||||||
|
|
||||||
useUpdateDatabaseForTab(tabVisible, conid, database);
|
useUpdateDatabaseForTab(tabVisible, conid, database);
|
||||||
const connection = useConnectionInfo({ conid });
|
const connection = useConnectionInfo({ conid });
|
||||||
|
|
||||||
const handleChange = (text) => {
|
|
||||||
if (text != null) queryTextRef.current = text;
|
|
||||||
setQueryText(text);
|
|
||||||
saveToStorageDebounced();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleExecute = async () => {
|
const handleExecute = async () => {
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
setExecuteNumber((num) => num + 1);
|
setExecuteNumber((num) => num + 1);
|
||||||
@@ -167,7 +83,7 @@ export default function QueryTab({
|
|||||||
setBusy(true);
|
setBusy(true);
|
||||||
await axios.post('sessions/execute-query', {
|
await axios.post('sessions/execute-query', {
|
||||||
sesid,
|
sesid,
|
||||||
sql: selectedText || queryText,
|
sql: selectedText || editorData,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -204,17 +120,23 @@ export default function QueryTab({
|
|||||||
editorRef.current.editor.clearSelection();
|
editorRef.current.editor.clearSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isLoading || isLoadingTemplate)
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<LoadingInfo message="Loading SQL script" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<VerticalSplitter>
|
<VerticalSplitter>
|
||||||
<SqlEditor
|
<SqlEditor
|
||||||
value={queryText}
|
value={editorData || ''}
|
||||||
onChange={handleChange}
|
onChange={setEditorData}
|
||||||
tabVisible={tabVisible}
|
tabVisible={tabVisible}
|
||||||
engine={connection && connection.engine}
|
engine={connection && connection.engine}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
editorRef={editorRef}
|
editorRef={editorRef}
|
||||||
readOnly={queryText == loadingText}
|
|
||||||
conid={conid}
|
conid={conid}
|
||||||
database={database}
|
database={database}
|
||||||
/>
|
/>
|
||||||
@@ -248,14 +170,7 @@ export default function QueryTab({
|
|||||||
/>,
|
/>,
|
||||||
toolbarPortalRef.current
|
toolbarPortalRef.current
|
||||||
)}
|
)}
|
||||||
<SaveFileModal
|
<SaveTabModal modalState={saveFileModalState} data={editorData} format="text" folder="sql" tabid={tabid} />
|
||||||
modalState={saveFileModalState}
|
|
||||||
getData={() => localStorage.getItem(localStorageKey)}
|
|
||||||
format="text"
|
|
||||||
folder="sql"
|
|
||||||
name={openedTabs.find((x) => x.tabid == tabid).title}
|
|
||||||
onSave={(name) => changeTab(tabid, setOpenedTabs, (tab) => ({ ...tab, title: name }))}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import localforage from 'localforage';
|
||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import { useSetOpenedTabs } from '../utility/globalState';
|
import { useSetOpenedTabs } from '../utility/globalState';
|
||||||
import { VerticalSplitter } from '../widgets/Splitter';
|
import { VerticalSplitter } from '../widgets/Splitter';
|
||||||
@@ -22,13 +23,13 @@ export default function ShellTab({
|
|||||||
storageKey,
|
storageKey,
|
||||||
...other
|
...other
|
||||||
}) {
|
}) {
|
||||||
const localStorageKey = storageKey || `tabdata_shell_${tabid}`;
|
const localStorageKey = `tabdata_shell_${tabid}`;
|
||||||
const [shellText, setShellText] = React.useState(() => localStorage.getItem(localStorageKey) || initialScript || '');
|
const [shellText, setShellText] = React.useState(initialScript || '');
|
||||||
const shellTextRef = React.useRef(shellText);
|
const shellTextRef = React.useRef(shellText);
|
||||||
const [busy, setBusy] = React.useState(false);
|
const [busy, setBusy] = React.useState(false);
|
||||||
const showModal = useShowModal();
|
const showModal = useShowModal();
|
||||||
|
|
||||||
const saveToStorage = React.useCallback(() => localStorage.setItem(localStorageKey, shellTextRef.current), [
|
const saveToStorage = React.useCallback(() => localforage.setItem(localStorageKey, shellTextRef.current), [
|
||||||
localStorageKey,
|
localStorageKey,
|
||||||
shellTextRef,
|
shellTextRef,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
|
import localforage from 'localforage';
|
||||||
|
|
||||||
export class LoadingToken {
|
export class LoadingToken {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -14,8 +15,11 @@ export function sleep(milliseconds) {
|
|||||||
return new Promise((resolve) => window.setTimeout(() => resolve(null), milliseconds));
|
return new Promise((resolve) => window.setTimeout(() => resolve(null), milliseconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openNewTab(setOpenedTabs, newTab) {
|
export async function openNewTab(setOpenedTabs, newTab, initialData = undefined) {
|
||||||
const tabid = uuidv1();
|
const tabid = uuidv1();
|
||||||
|
if (initialData) {
|
||||||
|
await localforage.setItem(`tabdata_${tabid}`, initialData);
|
||||||
|
}
|
||||||
setOpenedTabs((files) => [
|
setOpenedTabs((files) => [
|
||||||
...(files || []).map((x) => ({ ...x, selected: false })),
|
...(files || []).map((x) => ({ ...x, selected: false })),
|
||||||
{
|
{
|
||||||
|
|||||||
52
packages/web/src/utility/useEditorData.js
Normal file
52
packages/web/src/utility/useEditorData.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import localforage from 'localforage';
|
||||||
|
|
||||||
|
export default function useEditorData(tabid, initialData = null) {
|
||||||
|
const localStorageKey = `tabdata_${tabid}`;
|
||||||
|
|
||||||
|
const [value, setValue] = React.useState(initialData);
|
||||||
|
const [isLoading, setIsLoading] = React.useState(true);
|
||||||
|
|
||||||
|
const valueRef = React.useRef(null);
|
||||||
|
|
||||||
|
const initialLoad = async () => {
|
||||||
|
const init = await localforage.getItem(localStorageKey);
|
||||||
|
if (init) {
|
||||||
|
setValue(init);
|
||||||
|
valueRef.current = init;
|
||||||
|
}
|
||||||
|
setIsLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
initialLoad();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const saveToStorage = React.useCallback(async () => {
|
||||||
|
if (valueRef.current == null) return;
|
||||||
|
try {
|
||||||
|
await localforage.setItem(localStorageKey, valueRef.current);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}, [localStorageKey, valueRef]);
|
||||||
|
|
||||||
|
const saveToStorageDebounced = React.useMemo(() => _.debounce(saveToStorage, 500), [saveToStorage]);
|
||||||
|
|
||||||
|
const handleChange = (newValue) => {
|
||||||
|
if (newValue != null) valueRef.current = newValue;
|
||||||
|
setValue(newValue);
|
||||||
|
saveToStorageDebounced();
|
||||||
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
window.addEventListener('beforeunload', saveToStorage);
|
||||||
|
return () => {
|
||||||
|
saveToStorage();
|
||||||
|
window.removeEventListener('beforeunload', saveToStorage);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { editorData: value, setEditorData: handleChange, isLoading };
|
||||||
|
}
|
||||||
48
packages/web/src/utility/useSqlTemplate.js
Normal file
48
packages/web/src/utility/useSqlTemplate.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { getDbCore, getConnectionInfo, getSqlObjectInfo } from '../utility/metadataLoaders';
|
||||||
|
import sqlFormatter from 'sql-formatter';
|
||||||
|
import useExtensions from '../utility/useExtensions';
|
||||||
|
import { driverBase, findEngineDriver } from 'dbgate-tools';
|
||||||
|
|
||||||
|
export default function useSqlTemplate(sqlTemplate, props) {
|
||||||
|
const [sql, setSql] = React.useState('');
|
||||||
|
const extensions = useExtensions();
|
||||||
|
const [isLoading, setIsLoading] = React.useState(!!sqlTemplate);
|
||||||
|
|
||||||
|
async function loadTemplate() {
|
||||||
|
if (sqlTemplate == 'CREATE TABLE') {
|
||||||
|
const tableInfo = await getDbCore(props, props.objectTypeField || 'tables');
|
||||||
|
const connection = await getConnectionInfo(props);
|
||||||
|
const driver = findEngineDriver(connection, extensions) || driverBase;
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
if (tableInfo) dmp.createTable(tableInfo);
|
||||||
|
setSql(dmp.s);
|
||||||
|
}
|
||||||
|
if (sqlTemplate == 'CREATE OBJECT') {
|
||||||
|
const objectInfo = await getSqlObjectInfo(props);
|
||||||
|
if (objectInfo) {
|
||||||
|
if (objectInfo.requiresFormat && objectInfo.createSql) setSql(sqlFormatter.format(objectInfo.createSql));
|
||||||
|
else setSql(objectInfo.createSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sqlTemplate == 'EXECUTE PROCEDURE') {
|
||||||
|
const procedureInfo = await getSqlObjectInfo(props);
|
||||||
|
const connection = await getConnectionInfo(props);
|
||||||
|
|
||||||
|
const driver = findEngineDriver(connection, extensions) || driverBase;
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
if (procedureInfo) dmp.put('^execute %f', procedureInfo);
|
||||||
|
setSql(dmp.s);
|
||||||
|
}
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (sqlTemplate) {
|
||||||
|
loadTemplate();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return [sql, isLoading];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user