display data keys, data item length

This commit is contained in:
mappu 2017-05-21 16:15:49 +12:00
parent 35f28fa5ed
commit 5270dd00bc
5 changed files with 121 additions and 3 deletions

41
main.go
View File

@ -2,6 +2,7 @@ package main
import "C"
import (
"encoding/binary"
"encoding/json"
"errors"
"os"
@ -197,6 +198,46 @@ func Bolt_ListBuckets(b ObjectReference, browse []string) ObjectReference {
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
func GetNext(oRef ObjectReference) (int64, *C.char, int) {
pNC_Iface, ok := gms.Get(oRef)

View File

@ -1,5 +1,7 @@
#include "boltdb.h"
#include <QtEndian>
BoltDB::BoltDB()
{
@ -46,6 +48,17 @@ bool BoltDB::listBuckets(QStringList bucketPath, QString& errorOut, NameReciever
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)
{
errorOut.clear();

View File

@ -20,6 +20,8 @@ public:
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 getBucketStatsJSON(QStringList bucketPath, std::function<void(QByteArray)> onSuccess, std::function<void(QString)> onError);

View File

@ -187,6 +187,10 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
}
);
// Clean up foreign areas
ui->bucketPropertiesArea->clear();
ui->bucketData->clear();
} else {
// Selected a bucket
@ -213,7 +217,22 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
);
// 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();
}
}

View File

@ -53,6 +53,9 @@
</column>
</widget>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="databasePage">
<layout class="QGridLayout" name="gridLayout_4">
<property name="leftMargin">
@ -125,7 +128,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="bucketTabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="bucketPropertiesTab">
<attribute name="title">
@ -160,6 +163,46 @@
<attribute name="title">
<string>Data</string>
</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>
</item>
@ -265,7 +308,7 @@
</action>
<action name="actionClear_selection">
<property name="text">
<string>Clear selection</string>
<string>&amp;Clear selection</string>
</property>
</action>
</widget>