handler script errors

This commit is contained in:
Jan Prochazka 2022-06-23 14:32:34 +02:00
parent c0b0ca22aa
commit 571c928234
4 changed files with 22 additions and 36 deletions

View File

@ -83,12 +83,7 @@
label: 'New collection name',
header: 'Create collection',
onConfirm: async newCollection => {
const dbid = { conid: connection._id, database: name };
await apiCall('database-connections/run-script', {
...dbid,
sql: `db.createCollection('${newCollection}')`,
});
await apiCall('database-connections/sync-model', dbid);
saveScriptToDatabase({ conid: connection._id, database: name }, `db.createCollection('${newCollection}')`);
},
});
};
@ -224,13 +219,7 @@
};
async function handleConfirmSql(sql) {
const resp = await apiCall('database-connections/run-script', { conid: connection._id, database: name, sql });
const { errorMessage } = resp || {};
if (errorMessage) {
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
} else {
showSnackbarSuccess('Saved to database');
}
saveScriptToDatabase({ conid: connection._id, database: name }, sql, false);
}
const driver = findEngineDriver(connection, getExtensions());
@ -317,14 +306,14 @@
import { openJsonDocument } from '../tabs/JsonTab.svelte';
import { apiCall } from '../utility/api';
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 newQuery from '../query/newQuery';
import { exportSqlDump } from '../utility/exportFileTools';
import ImportDatabaseDumpModal from '../modals/ImportDatabaseDumpModal.svelte';
import ExportDatabaseDumpModal from '../modals/ExportDatabaseDumpModal.svelte';
import ConfirmModal from '../modals/ConfirmModal.svelte';
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
export let data;
export let passProps;

View File

@ -463,12 +463,8 @@
showModal(ConfirmModal, {
message: `Really drop collection ${data.pureName}?`,
onConfirm: async () => {
saveScriptToDatabase(_.pick(data, ['conid', 'database']), `db.dropCollection('${data.pureName}')`);
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) {
@ -515,8 +511,7 @@
showModal(ConfirmSqlModal, {
sql: dmp.s,
onConfirm: async () => {
const resp = await apiCall('database-connections/run-script', { conid, database, sql: dmp.s });
await apiCall('database-connections/sync-model', { conid, database });
saveScriptToDatabase({ conid, database }, dmp.s);
},
engine: driver.engine,
});
@ -700,7 +695,7 @@
import getConnectionLabel from '../utility/getConnectionLabel';
import { exportQuickExportFile } from '../utility/exportFileTools';
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 ConfirmModal from '../modals/ConfirmModal.svelte';
import { apiCall } from '../utility/api';

View File

@ -1,17 +1,17 @@
<script context='module'>
export function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
await apiCall('database-connections/run-script', {
conid,
database,
sql,
<script context="module">
export async function saveScriptToDatabase({ conid, database }, sql, syncModel = true) {
const resp = await apiCall('database-connections/run-script', {
conid,
database,
sql,
});
const { errorMessage } = resp || {};
if (errorMessage) {
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
showModal(ErrorMessageModal, { title: 'Error when executing script', message: errorMessage });
} else {
showSnackbarSuccess('Saved to database');
if (syncModel) apiCall('database-connections/sync-model', { conid, database });
showSnackbarSuccess('Saved to database');
if (syncModel) apiCall('database-connections/sync-model', { conid, database });
}
}
</script>
@ -26,9 +26,12 @@
import FontIcon from '../icons/FontIcon.svelte';
import newQuery from '../query/newQuery';
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 { closeCurrentModal } from './modalTools';
import { closeCurrentModal, showModal } from './modalTools';
export let sql;
export let onConfirm;

View File

@ -4,7 +4,7 @@ import InputTextModal from '../modals/InputTextModal.svelte';
import { showModal } from '../modals/modalTools';
import { getExtensions } from '../stores';
import { getConnectionInfo, getDatabaseInfo } from './metadataLoaders';
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
import ConfirmSqlModal, { saveScriptToDatabase } from '../modals/ConfirmSqlModal.svelte';
import { apiCall } from './api';
export async function alterDatabaseDialog(conid, database, updateFunc) {
@ -21,8 +21,7 @@ export async function alterDatabaseDialog(conid, database, updateFunc) {
sql,
recreates,
onConfirm: async () => {
const resp = await apiCall('database-connections/run-script', { conid, database, sql });
await apiCall('database-connections/sync-model', { conid, database });
saveScriptToDatabase({ conid, database }, sql);
},
engine: driver.engine,
});