mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
handler script errors
This commit is contained in:
parent
c0b0ca22aa
commit
571c928234
@ -83,12 +83,7 @@
|
|||||||
label: 'New collection name',
|
label: 'New collection name',
|
||||||
header: 'Create collection',
|
header: 'Create collection',
|
||||||
onConfirm: async newCollection => {
|
onConfirm: async newCollection => {
|
||||||
const dbid = { conid: connection._id, database: name };
|
saveScriptToDatabase({ conid: connection._id, database: name }, `db.createCollection('${newCollection}')`);
|
||||||
await apiCall('database-connections/run-script', {
|
|
||||||
...dbid,
|
|
||||||
sql: `db.createCollection('${newCollection}')`,
|
|
||||||
});
|
|
||||||
await apiCall('database-connections/sync-model', dbid);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -224,13 +219,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function handleConfirmSql(sql) {
|
async function handleConfirmSql(sql) {
|
||||||
const resp = await apiCall('database-connections/run-script', { conid: connection._id, database: name, sql });
|
saveScriptToDatabase({ conid: connection._id, database: name }, sql, false);
|
||||||
const { errorMessage } = resp || {};
|
|
||||||
if (errorMessage) {
|
|
||||||
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
|
|
||||||
} else {
|
|
||||||
showSnackbarSuccess('Saved to database');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const driver = findEngineDriver(connection, getExtensions());
|
const driver = findEngineDriver(connection, getExtensions());
|
||||||
@ -317,14 +306,14 @@
|
|||||||
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal, { saveScriptToDatabase } from '../modals/ConfirmSqlModal.svelte';
|
||||||
import { filterAppsForDatabase } from '../utility/appTools';
|
import { filterAppsForDatabase } from '../utility/appTools';
|
||||||
import newQuery from '../query/newQuery';
|
import newQuery from '../query/newQuery';
|
||||||
import { exportSqlDump } from '../utility/exportFileTools';
|
import { exportSqlDump } from '../utility/exportFileTools';
|
||||||
import ImportDatabaseDumpModal from '../modals/ImportDatabaseDumpModal.svelte';
|
import ImportDatabaseDumpModal from '../modals/ImportDatabaseDumpModal.svelte';
|
||||||
import ExportDatabaseDumpModal from '../modals/ExportDatabaseDumpModal.svelte';
|
import ExportDatabaseDumpModal from '../modals/ExportDatabaseDumpModal.svelte';
|
||||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
|
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
export let passProps;
|
export let passProps;
|
||||||
|
@ -463,12 +463,8 @@
|
|||||||
showModal(ConfirmModal, {
|
showModal(ConfirmModal, {
|
||||||
message: `Really drop collection ${data.pureName}?`,
|
message: `Really drop collection ${data.pureName}?`,
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
|
saveScriptToDatabase(_.pick(data, ['conid', 'database']), `db.dropCollection('${data.pureName}')`);
|
||||||
const dbid = _.pick(data, ['conid', 'database']);
|
const dbid = _.pick(data, ['conid', 'database']);
|
||||||
await apiCall('database-connections/run-script', {
|
|
||||||
...dbid,
|
|
||||||
sql: `db.dropCollection('${data.pureName}')`,
|
|
||||||
});
|
|
||||||
apiCall('database-connections/sync-model', dbid);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (menu.isRenameCollection) {
|
} else if (menu.isRenameCollection) {
|
||||||
@ -515,8 +511,7 @@
|
|||||||
showModal(ConfirmSqlModal, {
|
showModal(ConfirmSqlModal, {
|
||||||
sql: dmp.s,
|
sql: dmp.s,
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const resp = await apiCall('database-connections/run-script', { conid, database, sql: dmp.s });
|
saveScriptToDatabase({ conid, database }, dmp.s);
|
||||||
await apiCall('database-connections/sync-model', { conid, database });
|
|
||||||
},
|
},
|
||||||
engine: driver.engine,
|
engine: driver.engine,
|
||||||
});
|
});
|
||||||
@ -700,7 +695,7 @@
|
|||||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { exportQuickExportFile } from '../utility/exportFileTools';
|
import { exportQuickExportFile } from '../utility/exportFileTools';
|
||||||
import createQuickExportMenu from '../utility/createQuickExportMenu';
|
import createQuickExportMenu from '../utility/createQuickExportMenu';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal, { saveScriptToDatabase } from '../modals/ConfirmSqlModal.svelte';
|
||||||
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';
|
import { alterDatabaseDialog, renameDatabaseObjectDialog } from '../utility/alterDatabaseTools';
|
||||||
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
import ConfirmModal from '../modals/ConfirmModal.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
<script context='module'>
|
<script context="module">
|
||||||
export function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
|
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
|
||||||
await apiCall('database-connections/run-script', {
|
const resp = await apiCall('database-connections/run-script', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql,
|
sql,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { errorMessage } = resp || {};
|
const { errorMessage } = resp || {};
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
|
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
|
||||||
} else {
|
} else {
|
||||||
showSnackbarSuccess('Saved to database');
|
showSnackbarSuccess('Saved to database');
|
||||||
if (syncModel) apiCall('database-connections/sync-model', { conid, database });
|
if (syncModel) apiCall('database-connections/sync-model', { conid, database });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -26,9 +26,12 @@
|
|||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import newQuery from '../query/newQuery';
|
import newQuery from '../query/newQuery';
|
||||||
import SqlEditor from '../query/SqlEditor.svelte';
|
import SqlEditor from '../query/SqlEditor.svelte';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
|
import ErrorMessageModal from './ErrorMessageModal.svelte';
|
||||||
|
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
import { closeCurrentModal } from './modalTools';
|
import { closeCurrentModal, showModal } from './modalTools';
|
||||||
|
|
||||||
export let sql;
|
export let sql;
|
||||||
export let onConfirm;
|
export let onConfirm;
|
||||||
|
@ -4,7 +4,7 @@ import InputTextModal from '../modals/InputTextModal.svelte';
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
import { getExtensions } from '../stores';
|
import { getExtensions } from '../stores';
|
||||||
import { getConnectionInfo, getDatabaseInfo } from './metadataLoaders';
|
import { getConnectionInfo, getDatabaseInfo } from './metadataLoaders';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmSqlModal, { saveScriptToDatabase } from '../modals/ConfirmSqlModal.svelte';
|
||||||
import { apiCall } from './api';
|
import { apiCall } from './api';
|
||||||
|
|
||||||
export async function alterDatabaseDialog(conid, database, updateFunc) {
|
export async function alterDatabaseDialog(conid, database, updateFunc) {
|
||||||
@ -21,8 +21,7 @@ export async function alterDatabaseDialog(conid, database, updateFunc) {
|
|||||||
sql,
|
sql,
|
||||||
recreates,
|
recreates,
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
const resp = await apiCall('database-connections/run-script', { conid, database, sql });
|
saveScriptToDatabase({ conid, database }, sql);
|
||||||
await apiCall('database-connections/sync-model', { conid, database });
|
|
||||||
},
|
},
|
||||||
engine: driver.engine,
|
engine: driver.engine,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user