mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 13:16:00 +00:00
get server version
This commit is contained in:
@@ -17,6 +17,13 @@ module.exports = {
|
|||||||
existing.structure = structure;
|
existing.structure = structure;
|
||||||
socket.emitChanged(`database-structure-changed-${conid}-${database}`);
|
socket.emitChanged(`database-structure-changed-${conid}-${database}`);
|
||||||
},
|
},
|
||||||
|
handle_version(conid, database, { version }) {
|
||||||
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
|
if (!existing) return;
|
||||||
|
existing.serverVersion = version;
|
||||||
|
socket.emitChanged(`database-server-version-changed-${conid}-${database}`);
|
||||||
|
},
|
||||||
|
|
||||||
handle_error(conid, database, props) {
|
handle_error(conid, database, props) {
|
||||||
const { error } = props;
|
const { error } = props;
|
||||||
console.log(`Error in database connection ${conid}, database ${database}: ${error}`);
|
console.log(`Error in database connection ${conid}, database ${database}: ${error}`);
|
||||||
@@ -51,6 +58,7 @@ module.exports = {
|
|||||||
database,
|
database,
|
||||||
subprocess,
|
subprocess,
|
||||||
structure: lastClosed ? lastClosed.structure : DatabaseAnalyser.createEmptyStructure(),
|
structure: lastClosed ? lastClosed.structure : DatabaseAnalyser.createEmptyStructure(),
|
||||||
|
serverVersion: lastClosed ? lastClosed.serverVersion : null,
|
||||||
connection,
|
connection,
|
||||||
status: { name: 'pending' },
|
status: { name: 'pending' },
|
||||||
};
|
};
|
||||||
@@ -175,6 +183,12 @@ module.exports = {
|
|||||||
// };
|
// };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
serverVersion_meta: 'get',
|
||||||
|
async serverVersion({ conid, database }) {
|
||||||
|
const opened = await this.ensureOpened(conid, database);
|
||||||
|
return opened.serverVersion;
|
||||||
|
},
|
||||||
|
|
||||||
sqlPreview_meta: 'post',
|
sqlPreview_meta: 'post',
|
||||||
async sqlPreview({ conid, database, objects, options }) {
|
async sqlPreview({ conid, database, objects, options }) {
|
||||||
// wait for structure
|
// wait for structure
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ module.exports = {
|
|||||||
existing.databases = databases;
|
existing.databases = databases;
|
||||||
socket.emitChanged(`database-list-changed-${conid}`);
|
socket.emitChanged(`database-list-changed-${conid}`);
|
||||||
},
|
},
|
||||||
|
handle_version(conid, { version }) {
|
||||||
|
const existing = this.opened.find(x => x.conid == conid);
|
||||||
|
if (!existing) return;
|
||||||
|
existing.version = version;
|
||||||
|
socket.emitChanged(`server-version-changed-${conid}`);
|
||||||
|
},
|
||||||
handle_status(conid, { status }) {
|
handle_status(conid, { status }) {
|
||||||
const existing = this.opened.find(x => x.conid == conid);
|
const existing = this.opened.find(x => x.conid == conid);
|
||||||
if (!existing) return;
|
if (!existing) return;
|
||||||
@@ -85,6 +91,12 @@ module.exports = {
|
|||||||
return opened.databases;
|
return opened.databases;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
version_meta: 'get',
|
||||||
|
async version({ conid }) {
|
||||||
|
const opened = await this.ensureOpened(conid);
|
||||||
|
return opened.version;
|
||||||
|
},
|
||||||
|
|
||||||
serverStatus_meta: 'get',
|
serverStatus_meta: 'get',
|
||||||
async serverStatus() {
|
async serverStatus() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ function setStatusName(name) {
|
|||||||
setStatus({ name });
|
setStatus({ name });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function readVersion() {
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
const version = await driver.getVersion(systemConnection);
|
||||||
|
process.send({ msgtype: 'version', version });
|
||||||
|
}
|
||||||
|
|
||||||
async function handleConnect({ connection, structure }) {
|
async function handleConnect({ connection, structure }) {
|
||||||
storedConnection = connection;
|
storedConnection = connection;
|
||||||
lastPing = new Date().getTime();
|
lastPing = new Date().getTime();
|
||||||
@@ -63,6 +69,7 @@ async function handleConnect({ connection, structure }) {
|
|||||||
if (!structure) setStatusName('pending');
|
if (!structure) setStatusName('pending');
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection));
|
systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection));
|
||||||
|
readVersion();
|
||||||
if (structure) {
|
if (structure) {
|
||||||
analysedStructure = structure;
|
analysedStructure = structure;
|
||||||
handleIncrementalRefresh();
|
handleIncrementalRefresh();
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ async function handleRefresh() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function readVersion() {
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
const version = await driver.getVersion(systemConnection);
|
||||||
|
process.send({ msgtype: 'version', version });
|
||||||
|
}
|
||||||
|
|
||||||
function setStatus(status) {
|
function setStatus(status) {
|
||||||
const statusString = stableStringify(status);
|
const statusString = stableStringify(status);
|
||||||
if (lastStatus != statusString) {
|
if (lastStatus != statusString) {
|
||||||
@@ -51,6 +57,7 @@ async function handleConnect(connection) {
|
|||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
try {
|
try {
|
||||||
systemConnection = await connectUtility(driver, storedConnection);
|
systemConnection = await connectUtility(driver, storedConnection);
|
||||||
|
readVersion();
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
setInterval(handleRefresh, 30 * 1000);
|
setInterval(handleRefresh, 30 * 1000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
1
packages/types/index.d.ts
vendored
1
packages/types/index.d.ts
vendored
@@ -4,6 +4,7 @@ export interface OpenedDatabaseConnection {
|
|||||||
conid: string;
|
conid: string;
|
||||||
database: string;
|
database: string;
|
||||||
structure: DatabaseInfo;
|
structure: DatabaseInfo;
|
||||||
|
serverVersion?: any;
|
||||||
subprocess: ChildProcess;
|
subprocess: ChildProcess;
|
||||||
disconnected?: boolean;
|
disconnected?: boolean;
|
||||||
status?: {
|
status?: {
|
||||||
|
|||||||
@@ -14,7 +14,12 @@
|
|||||||
import { extensions } from '../stores';
|
import { extensions } from '../stores';
|
||||||
import stableStringify from 'json-stable-stringify';
|
import stableStringify from 'json-stable-stringify';
|
||||||
|
|
||||||
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
import {
|
||||||
|
useConnectionInfo,
|
||||||
|
useDatabaseInfo,
|
||||||
|
useDatabaseServerVersion,
|
||||||
|
useServerVersion,
|
||||||
|
} from '../utility/metadataLoaders';
|
||||||
|
|
||||||
import DataGrid from './DataGrid.svelte';
|
import DataGrid from './DataGrid.svelte';
|
||||||
import ReferenceHeader from './ReferenceHeader.svelte';
|
import ReferenceHeader from './ReferenceHeader.svelte';
|
||||||
@@ -38,6 +43,9 @@
|
|||||||
|
|
||||||
$: connection = useConnectionInfo({ conid });
|
$: connection = useConnectionInfo({ conid });
|
||||||
$: dbinfo = useDatabaseInfo({ conid, database });
|
$: dbinfo = useDatabaseInfo({ conid, database });
|
||||||
|
// $: serverVersion = useDatabaseServerVersion({ conid, database });
|
||||||
|
|
||||||
|
// $: console.log('serverVersion', $serverVersion);
|
||||||
|
|
||||||
let myLoadedTime = 0;
|
let myLoadedTime = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,18 @@ const databaseListLoader = ({ conid }) => ({
|
|||||||
reloadTrigger: `database-list-changed-${conid}`,
|
reloadTrigger: `database-list-changed-${conid}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const serverVersionLoader = ({ conid }) => ({
|
||||||
|
url: 'server-connections/version',
|
||||||
|
params: { conid },
|
||||||
|
reloadTrigger: `server-version-changed-${conid}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const databaseServerVersionLoader = ({ conid, database }) => ({
|
||||||
|
url: 'database-connections/server-version',
|
||||||
|
params: { conid, database },
|
||||||
|
reloadTrigger: `database-server-version-changed-${conid}-${database}`,
|
||||||
|
});
|
||||||
|
|
||||||
const archiveFoldersLoader = () => ({
|
const archiveFoldersLoader = () => ({
|
||||||
url: 'archive/folders',
|
url: 'archive/folders',
|
||||||
params: {},
|
params: {},
|
||||||
@@ -318,6 +330,21 @@ export function useDatabaseList(args) {
|
|||||||
return useCore(databaseListLoader, args);
|
return useCore(databaseListLoader, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getServerVersion(args) {
|
||||||
|
return getCore(serverVersionLoader, args);
|
||||||
|
}
|
||||||
|
export function useServerVersion(args) {
|
||||||
|
return useCore(serverVersionLoader, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDatabaseServerVersion(args) {
|
||||||
|
return getCore(databaseServerVersionLoader, args);
|
||||||
|
}
|
||||||
|
export function useDatabaseServerVersion(args) {
|
||||||
|
return useCore(databaseServerVersionLoader, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getServerStatus() {
|
export function getServerStatus() {
|
||||||
return getCore(serverStatusLoader, {});
|
return getCore(serverStatusLoader, {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,17 @@ const driver = {
|
|||||||
},
|
},
|
||||||
async getVersion(pool) {
|
async getVersion(pool) {
|
||||||
const { version } = (await this.query(pool, 'SELECT @@VERSION AS version')).rows[0];
|
const { version } = (await this.query(pool, 'SELECT @@VERSION AS version')).rows[0];
|
||||||
return { version };
|
|
||||||
|
const { productVersion } = (
|
||||||
|
await this.query(pool, "SELECT SERVERPROPERTY ('productversion') as productVersion")
|
||||||
|
).rows[0];
|
||||||
|
let productVersionNumber = 0;
|
||||||
|
if (productVersion) {
|
||||||
|
const splitted = productVersion.split('.');
|
||||||
|
const number = parseInt(splitted[0]) || 0;
|
||||||
|
productVersionNumber = number;
|
||||||
|
}
|
||||||
|
return { version, productVersion, productVersionNumber };
|
||||||
},
|
},
|
||||||
async listDatabases(pool) {
|
async listDatabases(pool) {
|
||||||
const { rows } = await this.query(pool, 'SELECT name FROM sys.databases order by name');
|
const { rows } = await this.query(pool, 'SELECT name FROM sys.databases order by name');
|
||||||
|
|||||||
Reference in New Issue
Block a user