mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 07:56:01 +00:00
handle disconnected database
This commit is contained in:
@@ -85,6 +85,16 @@ module.exports = {
|
||||
return res;
|
||||
},
|
||||
|
||||
status_meta: 'get',
|
||||
async status({ conid, database }) {
|
||||
const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||
if (existing) return existing.status;
|
||||
return {
|
||||
name: 'error',
|
||||
message: 'Not connected',
|
||||
};
|
||||
},
|
||||
|
||||
ping_meta: 'post',
|
||||
async ping({ conid, database }) {
|
||||
const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||
|
||||
@@ -10,16 +10,31 @@ let analysedStructure = null;
|
||||
let lastPing = null;
|
||||
let lastStatus = null;
|
||||
|
||||
async function checkedAsyncCall(promise) {
|
||||
try {
|
||||
const res = await promise;
|
||||
return res;
|
||||
} catch (err) {
|
||||
setStatus({
|
||||
name: 'error',
|
||||
message: err.message,
|
||||
});
|
||||
// console.error(err);
|
||||
setTimeout(() => process.exit(1), 1000);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFullRefresh() {
|
||||
const driver = engines(storedConnection);
|
||||
analysedStructure = await driver.analyseFull(systemConnection);
|
||||
analysedStructure = await checkedAsyncCall(driver.analyseFull(systemConnection));
|
||||
process.send({ msgtype: 'structure', structure: analysedStructure });
|
||||
setStatusName('ok');
|
||||
}
|
||||
|
||||
async function handleIncrementalRefresh() {
|
||||
const driver = engines(storedConnection);
|
||||
const newStructure = await driver.analyseIncremental(systemConnection, analysedStructure);
|
||||
const newStructure = await checkedAsyncCall(driver.analyseIncremental(systemConnection, analysedStructure));
|
||||
if (newStructure != null) {
|
||||
analysedStructure = newStructure;
|
||||
process.send({ msgtype: 'structure', structure: analysedStructure });
|
||||
@@ -43,9 +58,8 @@ async function handleConnect({ connection, structure }) {
|
||||
lastPing = new Date().getTime();
|
||||
|
||||
if (!structure) setStatusName('pending');
|
||||
else setStatusName('ok');
|
||||
const driver = engines(storedConnection);
|
||||
systemConnection = await driverConnect(driver, storedConnection);
|
||||
systemConnection = await checkedAsyncCall(driverConnect(driver, storedConnection));
|
||||
if (structure) {
|
||||
analysedStructure = structure;
|
||||
handleIncrementalRefresh();
|
||||
|
||||
@@ -27,6 +27,12 @@ const sqlObjectListLoader = ({ conid, database }) => ({
|
||||
reloadTrigger: [`database-structure-changed-${conid}-${database}`, `database-status-changed-${conid}-${database}`],
|
||||
});
|
||||
|
||||
const databaseStatusLoader = ({ conid, database }) => ({
|
||||
url: 'database-connections/status',
|
||||
params: { conid, database },
|
||||
reloadTrigger: `database-status-changed-${conid}-${database}`,
|
||||
});
|
||||
|
||||
const databaseListLoader = ({ conid }) => ({
|
||||
url: 'server-connections/list-databases',
|
||||
params: { conid },
|
||||
@@ -125,6 +131,13 @@ export function useSqlObjectList(args) {
|
||||
return useCore(sqlObjectListLoader, args);
|
||||
}
|
||||
|
||||
export function getDatabaseStatus(args) {
|
||||
return getCore(databaseStatusLoader, args);
|
||||
}
|
||||
export function useDatabaseStatus(args) {
|
||||
return useCore(databaseStatusLoader, args);
|
||||
}
|
||||
|
||||
export function getDatabaseList(args) {
|
||||
return getCore(databaseListLoader, args);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import styled from 'styled-components';
|
||||
|
||||
import { getEngineIcon } from '../icons';
|
||||
import { useCurrentDatabase } from '../utility/globalState';
|
||||
import { useDatabaseStatus } from '../utility/metadataLoaders';
|
||||
import { FontIcon } from '../icons';
|
||||
|
||||
const Container = styled.div`
|
||||
display: flex;
|
||||
@@ -18,6 +20,7 @@ const Item = styled.div`
|
||||
|
||||
export default function StatusBar() {
|
||||
const { name, connection } = useCurrentDatabase() || {};
|
||||
const status = useDatabaseStatus(connection ? { conid: connection._id, database: name } : {});
|
||||
const { displayName, server, user, engine } = connection || {};
|
||||
const EngineIcon = getEngineIcon(engine);
|
||||
return (
|
||||
@@ -38,6 +41,26 @@ export default function StatusBar() {
|
||||
<i className="fas fa-user" /> {user}
|
||||
</Item>
|
||||
)}
|
||||
|
||||
{status && (
|
||||
<Item>
|
||||
{status.name == 'pending' && (
|
||||
<>
|
||||
<FontIcon icon="fas fa-spinner fa-spin" /> Loading
|
||||
</>
|
||||
)}
|
||||
{status.name == 'ok' && (
|
||||
<>
|
||||
<FontIcon icon="fas fa-check-circle lime" /> Connected
|
||||
</>
|
||||
)}
|
||||
{status.name == 'error' && (
|
||||
<>
|
||||
<FontIcon icon="fas fa-times-circle red" /> Error
|
||||
</>
|
||||
)}
|
||||
</Item>
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user