mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 09:03:58 +00:00
redis db context menu
This commit is contained in:
@@ -142,6 +142,7 @@ module.exports = {
|
|||||||
createDatabase_meta: true,
|
createDatabase_meta: true,
|
||||||
async createDatabase({ conid, name }) {
|
async createDatabase({ conid, name }) {
|
||||||
const opened = await this.ensureOpened(conid);
|
const opened = await this.ensureOpened(conid);
|
||||||
|
if (opened.connection.isReadOnly) return false;
|
||||||
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
opened.subprocess.send({ msgtype: 'createDatabase', name });
|
||||||
return { status: 'ok' };
|
return { status: 'ok' };
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export const driverBase = {
|
|||||||
dumperClass: SqlDumper,
|
dumperClass: SqlDumper,
|
||||||
dialect,
|
dialect,
|
||||||
databaseEngineTypes: ['sql'],
|
databaseEngineTypes: ['sql'],
|
||||||
|
supportedCreateDatabase: true,
|
||||||
|
|
||||||
async analyseFull(pool, version) {
|
async analyseFull(pool, version) {
|
||||||
const analyser = new this.analyserClass(pool, this, version);
|
const analyser = new this.analyserClass(pool, this, version);
|
||||||
|
|||||||
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -61,6 +61,7 @@ export interface EngineDriver {
|
|||||||
supportedKeyTypes: SupportedDbKeyType[];
|
supportedKeyTypes: SupportedDbKeyType[];
|
||||||
supportsDatabaseUrl?: boolean;
|
supportsDatabaseUrl?: boolean;
|
||||||
isElectronOnly?: boolean;
|
isElectronOnly?: boolean;
|
||||||
|
supportedCreateDatabase?: boolean;
|
||||||
showConnectionField?: (field: string, values: any) => boolean;
|
showConnectionField?: (field: string, values: any) => boolean;
|
||||||
showConnectionTab?: (tab: 'ssl' | 'sshTunnel', values: any) => boolean;
|
showConnectionTab?: (tab: 'ssl' | 'sshTunnel', values: any) => boolean;
|
||||||
beforeConnectionSave?: (values: any) => any;
|
beforeConnectionSave?: (values: any) => any;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getContextMenu = () => {
|
const getContextMenu = () => {
|
||||||
|
const driver = $extensions.drivers.find(x => x.engine == data.engine);
|
||||||
const config = getCurrentConfig();
|
const config = getCurrentConfig();
|
||||||
const handleRefresh = () => {
|
const handleRefresh = () => {
|
||||||
apiCall('server-connections/refresh', { conid: data._id });
|
apiCall('server-connections/refresh', { conid: data._id });
|
||||||
@@ -146,7 +147,9 @@
|
|||||||
text: 'Disconnect',
|
text: 'Disconnect',
|
||||||
onClick: handleDisconnect,
|
onClick: handleDisconnect,
|
||||||
},
|
},
|
||||||
$openedConnections.includes(data._id) && {
|
$openedConnections.includes(data._id) &&
|
||||||
|
driver?.supportedCreateDatabase &&
|
||||||
|
!data.isReadOnly && {
|
||||||
text: 'Create database',
|
text: 'Create database',
|
||||||
onClick: handleCreateDatabase,
|
onClick: handleCreateDatabase,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -158,6 +158,21 @@
|
|||||||
openJsonDocument(db, name);
|
openJsonDocument(db, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGenerateScript = async () => {
|
||||||
|
const data = await apiCall('database-connections/export-keys', {
|
||||||
|
conid: connection?._id,
|
||||||
|
database: name,
|
||||||
|
options: {
|
||||||
|
keyPrefix: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
newQuery({
|
||||||
|
title: 'Export #',
|
||||||
|
initialData: data,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
async function handleConfirmSql(sql) {
|
async function handleConfirmSql(sql) {
|
||||||
const resp = await apiCall('database-connections/run-script', { conid: connection._id, database: name, sql });
|
const resp = await apiCall('database-connections/run-script', { conid: connection._id, database: name, sql });
|
||||||
const { errorMessage } = resp || {};
|
const { errorMessage } = resp || {};
|
||||||
@@ -172,17 +187,21 @@
|
|||||||
|
|
||||||
const commands = _.flatten((apps || []).map(x => x.commands || []));
|
const commands = _.flatten((apps || []).map(x => x.commands || []));
|
||||||
|
|
||||||
|
const isSqlOrDoc =
|
||||||
|
driver?.databaseEngineTypes?.includes('sql') || driver?.databaseEngineTypes?.includes('document');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleNewTable, text: 'New table' },
|
||||||
driver?.databaseEngineTypes?.includes('document') && { onClick: handleNewCollection, text: 'New collection' },
|
driver?.databaseEngineTypes?.includes('document') && { onClick: handleNewCollection, text: 'New collection' },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
!connection.isReadOnly && { onClick: handleImport, text: 'Import' },
|
isSqlOrDoc && !connection.isReadOnly && { onClick: handleImport, text: 'Import' },
|
||||||
{ onClick: handleExport, text: 'Export' },
|
isSqlOrDoc && { onClick: handleExport, text: 'Export' },
|
||||||
{ onClick: handleShowDiagram, text: 'Show diagram' },
|
isSqlOrDoc && { onClick: handleShowDiagram, text: 'Show diagram' },
|
||||||
{ onClick: handleSqlGenerator, text: 'SQL Generator' },
|
isSqlOrDoc && { onClick: handleSqlGenerator, text: 'SQL Generator' },
|
||||||
{ onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
isSqlOrDoc && { onClick: handleOpenJsonModel, text: 'Open model as JSON' },
|
||||||
{ onClick: handleExportModel, text: 'Export DB model - experimental' },
|
isSqlOrDoc && { onClick: handleExportModel, text: 'Export DB model - experimental' },
|
||||||
|
isSqlOrDoc &&
|
||||||
_.get($currentDatabase, 'connection._id') &&
|
_.get($currentDatabase, 'connection._id') &&
|
||||||
(_.get($currentDatabase, 'connection._id') != _.get(connection, '_id') ||
|
(_.get($currentDatabase, 'connection._id') != _.get(connection, '_id') ||
|
||||||
(_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
(_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
||||||
@@ -191,6 +210,8 @@
|
|||||||
text: `Compare with ${_.get($currentDatabase, 'name')}`,
|
text: `Compare with ${_.get($currentDatabase, 'name')}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
driver?.databaseEngineTypes?.includes('keyvalue') && { onClick: handleGenerateScript, text: 'Generate script' },
|
||||||
|
|
||||||
_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
||||||
_.get($currentDatabase, 'name') == name && { onClick: handleDisconnect, text: 'Disconnect' },
|
_.get($currentDatabase, 'name') == name && { onClick: handleDisconnect, text: 'Disconnect' },
|
||||||
|
|
||||||
@@ -240,6 +261,7 @@
|
|||||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
||||||
import { filterAppsForDatabase } from '../utility/appTools';
|
import { filterAppsForDatabase } from '../utility/appTools';
|
||||||
|
import newQuery from '../query/newQuery';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
export let passProps;
|
export let passProps;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const driver = {
|
|||||||
defaultPort: 6379,
|
defaultPort: 6379,
|
||||||
editorMode: 'text',
|
editorMode: 'text',
|
||||||
databaseEngineTypes: ['keyvalue'],
|
databaseEngineTypes: ['keyvalue'],
|
||||||
|
supportedCreateDatabase: false,
|
||||||
getQuerySplitterOptions: () => redisSplitterOptions,
|
getQuerySplitterOptions: () => redisSplitterOptions,
|
||||||
supportedKeyTypes: [
|
supportedKeyTypes: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user