mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 17:55:59 +00:00
update mongo data
This commit is contained in:
@@ -99,6 +99,13 @@ module.exports = {
|
|||||||
return res.result;
|
return res.result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateCollection_meta: 'post',
|
||||||
|
async updateCollection({ conid, database, changeSet }) {
|
||||||
|
const opened = await this.ensureOpened(conid, database);
|
||||||
|
const res = await this.sendRequest(opened, { msgtype: 'updateCollection', changeSet });
|
||||||
|
return res.result;
|
||||||
|
},
|
||||||
|
|
||||||
status_meta: 'get',
|
status_meta: 'get',
|
||||||
async status({ conid, database }) {
|
async status({ conid, database }) {
|
||||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
|
|||||||
@@ -105,6 +105,17 @@ async function handleCollectionData({ msgid, options }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleUpdateCollection({ msgid, changeSet }) {
|
||||||
|
await waitConnected();
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
try {
|
||||||
|
const result = await driver.updateCollection(systemConnection, changeSet);
|
||||||
|
process.send({ msgtype: 'response', msgid, result });
|
||||||
|
} catch (err) {
|
||||||
|
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSqlPreview({ msgid, objects, options }) {
|
async function handleSqlPreview({ msgid, objects, options }) {
|
||||||
await waitConnected();
|
await waitConnected();
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
@@ -140,6 +151,7 @@ function handlePing() {
|
|||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
queryData: handleQueryData,
|
queryData: handleQueryData,
|
||||||
|
updateCollection: handleUpdateCollection,
|
||||||
collectionData: handleCollectionData,
|
collectionData: handleCollectionData,
|
||||||
sqlPreview: handleSqlPreview,
|
sqlPreview: handleSqlPreview,
|
||||||
ping: handlePing,
|
ping: handlePing,
|
||||||
|
|||||||
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -61,6 +61,7 @@ export interface EngineDriver {
|
|||||||
createDumper(): SqlDumper;
|
createDumper(): SqlDumper;
|
||||||
getAuthTypes(): EngineAuthType[];
|
getAuthTypes(): EngineAuthType[];
|
||||||
readCollection(pool: any, options: ReadCollectionOptions): Promise<any>;
|
readCollection(pool: any, options: ReadCollectionOptions): Promise<any>;
|
||||||
|
updateCollection(pool: any, changeSet: any): Promise<any>;
|
||||||
|
|
||||||
analyserClass?: any;
|
analyserClass?: any;
|
||||||
dumperClass?: any;
|
dumperClass?: any;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
import { scriptToSql } from 'dbgate-sqltree';
|
import { scriptToSql } from 'dbgate-sqltree';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal.svelte';
|
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
|
||||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
@@ -128,15 +128,15 @@
|
|||||||
// $: console.log('GRIDER', grider);
|
// $: console.log('GRIDER', grider);
|
||||||
// $: if (onChangeGrider) onChangeGrider(grider);
|
// $: if (onChangeGrider) onChangeGrider(grider);
|
||||||
|
|
||||||
async function handleConfirmSql(sql) {
|
async function handleConfirmChange(changeSet) {
|
||||||
const resp = await axiosInstance.request({
|
const resp = await axiosInstance.request({
|
||||||
url: 'database-connections/query-data',
|
url: 'database-connections/update-collection',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: {
|
params: {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
},
|
},
|
||||||
data: { sql },
|
data: { changeSet },
|
||||||
});
|
});
|
||||||
const { errorMessage } = resp.data || {};
|
const { errorMessage } = resp.data || {};
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
@@ -148,11 +148,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleSave() {
|
function handleSave() {
|
||||||
const script = changeSetToSql(changeSetState && changeSetState.value, display.dbinfo);
|
const json = changeSetState && changeSetState.value;
|
||||||
const sql = scriptToSql(display.driver, script);
|
showModal(ConfirmNoSqlModal, {
|
||||||
showModal(ConfirmSqlModal, {
|
json,
|
||||||
sql,
|
onConfirm: () => handleConfirmChange(json),
|
||||||
onConfirm: () => handleConfirmSql(sql),
|
|
||||||
engine: display.engine,
|
engine: display.engine,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
42
packages/web/src/modals/ConfirmNoSqlModal.svelte
Normal file
42
packages/web/src/modals/ConfirmNoSqlModal.svelte
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<script>
|
||||||
|
import FormStyledButton from '../elements/FormStyledButton.svelte';
|
||||||
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
|
import JSONTree from '../jsontree/JSONTree.svelte';
|
||||||
|
|
||||||
|
import ModalBase from './ModalBase.svelte';
|
||||||
|
import { closeCurrentModal } from './modalTools';
|
||||||
|
|
||||||
|
export let json;
|
||||||
|
export let onConfirm;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<FormProvider>
|
||||||
|
<ModalBase {...$$restProps}>
|
||||||
|
<div slot="header">Save changes</div>
|
||||||
|
|
||||||
|
<div class="editor">
|
||||||
|
<JSONTree value={json} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div slot="footer">
|
||||||
|
<FormSubmit
|
||||||
|
value="OK"
|
||||||
|
on:click={() => {
|
||||||
|
closeCurrentModal();
|
||||||
|
onConfirm();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FormStyledButton type="button" value="Close" onClick={closeCurrentModal} />
|
||||||
|
</div>
|
||||||
|
</ModalBase>
|
||||||
|
</FormProvider>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.editor {
|
||||||
|
position: relative;
|
||||||
|
height: 30vh;
|
||||||
|
width: 40vw;
|
||||||
|
overflow: scroll;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user