mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 16:26:00 +00:00
metadata loaders refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
93
packages/web/src/utility/metadataLoaders.js
Normal file
93
packages/web/src/utility/metadataLoaders.js
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user