mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Drop indexes
This commit is contained in:
parent
f51abb45cd
commit
6469cdb630
@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import CodeViewer from '../../../components/codeviewer.svelte';
|
import CodeViewer from '../../../components/codeviewer.svelte';
|
||||||
import ObjectGrid from '../../../components/objectgrid.svelte';
|
import ObjectGrid from '../../../components/objectgrid.svelte';
|
||||||
import { GetIndexes } from '../../../../wailsjs/go/app/App';
|
import { DropIndex, GetIndexes } from '../../../../wailsjs/go/app/App';
|
||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
|
|
||||||
@ -16,8 +16,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openJson(itemId) {
|
async function dropActive() {
|
||||||
const item = indexes?.filter(i => i.name == itemId);
|
if (!activeKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const success = await DropIndex(collection.hostKey, collection.dbKey, collection.key, activeKey);
|
||||||
|
if (success) {
|
||||||
|
await getIndexes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openJson(indexId) {
|
||||||
|
const item = indexes?.filter(i => i.name == indexId);
|
||||||
json = JSON.stringify(item, undefined, 2);
|
json = JSON.stringify(item, undefined, 2);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -25,7 +35,9 @@
|
|||||||
<div class="indexes">
|
<div class="indexes">
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button class="btn" on:click={getIndexes}>Get indexes</button>
|
<button class="btn" on:click={getIndexes}>Get indexes</button>
|
||||||
<button class="btn danger" disabled={!indexes?.length || !activeKey}>Drop selected</button>
|
<button class="btn danger" on:click={dropActive} disabled={!indexes?.length || !activeKey}>
|
||||||
|
Drop selected
|
||||||
|
</button>
|
||||||
<button class="btn">Create…</button>
|
<button class="btn">Create…</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
2
frontend/wailsjs/go/app/App.d.ts
vendored
2
frontend/wailsjs/go/app/App.d.ts
vendored
@ -8,6 +8,8 @@ export function DropCollection(arg1:string,arg2:string,arg3:string):Promise<bool
|
|||||||
|
|
||||||
export function DropDatabase(arg1:string,arg2:string):Promise<boolean>;
|
export function DropDatabase(arg1:string,arg2:string):Promise<boolean>;
|
||||||
|
|
||||||
|
export function DropIndex(arg1:string,arg2:string,arg3:string,arg4:string):Promise<boolean>;
|
||||||
|
|
||||||
export function FindItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<app.findResult>;
|
export function FindItems(arg1:string,arg2:string,arg3:string,arg4:string):Promise<app.findResult>;
|
||||||
|
|
||||||
export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise<Array<primitive.M>>;
|
export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise<Array<primitive.M>>;
|
||||||
|
@ -10,6 +10,10 @@ export function DropDatabase(arg1, arg2) {
|
|||||||
return window['go']['app']['App']['DropDatabase'](arg1, arg2);
|
return window['go']['app']['App']['DropDatabase'](arg1, arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function DropIndex(arg1, arg2, arg3, arg4) {
|
||||||
|
return window['go']['app']['App']['DropIndex'](arg1, arg2, arg3, arg4);
|
||||||
|
}
|
||||||
|
|
||||||
export function FindItems(arg1, arg2, arg3, arg4) {
|
export function FindItems(arg1, arg2, arg3, arg4) {
|
||||||
return window['go']['app']['App']['FindItems'](arg1, arg2, arg3, arg4);
|
return window['go']['app']['App']['FindItems'](arg1, arg2, arg3, arg4);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
||||||
@ -40,3 +41,25 @@ func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M {
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) DropIndex(hostKey, dbKey, collKey, indexName string) bool {
|
||||||
|
client, ctx, close, err := a.connectToHost(hostKey)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
_, err = client.Database(dbKey).Collection(collKey).Indexes().DropOne(ctx, indexName, &options.DropIndexesOptions{})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||||
|
Type: runtime.ErrorDialog,
|
||||||
|
Title: "Encountered an error while creating index cursor",
|
||||||
|
Message: err.Error(),
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user