mongo update script preview

This commit is contained in:
Jan Prochazka 2021-04-08 10:02:04 +02:00
parent 1bf9110f4b
commit c7e1e294ef
3 changed files with 17 additions and 9 deletions

View File

@ -32,6 +32,7 @@ export interface ReadCollectionOptions {
skip?: number;
limit?: number;
}
export interface EngineDriver {
engine: string;
title: string;
@ -62,6 +63,7 @@ export interface EngineDriver {
getAuthTypes(): EngineAuthType[];
readCollection(pool: any, options: ReadCollectionOptions): Promise<any>;
updateCollection(pool: any, changeSet: any): Promise<any>;
getCollectionUpdateScript(changeSet: any): string;
analyserClass?: any;
dumperClass?: any;

View File

@ -3,11 +3,12 @@
import FormProvider from '../forms/FormProvider.svelte';
import FormSubmit from '../forms/FormSubmit.svelte';
import JSONTree from '../jsontree/JSONTree.svelte';
import AceEditor from '../query/AceEditor.svelte';
import ModalBase from './ModalBase.svelte';
import { closeCurrentModal } from './modalTools';
export let json;
export let script;
export let onConfirm;
</script>
@ -16,7 +17,7 @@
<div slot="header">Save changes</div>
<div class="editor">
<JSONTree value={json} />
<AceEditor mode="javascript" readOnly value={script} />
</div>
<div slot="footer">
@ -37,6 +38,5 @@
position: relative;
height: 30vh;
width: 40vw;
overflow: scroll;
}
</style>

View File

@ -118,11 +118,17 @@
export function save() {
const json = $changeSetStore?.value;
showModal(ConfirmNoSqlModal, {
json,
onConfirm: () => handleConfirmChange(json),
engine: display.engine,
});
const driver = findEngineDriver($connection, $extensions);
const script = driver.getCollectionUpdateScript ? driver.getCollectionUpdateScript(json) : null;
if (script) {
showModal(ConfirmNoSqlModal, {
script,
onConfirm: () => handleConfirmChange(json),
engine: display.engine,
});
} else {
handleConfirmChange(json);
}
}
export function addJsonDocument() {