mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
procedures, functions
This commit is contained in:
parent
4c8b86dfaa
commit
f690c42153
@ -38,10 +38,10 @@ module.exports = {
|
||||
};
|
||||
},
|
||||
|
||||
viewInfo_meta: 'get',
|
||||
async viewInfo({ conid, database, schemaName, pureName }) {
|
||||
sqlObjectInfo_meta: 'get',
|
||||
async sqlObjectInfo({ objectTypeField, conid, database, schemaName, pureName }) {
|
||||
const opened = await databaseConnections.ensureOpened(conid, database);
|
||||
const view = opened.structure.views.find((x) => x.pureName == pureName && x.schemaName == schemaName);
|
||||
return view;
|
||||
const res = opened.structure[objectTypeField].find((x) => x.pureName == pureName && x.schemaName == schemaName);
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
@ -47,10 +47,10 @@ export default function TabsPanel() {
|
||||
setOpenedTabs(files => files.filter(x => x.tabid != tabid));
|
||||
}
|
||||
};
|
||||
console.log(
|
||||
't',
|
||||
tabs.map(x => x.tooltip)
|
||||
);
|
||||
// console.log(
|
||||
// 't',
|
||||
// tabs.map(x => x.tooltip)
|
||||
// );
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -10,6 +10,8 @@ import { filterName } from '@dbgate/datalib';
|
||||
const icons = {
|
||||
tables: 'table2.svg',
|
||||
views: 'view2.svg',
|
||||
procedures: 'procedure2.svg',
|
||||
functions: 'function.svg',
|
||||
};
|
||||
|
||||
const menus = {
|
||||
@ -34,7 +36,19 @@ const menus = {
|
||||
},
|
||||
{
|
||||
label: 'Show CREATE VIEW script',
|
||||
tab: 'ViewCreateScriptTab',
|
||||
tab: 'SqlObjectCreateScriptTab',
|
||||
},
|
||||
],
|
||||
procedures: [
|
||||
{
|
||||
label: 'Show CREATE PROCEDURE script',
|
||||
tab: 'SqlObjectCreateScriptTab',
|
||||
},
|
||||
],
|
||||
functions: [
|
||||
{
|
||||
label: 'Show CREATE FUNCTION script',
|
||||
tab: 'SqlObjectCreateScriptTab',
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -42,6 +56,8 @@ const menus = {
|
||||
const defaultTabs = {
|
||||
tables: 'TableDataTab',
|
||||
views: 'ViewDataTab',
|
||||
procedures: 'SqlObjectCreateScriptTab',
|
||||
functions: 'SqlObjectCreateScriptTab',
|
||||
};
|
||||
|
||||
async function openObjectDetail(
|
||||
@ -65,6 +81,7 @@ async function openObjectDetail(
|
||||
pureName,
|
||||
conid,
|
||||
database,
|
||||
objectTypeField,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
11
packages/web/src/tabs/SqlObjectCreateScriptTab.js
Normal file
11
packages/web/src/tabs/SqlObjectCreateScriptTab.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React from 'react';
|
||||
import { useConnectionInfo, useSqlObjectInfo } from '../utility/metadataLoaders';
|
||||
import SqlEditor from '../sqleditor/SqlEditor';
|
||||
|
||||
export default function SqlObjectCreateScriptTab({ objectTypeField, conid, database, schemaName, pureName }) {
|
||||
const sqlObjectInfo = useSqlObjectInfo({ conid, database, schemaName, pureName, objectTypeField });
|
||||
const connnection = useConnectionInfo({ conid });
|
||||
if (!connnection || !sqlObjectInfo) return null;
|
||||
|
||||
return <SqlEditor engine={connnection && connnection.engine} value={sqlObjectInfo.createSql} readOnly />;
|
||||
}
|
@ -18,7 +18,7 @@ export default function TableDataTab({ conid, database, schemaName, pureName, ta
|
||||
|
||||
useUpdateDatabaseForTab(tabVisible, conid, database);
|
||||
const connection = useConnectionInfo({ conid });
|
||||
console.log('GOT CONNECTION', connection);
|
||||
// console.log('GOT CONNECTION', connection);
|
||||
|
||||
// usePropsCompare({ tableInfo, connection, config, cache });
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
import React from 'react';
|
||||
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
|
||||
import SqlEditor from '../sqleditor/SqlEditor';
|
||||
|
||||
export default function ViewCreateScriptTab({ conid, database, schemaName, pureName }) {
|
||||
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
||||
const connnection = useConnectionInfo({ conid });
|
||||
if (!connnection || !viewInfo) return null;
|
||||
|
||||
return <SqlEditor engine={connnection && connnection.engine} value={viewInfo.createSql} readOnly />;
|
||||
}
|
@ -2,7 +2,7 @@ import TableDataTab from './TableDataTab';
|
||||
import ViewDataTab from './ViewDataTab';
|
||||
import TableStructureTab from './TableStructureTab';
|
||||
import TableCreateScriptTab from './TableCreateScriptTab';
|
||||
import ViewCreateScriptTab from './ViewCreateScriptTab';
|
||||
import SqlObjectCreateScriptTab from './SqlObjectCreateScriptTab';
|
||||
import QueryTab from './QueryTab';
|
||||
|
||||
export default {
|
||||
@ -11,5 +11,5 @@ export default {
|
||||
TableStructureTab,
|
||||
TableCreateScriptTab,
|
||||
QueryTab,
|
||||
ViewCreateScriptTab,
|
||||
SqlObjectCreateScriptTab,
|
||||
};
|
||||
|
@ -9,9 +9,9 @@ const tableInfoLoader = ({ conid, database, schemaName, pureName }) => ({
|
||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||
});
|
||||
|
||||
const viewInfoLoader = ({ conid, database, schemaName, pureName }) => ({
|
||||
url: 'metadata/view-info',
|
||||
params: { conid, database, schemaName, pureName },
|
||||
const sqlObjectInfoLoader = ({ objectTypeField, conid, database, schemaName, pureName }) => ({
|
||||
url: 'metadata/sql-object-info',
|
||||
params: { objectTypeField, conid, database, schemaName, pureName },
|
||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||
});
|
||||
|
||||
@ -86,12 +86,20 @@ export function useTableInfo(args) {
|
||||
|
||||
/** @returns {Promise<import('@dbgate/types').ViewInfo>} */
|
||||
export function getViewInfo(args) {
|
||||
return getCore(viewInfoLoader, args);
|
||||
return getCore(sqlObjectInfoLoader, { ...args, objectTypeField: 'views' });
|
||||
}
|
||||
|
||||
/** @returns {import('@dbgate/types').ViewInfo} */
|
||||
export function useViewInfo(args) {
|
||||
return useCore(viewInfoLoader, args);
|
||||
return useCore(sqlObjectInfoLoader, { ...args, objectTypeField: 'views' });
|
||||
}
|
||||
|
||||
export function getSqlObjectInfo(args) {
|
||||
return getCore(sqlObjectInfoLoader, args);
|
||||
}
|
||||
|
||||
export function useSqlObjectInfo(args) {
|
||||
return useCore(sqlObjectInfoLoader, args);
|
||||
}
|
||||
|
||||
/** @returns {Promise<import('@dbgate/types').StoredConnection>} */
|
||||
|
@ -92,7 +92,7 @@ function SqlObjectList({ conid, database }) {
|
||||
|
||||
const [filter, setFilter] = React.useState('');
|
||||
const objectList = _.flatten(
|
||||
['tables', 'views'].map((objectTypeField) =>
|
||||
['tables', 'views', 'procedures', 'functions'].map((objectTypeField) =>
|
||||
((objects || {})[objectTypeField] || []).map((obj) => ({ ...obj, objectTypeField }))
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user