1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Started work on indexes

This commit is contained in:
Romein van Buren 2023-01-17 09:44:21 +01:00
parent e85183b6f1
commit f030c9fd3d
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
5 changed files with 85 additions and 8 deletions

View File

@ -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);
}

View File

@ -1,13 +1,43 @@
<script>
import CodeViewer from '../../../components/codeviewer.svelte';
import ObjectGrid from '../../../components/objectgrid.svelte';
import { GetIndexes } from '../../../../wailsjs/go/app/App';
export let collection;
const indexes = [];
let indexes = [];
let activeKey = '';
let json = '';
function getIndexes() {}
async function getIndexes() {
const result = await GetIndexes(collection.hostKey, collection.dbKey, collection.key);
if (result) {
indexes = result;
}
}
function openJson(itemId) {
const item = indexes?.filter(i => i.name == itemId);
json = JSON.stringify(item, undefined, 2);
}
</script>
<div class="buttons">
<button class="btn" on:click={getIndexes}>Get indexes</button>
<button class="btn danger" disabled={!indexes?.length}>Drop selected</button>
<button class="btn">Create&hellip;</button>
<div class="indexes">
<div class="actions">
<button class="btn" on:click={getIndexes}>Get indexes</button>
<button class="btn danger" disabled={!indexes?.length || !activeKey}>Drop selected</button>
<button class="btn">Create&hellip;</button>
</div>
<ObjectGrid key="name" data={indexes} bind:activeKey on:trigger={e => openJson(e.detail)} />
</div>
<CodeViewer bind:code={json} language="json" />
<style>
.indexes {
display: grid;
gap: 0.5rem;
grid-template: auto 1fr / 1fr;
}
</style>

View File

@ -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<boolean>;
export function DropDatabase(arg1:string,arg2:string):Promise<boolean>;
export function GetIndexes(arg1:string,arg2:string,arg3:string):Promise<Array<primitive.M>>;
export function Hosts():Promise<map[string]app.Host>;
export function OpenCollection(arg1:string,arg2:string,arg3:string):Promise<primitive.M>;

View File

@ -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']();
}

View File

@ -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
}