mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 19:33:59 +00:00
create, drop collection from menu
This commit is contained in:
@@ -38,6 +38,24 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleNewCollection = () => {
|
||||||
|
showModal(InputTextModal, {
|
||||||
|
value: '',
|
||||||
|
label: 'New collection name',
|
||||||
|
header: 'Create collection',
|
||||||
|
onConfirm: async newCollection => {
|
||||||
|
const dbid = { conid: connection._id, database: name };
|
||||||
|
await axiosInstance.request({
|
||||||
|
url: 'database-connections/run-script',
|
||||||
|
method: 'post',
|
||||||
|
params: dbid,
|
||||||
|
data: { sql: `db.createCollection('${newCollection}')` },
|
||||||
|
});
|
||||||
|
axiosInstance.post('database-connections/sync-model', dbid);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleImport = () => {
|
const handleImport = () => {
|
||||||
showModal(ImportExportModal, {
|
showModal(ImportExportModal, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@@ -102,9 +120,12 @@
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const driver = findEngineDriver(connection, getExtensions());
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
{ onClick: handleNewQuery, text: 'New query', isNewQuery: true },
|
||||||
{ onClick: handleNewTable, text: 'New table' },
|
!driver?.dialect?.nosql && { onClick: handleNewTable, text: 'New table' },
|
||||||
|
driver?.dialect?.nosql && { onClick: handleNewCollection, text: 'New collection' },
|
||||||
{ divider: true },
|
{ divider: true },
|
||||||
{ onClick: handleImport, text: 'Import' },
|
{ onClick: handleImport, text: 'Import' },
|
||||||
{ onClick: handleExport, text: 'Export' },
|
{ onClick: handleExport, text: 'Export' },
|
||||||
@@ -132,12 +153,14 @@
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||||
import { currentArchive, currentDatabase, extensions, selectedWidget } from '../stores';
|
import { currentArchive, currentDatabase, extensions, getExtensions, selectedWidget } from '../stores';
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import getElectron from '../utility/getElectron';
|
import getElectron from '../utility/getElectron';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
|
import InputTextModal from '../modals/InputTextModal.svelte';
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
|
|||||||
@@ -308,6 +308,10 @@
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Drop collection',
|
||||||
|
isDropCollection: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
},
|
},
|
||||||
@@ -396,6 +400,7 @@
|
|||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';
|
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';
|
||||||
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -538,6 +543,20 @@
|
|||||||
);
|
);
|
||||||
obj.pureName = newName;
|
obj.pureName = newName;
|
||||||
});
|
});
|
||||||
|
} else if (menu.isDropCollection) {
|
||||||
|
showModal(ConfirmModal, {
|
||||||
|
message: `Really drop collection ${data.pureName}?`,
|
||||||
|
onConfirm: async () => {
|
||||||
|
const dbid = _.pick(data, ['conid', 'database']);
|
||||||
|
await axiosInstance.request({
|
||||||
|
url: 'database-connections/run-script',
|
||||||
|
method: 'post',
|
||||||
|
params: dbid,
|
||||||
|
data: { sql: `db.dropCollection('${data.pureName}')` },
|
||||||
|
});
|
||||||
|
axiosInstance.post('database-connections/sync-model', dbid);
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openDatabaseObjectDetail(
|
openDatabaseObjectDetail(
|
||||||
menu.tab,
|
menu.tab,
|
||||||
|
|||||||
@@ -88,6 +88,12 @@ const driver = {
|
|||||||
columns: [],
|
columns: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
async script(pool, sql) {
|
||||||
|
let func;
|
||||||
|
func = eval(`(db,ObjectId) => { ${sql} }`);
|
||||||
|
const db = await getScriptableDb(pool);
|
||||||
|
func(db, ObjectId);
|
||||||
|
},
|
||||||
async stream(pool, sql, options) {
|
async stream(pool, sql, options) {
|
||||||
let func;
|
let func;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user