diff --git a/packages/web/src/appobj/tableAppObject.js b/packages/web/src/appobj/tableAppObject.js
index fcb57bae..fbd644d2 100644
--- a/packages/web/src/appobj/tableAppObject.js
+++ b/packages/web/src/appobj/tableAppObject.js
@@ -2,7 +2,7 @@ import React from 'react';
import { TableIcon } from '../icons';
import { DropDownMenuItem } from '../modals/DropDownMenu';
import { openNewTab } from '../utility/common';
-import getConnectionInfo from '../utility/getConnectionInfo';
+import { getConnectionInfo } from '../utility/metadataLoaders';
import fullDisplayName from '../utility/fullDisplayName';
import { filterName } from '@dbgate/datalib';
diff --git a/packages/web/src/appobj/viewAppObject.js b/packages/web/src/appobj/viewAppObject.js
index 64bf2d59..95fd32cc 100644
--- a/packages/web/src/appobj/viewAppObject.js
+++ b/packages/web/src/appobj/viewAppObject.js
@@ -2,7 +2,7 @@ import React from 'react';
import { ViewIcon } from '../icons';
import { DropDownMenuItem } from '../modals/DropDownMenu';
import { openNewTab } from '../utility/common';
-import getConnectionInfo from '../utility/getConnectionInfo';
+import { getConnectionInfo } from '../utility/metadataLoaders';
import fullDisplayName from '../utility/fullDisplayName';
import { filterName } from '@dbgate/datalib';
diff --git a/packages/web/src/tabs/QueryTab.js b/packages/web/src/tabs/QueryTab.js
index 6ccdf813..193f7e32 100644
--- a/packages/web/src/tabs/QueryTab.js
+++ b/packages/web/src/tabs/QueryTab.js
@@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import _ from 'lodash';
import axios from '../utility/axios';
-import useConnectionInfo from '../utility/useConnectionInfo';
+import { useConnectionInfo } from '../utility/metadataLoaders';
import SqlEditor from '../sqleditor/SqlEditor';
import { useUpdateDatabaseForTab } from '../utility/globalState';
import QueryToolbar from '../query/QueryToolbar';
diff --git a/packages/web/src/tabs/TableCreateScriptTab.js b/packages/web/src/tabs/TableCreateScriptTab.js
index 1935a18a..24270235 100644
--- a/packages/web/src/tabs/TableCreateScriptTab.js
+++ b/packages/web/src/tabs/TableCreateScriptTab.js
@@ -1,7 +1,6 @@
import React from 'react';
import engines from '@dbgate/engines';
-import useTableInfo from '../utility/useTableInfo';
-import useConnectionInfo from '../utility/useConnectionInfo';
+import { useTableInfo, useConnectionInfo } from '../utility/metadataLoaders';
import SqlEditor from '../sqleditor/SqlEditor';
export default function TableCreateScriptTab({ conid, database, schemaName, pureName }) {
diff --git a/packages/web/src/tabs/TableDataTab.js b/packages/web/src/tabs/TableDataTab.js
index 859211ec..99386c92 100644
--- a/packages/web/src/tabs/TableDataTab.js
+++ b/packages/web/src/tabs/TableDataTab.js
@@ -4,10 +4,8 @@ import styled from 'styled-components';
import theme from '../theme';
import DataGrid from '../datagrid/DataGrid';
import { TableGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
-import useTableInfo from '../utility/useTableInfo';
-import useConnectionInfo from '../utility/useConnectionInfo';
+import { useTableInfo, useConnectionInfo, getTableInfo } from '../utility/metadataLoaders';
import engines from '@dbgate/engines';
-import getTableInfo from '../utility/getTableInfo';
import useUndoReducer from '../utility/useUndoReducer';
import usePropsCompare from '../utility/usePropsCompare';
import { useUpdateDatabaseForTab } from '../utility/globalState';
@@ -26,7 +24,7 @@ export default function TableDataTab({ conid, database, schemaName, pureName, ta
const display = React.useMemo(
() =>
tableInfo && connection
- ? new TableGridDisplay(tableInfo, engines(connection), config, setConfig, cache, setCache, name =>
+ ? new TableGridDisplay(tableInfo, engines(connection), config, setConfig, cache, setCache, (name) =>
getTableInfo({ conid, database, ...name })
)
: null,
diff --git a/packages/web/src/tabs/TableStructureTab.js b/packages/web/src/tabs/TableStructureTab.js
index 5fdda944..dec18710 100644
--- a/packages/web/src/tabs/TableStructureTab.js
+++ b/packages/web/src/tabs/TableStructureTab.js
@@ -1,13 +1,11 @@
import React from 'react';
import styled from 'styled-components';
import _ from 'lodash';
-import theme from '../theme';
-import useFetch from '../utility/useFetch';
import ObjectListControl from '../utility/ObjectListControl';
import { TableColumn } from '../utility/TableControl';
import columnAppObject from '../appobj/columnAppObject';
import constraintAppObject from '../appobj/constraintAppObject';
-import useTableInfo from '../utility/useTableInfo';
+import { useTableInfo } from '../utility/metadataLoaders';
const WhitePage = styled.div`
position: absolute;
@@ -33,7 +31,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
fieldName="notNull"
header="Not NULL"
sortable={true}
- formatter={row => (row.notNull ? 'YES' : 'NO')}
+ formatter={(row) => (row.notNull ? 'YES' : 'NO')}
/>
@@ -41,14 +39,14 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
fieldName="isSparse"
header="Is Sparse"
sortable={true}
- formatter={row => (row.isSparse ? 'YES' : 'NO')}
+ formatter={(row) => (row.isSparse ? 'YES' : 'NO')}
/>
(row.isPersisted ? 'YES' : 'NO')}
+ formatter={(row) => (row.isPersisted ? 'YES' : 'NO')}
/>
{/* {_.includes(dbCaps.columnListOptionalColumns, 'referencedTableNamesFormatted') && (
@@ -80,7 +78,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
row.columns.map(x => x.columnName).join(', ')}
+ formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
/>
@@ -88,13 +86,13 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
row.columns.map(x => x.columnName).join(', ')}
+ formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
/>
- row.refTableName} />
+ row.refTableName} />
row.columns.map(x => x.refColumnName).join(', ')}
+ formatter={(row) => row.columns.map((x) => x.refColumnName).join(', ')}
/>
@@ -104,13 +102,13 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
row.columns.map(x => x.columnName).join(', ')}
+ formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
/>
- row.pureName} />
+ row.pureName} />
row.columns.map(x => x.refColumnName).join(', ')}
+ formatter={(row) => row.columns.map((x) => x.refColumnName).join(', ')}
/>
diff --git a/packages/web/src/tabs/ViewCreateScriptTab.js b/packages/web/src/tabs/ViewCreateScriptTab.js
index 78e38f45..2f531c38 100644
--- a/packages/web/src/tabs/ViewCreateScriptTab.js
+++ b/packages/web/src/tabs/ViewCreateScriptTab.js
@@ -1,7 +1,6 @@
import React from 'react';
-import useConnectionInfo from '../utility/useConnectionInfo';
+import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
import SqlEditor from '../sqleditor/SqlEditor';
-import useViewInfo from '../utility/useViewInfo';
export default function ViewCreateScriptTab({ conid, database, schemaName, pureName }) {
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
diff --git a/packages/web/src/tabs/ViewDataTab.js b/packages/web/src/tabs/ViewDataTab.js
index 82d57bdb..5097d378 100644
--- a/packages/web/src/tabs/ViewDataTab.js
+++ b/packages/web/src/tabs/ViewDataTab.js
@@ -4,14 +4,11 @@ import styled from 'styled-components';
import theme from '../theme';
import DataGrid from '../datagrid/DataGrid';
import { ViewGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
-import useTableInfo from '../utility/useTableInfo';
-import useConnectionInfo from '../utility/useConnectionInfo';
+import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
import engines from '@dbgate/engines';
-import getTableInfo from '../utility/getTableInfo';
import useUndoReducer from '../utility/useUndoReducer';
import usePropsCompare from '../utility/usePropsCompare';
import { useUpdateDatabaseForTab } from '../utility/globalState';
-import useViewInfo from '../utility/useViewInfo';
export default function ViewDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
@@ -26,9 +23,8 @@ export default function ViewDataTab({ conid, database, schemaName, pureName, tab
const display = React.useMemo(
() =>
- viewInfo && connection
- ? new ViewGridDisplay(viewInfo, engines(connection), config, setConfig, cache, setCache,
- )
+ viewInfo && connection
+ ? new ViewGridDisplay(viewInfo, engines(connection), config, setConfig, cache, setCache)
: null,
[viewInfo, connection, config, cache]
);
diff --git a/packages/web/src/utility/getConnectionInfo.js b/packages/web/src/utility/getConnectionInfo.js
deleted file mode 100644
index 9ab0a79f..00000000
--- a/packages/web/src/utility/getConnectionInfo.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import axios from './axios';
-
-export default async function getConnectionInfo(conid) {
- const resp = await axios.request({
- method: 'get',
- params: { conid },
- url: 'connections/get',
- });
- /** @type {import('@dbgate/types').StoredConnection} */
- const res = resp.data;
- return res;
-}
diff --git a/packages/web/src/utility/getTableInfo.js b/packages/web/src/utility/getTableInfo.js
deleted file mode 100644
index f81194cf..00000000
--- a/packages/web/src/utility/getTableInfo.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import axios from './axios';
-
-export default async function getTableInfo({ conid, database, schemaName, pureName }) {
- const resp = await axios.request({
- method: 'get',
- url: 'metadata/table-info',
- params: { conid, database, schemaName, pureName },
- });
- /** @type {import('@dbgate/types').TableInfo} */
- const res = resp.data;
- return res;
-}
diff --git a/packages/web/src/utility/globalState.js b/packages/web/src/utility/globalState.js
index 019b6c5c..c64c33d0 100644
--- a/packages/web/src/utility/globalState.js
+++ b/packages/web/src/utility/globalState.js
@@ -1,7 +1,7 @@
import _ from 'lodash';
import React from 'react';
import useStorage from './useStorage';
-import useConnectionInfo from './useConnectionInfo';
+import { useConnectionInfo } from './metadataLoaders';
import usePrevious from './usePrevious';
function createGlobalState(defaultValue) {
@@ -50,7 +50,7 @@ const [CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabaseCore] =
function useSetCurrentDatabase() {
const setDb = useSetCurrentDatabaseCore();
const db = useCurrentDatabase();
- return value => {
+ return (value) => {
if (_.get(db, 'name') !== _.get(value, 'name') || _.get(db, 'connection._id') != _.get(value, 'connection._id')) {
setDb(value);
}
diff --git a/packages/web/src/utility/metadataLoaders.js b/packages/web/src/utility/metadataLoaders.js
new file mode 100644
index 00000000..39304b8c
--- /dev/null
+++ b/packages/web/src/utility/metadataLoaders.js
@@ -0,0 +1,93 @@
+import useFetch from './useFetch';
+import axios from './axios';
+
+// /** @returns {import('@dbgate/types').TableInfo} */
+// function makeTableInfo(x) {
+// return x;
+// }
+
+// const tableInfoLoader = ({ conid, database, schemaName, pureName }) => ({
+// url: 'metadata/table-info',
+// params: { conid, database, schemaName, pureName },
+// reloadTrigger: `database-structure-changed-${conid}-${database}`,
+// type: makeTableInfo,
+// });
+
+// function createGet(loader) {
+// return async (args) => {
+// const { url, params, reloadTrigger, type } = loader(args);
+// const resp = await axios.request({
+// method: 'get',
+// url,
+// params,
+// });
+// return type(resp.data);
+// };
+// }
+
+// function createUse(loader) {
+// return async (args) => {
+// const { url, params, reloadTrigger, type } = loader(args);
+
+// const res = useFetch({
+// url,
+// params,
+// reloadTrigger,
+// });
+// return type(res);
+// };
+// }
+
+// export const getTableInfo = createGet(tableInfoLoader);
+// export const useTableInfo = createUse(tableInfoLoader);
+
+export async function getTableInfo({ conid, database, schemaName, pureName }) {
+ const resp = await axios.request({
+ method: 'get',
+ url: 'metadata/table-info',
+ params: { conid, database, schemaName, pureName },
+ });
+ /** @type {import('@dbgate/types').TableInfo} */
+ const res = resp.data;
+ return res;
+}
+
+export function useTableInfo({ conid, database, schemaName, pureName }) {
+ /** @type {import('@dbgate/types').TableInfo} */
+ const tableInfo = useFetch({
+ url: 'metadata/table-info',
+ params: { conid, database, schemaName, pureName },
+ reloadTrigger: `database-structure-changed-${conid}-${database}`,
+ });
+ return tableInfo;
+}
+
+export function useViewInfo({ conid, database, schemaName, pureName }) {
+ /** @type {import('@dbgate/types').ViewInfo} */
+ const viewInfo = useFetch({
+ url: 'metadata/view-info',
+ params: { conid, database, schemaName, pureName },
+ reloadTrigger: `database-structure-changed-${conid}-${database}`,
+ });
+ return viewInfo;
+}
+
+export function useConnectionInfo(conid) {
+ /** @type {import('@dbgate/types').StoredConnection} */
+ const connection = useFetch({
+ params: { conid },
+ url: 'connections/get',
+ });
+ return connection;
+}
+
+export async function getConnectionInfo(conid) {
+ const resp = await axios.request({
+ method: 'get',
+ params: { conid },
+ url: 'connections/get',
+ });
+ /** @type {import('@dbgate/types').StoredConnection} */
+ const res = resp.data;
+ return res;
+}
diff --git a/packages/web/src/utility/useConnectionInfo.js b/packages/web/src/utility/useConnectionInfo.js
deleted file mode 100644
index 369c9814..00000000
--- a/packages/web/src/utility/useConnectionInfo.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import useFetch from './useFetch';
-
-export default function useConnectionInfo(conid) {
- /** @type {import('@dbgate/types').StoredConnection} */
- const connection = useFetch({
- params: { conid },
- url: 'connections/get',
- });
- return connection;
-}
diff --git a/packages/web/src/utility/useTableInfo.js b/packages/web/src/utility/useTableInfo.js
deleted file mode 100644
index 07c6a17b..00000000
--- a/packages/web/src/utility/useTableInfo.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import useFetch from './useFetch';
-
-export default function useTableInfo({ conid, database, schemaName, pureName }) {
- /** @type {import('@dbgate/types').TableInfo} */
- const tableInfo = useFetch({
- url: 'metadata/table-info',
- params: { conid, database, schemaName, pureName },
- reloadTrigger: `database-structure-changed-${conid}-${database}`,
- });
- return tableInfo;
-}
diff --git a/packages/web/src/utility/useViewInfo.js b/packages/web/src/utility/useViewInfo.js
deleted file mode 100644
index 4d512025..00000000
--- a/packages/web/src/utility/useViewInfo.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import useFetch from './useFetch';
-
-export default function useViewInfo({ conid, database, schemaName, pureName }) {
- /** @type {import('@dbgate/types').ViewInfo} */
- const viewInfo = useFetch({
- url: 'metadata/view-info',
- params: { conid, database, schemaName, pureName },
- reloadTrigger: `database-structure-changed-${conid}-${database}`,
- });
- return viewInfo;
-}