display data keys, data item length
This commit is contained in:
parent
35f28fa5ed
commit
5270dd00bc
41
main.go
41
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
@ -197,6 +198,46 @@ func Bolt_ListBuckets(b ObjectReference, browse []string) ObjectReference {
|
|||||||
return pNC_Ref
|
return pNC_Ref
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export Bolt_ListItems
|
||||||
|
func Bolt_ListItems(b ObjectReference, browse []string) ObjectReference {
|
||||||
|
|
||||||
|
pNC := &NextCall{
|
||||||
|
content: make(chan CallResponse, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
pNC_Ref := gms.Put(pNC)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(browse) == 0 {
|
||||||
|
err = errors.New("No bucket specified")
|
||||||
|
} else {
|
||||||
|
// Nested-mode
|
||||||
|
err = withBrowse_ReadOnly(b, browse, func(db *bolt.DB, tx *bolt.Tx, bucket *bolt.Bucket) error {
|
||||||
|
return bucket.ForEach(func(k, v []byte) error {
|
||||||
|
if v == nil {
|
||||||
|
return nil // nil v means it's a bucket, skip
|
||||||
|
}
|
||||||
|
|
||||||
|
itemLength := make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(itemLength, uint64(len(v)))
|
||||||
|
pNC.content <- CallResponse{s: string(itemLength) + string(k)}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
pNC.content <- CallResponse{e: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(pNC.content)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return pNC_Ref
|
||||||
|
}
|
||||||
|
|
||||||
//export GetNext
|
//export GetNext
|
||||||
func GetNext(oRef ObjectReference) (int64, *C.char, int) {
|
func GetNext(oRef ObjectReference) (int64, *C.char, int) {
|
||||||
pNC_Iface, ok := gms.Get(oRef)
|
pNC_Iface, ok := gms.Get(oRef)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "boltdb.h"
|
#include "boltdb.h"
|
||||||
|
|
||||||
|
#include <QtEndian>
|
||||||
|
|
||||||
BoltDB::BoltDB()
|
BoltDB::BoltDB()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -46,6 +48,17 @@ bool BoltDB::listBuckets(QStringList bucketPath, QString& errorOut, NameReciever
|
|||||||
return pumpNext(listJob, errorOut, cb);
|
return pumpNext(listJob, errorOut, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BoltDB::listKeys(QStringList bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb)
|
||||||
|
{
|
||||||
|
GoSliceManagedWrapper browse(&bucketPath);
|
||||||
|
auto listJob = ::Bolt_ListItems(this->gmsDbRef, browse.slice);
|
||||||
|
return pumpNext(listJob, errorOut, [=](QByteArray b) {
|
||||||
|
// First 8 bytes are little-endian uint64 len
|
||||||
|
int64_t dataLen = qFromLittleEndian<qint64>(b.mid(0, 8));
|
||||||
|
cb(b.mid(8), dataLen);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool BoltDB::pumpNext(GoInt64 jobRef, QString& errorOut, NameReciever cb)
|
bool BoltDB::pumpNext(GoInt64 jobRef, QString& errorOut, NameReciever cb)
|
||||||
{
|
{
|
||||||
errorOut.clear();
|
errorOut.clear();
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
|
|
||||||
bool listBuckets(QStringList bucketPath, QString& errorOut, NameReciever cb);
|
bool listBuckets(QStringList bucketPath, QString& errorOut, NameReciever cb);
|
||||||
|
|
||||||
|
bool listKeys(QStringList bucketPath, QString& errorOut, std::function<void(QByteArray, int64_t)> cb);
|
||||||
|
|
||||||
bool getStatsJSON(std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
bool getStatsJSON(std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
||||||
|
|
||||||
bool getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
bool getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);
|
||||||
|
@ -187,6 +187,10 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Clean up foreign areas
|
||||||
|
ui->bucketPropertiesArea->clear();
|
||||||
|
ui->bucketData->clear();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Selected a bucket
|
// Selected a bucket
|
||||||
|
|
||||||
@ -213,7 +217,22 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Load the data tab
|
// Load the data tab
|
||||||
// TODO
|
ui->bucketData->clear();
|
||||||
|
QString err;
|
||||||
|
bool ok = bdb->listKeys(browse, err, [=](QByteArray name, int64_t dataLen) {
|
||||||
|
auto *itm = new QTreeWidgetItem();
|
||||||
|
itm->setText(0, QString::fromUtf8(name));
|
||||||
|
itm->setText(1, QString("%1").arg(dataLen));
|
||||||
|
ui->bucketData->addTopLevelItem(itm);
|
||||||
|
});
|
||||||
|
if (! ok) {
|
||||||
|
QMessageBox qmb;
|
||||||
|
qmb.setText(tr("Error listing bucket content: %1").arg(err));
|
||||||
|
qmb.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up foreign areas
|
||||||
|
ui->databasePropertiesArea->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,9 @@
|
|||||||
</column>
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStackedWidget" name="stackedWidget">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="databasePage">
|
<widget class="QWidget" name="databasePage">
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
@ -125,7 +128,7 @@
|
|||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTabWidget" name="bucketTabWidget">
|
<widget class="QTabWidget" name="bucketTabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="bucketPropertiesTab">
|
<widget class="QWidget" name="bucketPropertiesTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@ -160,6 +163,46 @@
|
|||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Data</string>
|
<string>Data</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_6">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTreeWidget" name="bucketData">
|
||||||
|
<property name="indentation">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="itemsExpandable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Key</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Data length</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -265,7 +308,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionClear_selection">
|
<action name="actionClear_selection">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Clear selection</string>
|
<string>&Clear selection</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
Reference in New Issue
Block a user