diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index aa4357a..a247d20 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -59,7 +59,6 @@ function openJson(itemId) { const item = result?.results?.filter(i => i._id == itemId); - console.log(item); json = JSON.stringify(item, undefined, 2); } diff --git a/frontend/src/organisms/connection/collection/indexes.svelte b/frontend/src/organisms/connection/collection/indexes.svelte index 5573e5c..7968413 100644 --- a/frontend/src/organisms/connection/collection/indexes.svelte +++ b/frontend/src/organisms/connection/collection/indexes.svelte @@ -1,13 +1,43 @@ -
- - - +
+
+ + + +
+ + openJson(e.detail)} />
+ + + + diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index 71e23bb..1fe7b35 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -1,13 +1,15 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -import {map[string]app} from '../models'; import {primitive} from '../models'; +import {map[string]app} from '../models'; import {app} from '../models'; export function DropCollection(arg1:string,arg2:string,arg3:string):Promise; export function DropDatabase(arg1:string,arg2:string):Promise; +export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise>; + export function Hosts():Promise; export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 83ba49d..c2ca10c 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -10,6 +10,10 @@ export function DropDatabase(arg1, arg2) { return window['go']['app']['App']['DropDatabase'](arg1, arg2); } +export function GetIndexes(arg1, arg2, arg3) { + return window['go']['app']['App']['GetIndexes'](arg1, arg2, arg3); +} + export function Hosts() { return window['go']['app']['App']['Hosts'](); } diff --git a/internal/app/collection_indexes.go b/internal/app/collection_indexes.go new file mode 100644 index 0000000..713a321 --- /dev/null +++ b/internal/app/collection_indexes.go @@ -0,0 +1,42 @@ +package app + +import ( + "fmt" + + "github.com/wailsapp/wails/v2/pkg/runtime" + "go.mongodb.org/mongo-driver/bson" +) + +func (a *App) GetIndexes(hostKey, dbKey, collKey string) []bson.M { + client, ctx, close, err := a.connectToHost(hostKey) + if err != nil { + fmt.Println(err.Error()) + return nil + } + defer close() + + cur, err := client.Database(dbKey).Collection(collKey).Indexes().List(ctx) + 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 nil + } + + var results []bson.M + err = cur.All(ctx, &results) + if err != nil { + fmt.Println(err.Error()) + runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Type: runtime.ErrorDialog, + Title: "Encountered an error while executing index cursor", + Message: err.Error(), + }) + return nil + } + + return results +}