mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Truncate collections
This commit is contained in:
parent
c76e5c9503
commit
b35222f86b
@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { busy, connections } from '../../stores';
|
import { busy, connections } from '../../stores';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import { DropCollection, DropDatabase, OpenCollection, OpenConnection, OpenDatabase } from '../../../wailsjs/go/app/App';
|
import { DropCollection, DropDatabase, OpenCollection, OpenConnection, OpenDatabase, TruncateCollection } from '../../../wailsjs/go/app/App';
|
||||||
import Grid from '../../components/grid.svelte';
|
import Grid from '../../components/grid.svelte';
|
||||||
import { WindowSetTitle } from '../../../wailsjs/runtime/runtime';
|
import { WindowSetTitle } from '../../../wailsjs/runtime/runtime';
|
||||||
|
|
||||||
@ -69,6 +69,13 @@
|
|||||||
busy.end();
|
busy.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function truncateCollection(dbKey, collKey) {
|
||||||
|
busy.start();
|
||||||
|
await TruncateCollection(activeHostKey, dbKey, collKey);
|
||||||
|
await reload();
|
||||||
|
busy.end();
|
||||||
|
}
|
||||||
|
|
||||||
async function dropCollection(dbKey, collKey) {
|
async function dropCollection(dbKey, collKey) {
|
||||||
busy.start();
|
busy.start();
|
||||||
await DropCollection(activeHostKey, dbKey, collKey);
|
await DropCollection(activeHostKey, dbKey, collKey);
|
||||||
@ -94,14 +101,15 @@
|
|||||||
name: collKey,
|
name: collKey,
|
||||||
icon: 'list',
|
icon: 'list',
|
||||||
menu: [
|
menu: [
|
||||||
{ label: `Rename ${collKey} collection…`, fn: () => dispatch('renameCollection', collKey) },
|
{ label: 'Rename collection…', fn: () => dispatch('renameCollection', collKey) },
|
||||||
{ label: `Drop ${collKey}…`, fn: () => dropCollection(dbKey, collKey) },
|
{ label: 'Truncate collection…', fn: () => truncateCollection(dbKey, collKey) },
|
||||||
|
{ label: 'Drop collection…', fn: () => dropCollection(dbKey, collKey) },
|
||||||
{ separator: true },
|
{ separator: true },
|
||||||
{ label: 'New collection…', fn: () => dispatch('newCollection') },
|
{ label: 'New collection…', fn: () => dispatch('newCollection') },
|
||||||
],
|
],
|
||||||
})) || [],
|
})) || [],
|
||||||
menu: [
|
menu: [
|
||||||
{ label: `Drop database ${dbKey}…`, fn: () => dropDatabase(dbKey) },
|
{ label: 'Drop database…', fn: () => dropDatabase(dbKey) },
|
||||||
{ separator: true },
|
{ separator: true },
|
||||||
{ label: 'New database…', fn: () => dispatch('newDatabase') },
|
{ label: 'New database…', fn: () => dispatch('newDatabase') },
|
||||||
],
|
],
|
||||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -41,6 +41,8 @@ export function RenameCollection(arg1:string,arg2:string,arg3:string,arg4:string
|
|||||||
|
|
||||||
export function Settings():Promise<app.Settings>;
|
export function Settings():Promise<app.Settings>;
|
||||||
|
|
||||||
|
export function TruncateCollection(arg1:string,arg2:string,arg3:string):Promise<boolean>;
|
||||||
|
|
||||||
export function UpdateHost(arg1:string,arg2:string):Promise<void>;
|
export function UpdateHost(arg1:string,arg2:string):Promise<void>;
|
||||||
|
|
||||||
export function UpdateItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<number>;
|
export function UpdateItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<number>;
|
||||||
|
@ -74,6 +74,10 @@ export function Settings() {
|
|||||||
return window['go']['app']['App']['Settings']();
|
return window['go']['app']['App']['Settings']();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function TruncateCollection(arg1, arg2, arg3) {
|
||||||
|
return window['go']['app']['App']['TruncateCollection'](arg1, arg2, arg3);
|
||||||
|
}
|
||||||
|
|
||||||
export function UpdateHost(arg1, arg2) {
|
export function UpdateHost(arg1, arg2) {
|
||||||
return window['go']['app']['App']['UpdateHost'](arg1, arg2);
|
return window['go']['app']['App']['UpdateHost'](arg1, arg2);
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,39 @@ func (a *App) RenameCollection(hostKey, dbKey, collKey, newCollKey string) bool
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) TruncateCollection(hostKey, dbKey, collKey string) bool {
|
||||||
|
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Title: "Confirm",
|
||||||
|
Message: "Are you sure you want to remove all items from " + collKey + "?",
|
||||||
|
Buttons: []string{"Yes", "No"},
|
||||||
|
DefaultButton: "Yes",
|
||||||
|
CancelButton: "No",
|
||||||
|
})
|
||||||
|
if sure != "Yes" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.Database(dbKey).Collection(collKey).DeleteMany(ctx, bson.D{})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Could not truncate " + collKey,
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
defer close()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
||||||
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
sure, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
Title: "Confirm",
|
Title: "Confirm",
|
||||||
@ -74,6 +107,7 @@ func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.Database(dbKey).Collection(collKey).Drop(ctx)
|
err = client.Database(dbKey).Collection(collKey).Drop(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
@ -84,6 +118,7 @@ func (a *App) DropCollection(hostKey, dbKey, collKey string) bool {
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
defer close()
|
defer close()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user