mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 12:56:01 +00:00
procedures, functions
This commit is contained in:
@@ -38,10 +38,10 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
viewInfo_meta: 'get',
|
sqlObjectInfo_meta: 'get',
|
||||||
async viewInfo({ conid, database, schemaName, pureName }) {
|
async sqlObjectInfo({ objectTypeField, conid, database, schemaName, pureName }) {
|
||||||
const opened = await databaseConnections.ensureOpened(conid, database);
|
const opened = await databaseConnections.ensureOpened(conid, database);
|
||||||
const view = opened.structure.views.find((x) => x.pureName == pureName && x.schemaName == schemaName);
|
const res = opened.structure[objectTypeField].find((x) => x.pureName == pureName && x.schemaName == schemaName);
|
||||||
return view;
|
return res;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ export default function TabsPanel() {
|
|||||||
setOpenedTabs(files => files.filter(x => x.tabid != tabid));
|
setOpenedTabs(files => files.filter(x => x.tabid != tabid));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log(
|
// console.log(
|
||||||
't',
|
// 't',
|
||||||
tabs.map(x => x.tooltip)
|
// tabs.map(x => x.tooltip)
|
||||||
);
|
// );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import { filterName } from '@dbgate/datalib';
|
|||||||
const icons = {
|
const icons = {
|
||||||
tables: 'table2.svg',
|
tables: 'table2.svg',
|
||||||
views: 'view2.svg',
|
views: 'view2.svg',
|
||||||
|
procedures: 'procedure2.svg',
|
||||||
|
functions: 'function.svg',
|
||||||
};
|
};
|
||||||
|
|
||||||
const menus = {
|
const menus = {
|
||||||
@@ -34,7 +36,19 @@ const menus = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Show CREATE VIEW script',
|
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 = {
|
const defaultTabs = {
|
||||||
tables: 'TableDataTab',
|
tables: 'TableDataTab',
|
||||||
views: 'ViewDataTab',
|
views: 'ViewDataTab',
|
||||||
|
procedures: 'SqlObjectCreateScriptTab',
|
||||||
|
functions: 'SqlObjectCreateScriptTab',
|
||||||
};
|
};
|
||||||
|
|
||||||
async function openObjectDetail(
|
async function openObjectDetail(
|
||||||
@@ -65,6 +81,7 @@ async function openObjectDetail(
|
|||||||
pureName,
|
pureName,
|
||||||
conid,
|
conid,
|
||||||
database,
|
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);
|
useUpdateDatabaseForTab(tabVisible, conid, database);
|
||||||
const connection = useConnectionInfo({ conid });
|
const connection = useConnectionInfo({ conid });
|
||||||
console.log('GOT CONNECTION', connection);
|
// console.log('GOT CONNECTION', connection);
|
||||||
|
|
||||||
// usePropsCompare({ tableInfo, connection, config, cache });
|
// 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 ViewDataTab from './ViewDataTab';
|
||||||
import TableStructureTab from './TableStructureTab';
|
import TableStructureTab from './TableStructureTab';
|
||||||
import TableCreateScriptTab from './TableCreateScriptTab';
|
import TableCreateScriptTab from './TableCreateScriptTab';
|
||||||
import ViewCreateScriptTab from './ViewCreateScriptTab';
|
import SqlObjectCreateScriptTab from './SqlObjectCreateScriptTab';
|
||||||
import QueryTab from './QueryTab';
|
import QueryTab from './QueryTab';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -11,5 +11,5 @@ export default {
|
|||||||
TableStructureTab,
|
TableStructureTab,
|
||||||
TableCreateScriptTab,
|
TableCreateScriptTab,
|
||||||
QueryTab,
|
QueryTab,
|
||||||
ViewCreateScriptTab,
|
SqlObjectCreateScriptTab,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ const tableInfoLoader = ({ conid, database, schemaName, pureName }) => ({
|
|||||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const viewInfoLoader = ({ conid, database, schemaName, pureName }) => ({
|
const sqlObjectInfoLoader = ({ objectTypeField, conid, database, schemaName, pureName }) => ({
|
||||||
url: 'metadata/view-info',
|
url: 'metadata/sql-object-info',
|
||||||
params: { conid, database, schemaName, pureName },
|
params: { objectTypeField, conid, database, schemaName, pureName },
|
||||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -86,12 +86,20 @@ export function useTableInfo(args) {
|
|||||||
|
|
||||||
/** @returns {Promise<import('@dbgate/types').ViewInfo>} */
|
/** @returns {Promise<import('@dbgate/types').ViewInfo>} */
|
||||||
export function getViewInfo(args) {
|
export function getViewInfo(args) {
|
||||||
return getCore(viewInfoLoader, args);
|
return getCore(sqlObjectInfoLoader, { ...args, objectTypeField: 'views' });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {import('@dbgate/types').ViewInfo} */
|
/** @returns {import('@dbgate/types').ViewInfo} */
|
||||||
export function useViewInfo(args) {
|
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>} */
|
/** @returns {Promise<import('@dbgate/types').StoredConnection>} */
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ function SqlObjectList({ conid, database }) {
|
|||||||
|
|
||||||
const [filter, setFilter] = React.useState('');
|
const [filter, setFilter] = React.useState('');
|
||||||
const objectList = _.flatten(
|
const objectList = _.flatten(
|
||||||
['tables', 'views'].map((objectTypeField) =>
|
['tables', 'views', 'procedures', 'functions'].map((objectTypeField) =>
|
||||||
((objects || {})[objectTypeField] || []).map((obj) => ({ ...obj, objectTypeField }))
|
((objects || {})[objectTypeField] || []).map((obj) => ({ ...obj, objectTypeField }))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user