mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 15:16:00 +00:00
utility functions, trat view as table
This commit is contained in:
@@ -43,10 +43,18 @@ const menus = {
|
|||||||
label: 'Show CREATE VIEW script',
|
label: 'Show CREATE VIEW script',
|
||||||
sqlTemplate: 'CREATE OBJECT',
|
sqlTemplate: 'CREATE OBJECT',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Show CREATE TABLE script',
|
||||||
|
sqlTemplate: 'CREATE TABLE',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Open structure',
|
||||||
|
tab: 'TableStructureTab',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
procedures: [
|
procedures: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
import FormStyledButton from '../widgets/FormStyledButton';
|
import FormStyledButton from '../widgets/FormStyledButton';
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
@@ -148,8 +149,9 @@ function SourceTargetConfig({
|
|||||||
{ value: 'jsonl', label: 'JSON lines file(s)', directions: ['source', 'target'] },
|
{ value: 'jsonl', label: 'JSON lines file(s)', directions: ['source', 'target'] },
|
||||||
{ value: 'excel', label: 'MS Excel file(s)', directions: ['source'] },
|
{ value: 'excel', label: 'MS Excel file(s)', directions: ['source'] },
|
||||||
];
|
];
|
||||||
const { values } = useFormikContext();
|
const { values, setFieldValue } = useFormikContext();
|
||||||
const storageType = values[storageTypeField];
|
const storageType = values[storageTypeField];
|
||||||
|
const dbinfo = useDatabaseInfo({ conid: values[connectionIdField], database: values[databaseNameField] });
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
{direction == 'source' && <Label>Source configuration</Label>}
|
{direction == 'source' && <Label>Source configuration</Label>}
|
||||||
@@ -172,6 +174,29 @@ function SourceTargetConfig({
|
|||||||
databaseName={databaseNameField}
|
databaseName={databaseNameField}
|
||||||
name={tablesField}
|
name={tablesField}
|
||||||
/>
|
/>
|
||||||
|
<div>
|
||||||
|
<FormStyledButton
|
||||||
|
type="button"
|
||||||
|
value="All tables"
|
||||||
|
onClick={() =>
|
||||||
|
setFieldValue(
|
||||||
|
'sourceList',
|
||||||
|
_.uniq([...(values.sourceList || []), ...(dbinfo && dbinfo.tables.map((x) => x.pureName))])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<FormStyledButton
|
||||||
|
type="button"
|
||||||
|
value="All views"
|
||||||
|
onClick={() =>
|
||||||
|
setFieldValue(
|
||||||
|
'sourceList',
|
||||||
|
_.uniq([...(values.sourceList || []), ...(dbinfo && dbinfo.views.map((x) => x.pureName))])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<FormStyledButton type="button" value="Remove all" onClick={() => setFieldValue('sourceList', [])} />
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ import _ from 'lodash';
|
|||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
|
|
||||||
import { useConnectionInfo, getTableInfo, getConnectionInfo, getSqlObjectInfo } from '../utility/metadataLoaders';
|
import {
|
||||||
|
useConnectionInfo,
|
||||||
|
getTableInfo,
|
||||||
|
getDbCore,
|
||||||
|
getConnectionInfo,
|
||||||
|
getSqlObjectInfo,
|
||||||
|
} from '../utility/metadataLoaders';
|
||||||
import SqlEditor from '../sqleditor/SqlEditor';
|
import SqlEditor from '../sqleditor/SqlEditor';
|
||||||
import { useUpdateDatabaseForTab, useSetOpenedTabs, useOpenedTabs } from '../utility/globalState';
|
import { useUpdateDatabaseForTab, useSetOpenedTabs, useOpenedTabs } from '../utility/globalState';
|
||||||
import QueryToolbar from '../query/QueryToolbar';
|
import QueryToolbar from '../query/QueryToolbar';
|
||||||
@@ -24,7 +30,7 @@ function useSqlTemplate(sqlTemplate, props) {
|
|||||||
|
|
||||||
async function loadTemplate() {
|
async function loadTemplate() {
|
||||||
if (sqlTemplate == 'CREATE TABLE') {
|
if (sqlTemplate == 'CREATE TABLE') {
|
||||||
const tableInfo = await getTableInfo(props);
|
const tableInfo = await getDbCore(props, props.objectTypeField || 'tables');
|
||||||
const connection = await getConnectionInfo(props);
|
const connection = await getConnectionInfo(props);
|
||||||
const driver = engines(connection.engine);
|
const driver = engines(connection.engine);
|
||||||
const dmp = driver.createDumper();
|
const dmp = driver.createDumper();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import ObjectListControl from '../utility/ObjectListControl';
|
|||||||
import { TableColumn } from '../utility/TableControl';
|
import { TableColumn } from '../utility/TableControl';
|
||||||
import columnAppObject from '../appobj/columnAppObject';
|
import columnAppObject from '../appobj/columnAppObject';
|
||||||
import constraintAppObject from '../appobj/constraintAppObject';
|
import constraintAppObject from '../appobj/constraintAppObject';
|
||||||
import { useTableInfo } from '../utility/metadataLoaders';
|
import { useTableInfo, useDbCore } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
const WhitePage = styled.div`
|
const WhitePage = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -16,8 +16,8 @@ const WhitePage = styled.div`
|
|||||||
background-color: white;
|
background-color: white;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function TableStructureTab({ conid, database, schemaName, pureName }) {
|
export default function TableStructureTab({ conid, database, schemaName, pureName, objectTypeField = 'tables' }) {
|
||||||
const tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
const tableInfo = useDbCore({ conid, database, schemaName, pureName, objectTypeField });
|
||||||
if (!tableInfo) return null;
|
if (!tableInfo) return null;
|
||||||
const { columns, primaryKey, foreignKeys, dependencies } = tableInfo;
|
const { columns, primaryKey, foreignKeys, dependencies } = tableInfo;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export function useDatabaseInfo(args) {
|
|||||||
return useCore(databaseInfoLoader, args);
|
return useCore(databaseInfoLoader, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDbCore(args, objectTypeField = undefined) {
|
export async function getDbCore(args, objectTypeField = undefined) {
|
||||||
const db = await getDatabaseInfo(args);
|
const db = await getDatabaseInfo(args);
|
||||||
if (!db) return null;
|
if (!db) return null;
|
||||||
return db[objectTypeField || args.objectTypeField].find(
|
return db[objectTypeField || args.objectTypeField].find(
|
||||||
|
|||||||
Reference in New Issue
Block a user