retrieve database properties

This commit is contained in:
mappu 2017-05-21 11:59:38 +12:00
parent 8597f270f6
commit 95a1bfeea5
6 changed files with 79 additions and 8 deletions

32
main.go
View File

@ -2,12 +2,20 @@ package main
import "C"
import (
"encoding/json"
"errors"
"os"
"github.com/boltdb/bolt"
)
const (
ERROR_AND_STOP_CALLING int64 = 100
ERROR_AND_KEEP_CALLING = 101
FINISHED_OK = 102
REAL_MESSAGE = 103
)
const Magic int64 = 0x10203040
//export GetMagic
@ -73,6 +81,23 @@ type CallResponse struct {
e error
}
//export Bolt_DBStats
func Bolt_DBStats(b ObjectReference) (int64, *C.char, int) {
var stats bolt.Stats
err := withBoltDBReference(b, func(db *bolt.DB) error {
stats = db.Stats()
return nil
})
jBytes, err := json.Marshal(stats)
if err != nil {
return ERROR_AND_STOP_CALLING, C.CString(err.Error()), len(err.Error())
}
return REAL_MESSAGE, C.CString(string(jBytes)), len(jBytes)
}
type NextCall struct {
content chan CallResponse
}
@ -129,13 +154,6 @@ func Bolt_ListBuckets(b ObjectReference, browse []string) ObjectReference {
return pNC_Ref
}
const (
ERROR_AND_STOP_CALLING int64 = 100
ERROR_AND_KEEP_CALLING = 101
FINISHED_OK = 102
REAL_MESSAGE = 103
)
//export GetNext
func GetNext(oRef ObjectReference) (int64, *C.char, int) {
pNC_Iface, ok := gms.Get(oRef)

View File

@ -67,6 +67,15 @@ struct Bolt_Open_return {
extern struct Bolt_Open_return Bolt_Open(GoString p0, GoUint32 p1, GoInt64 p2);
/* Return type for Bolt_DBStats */
struct Bolt_DBStats_return {
GoInt64 r0;
char* r1;
GoInt r2;
};
extern struct Bolt_DBStats_return Bolt_DBStats(GoInt64 p0);
extern GoInt64 Bolt_ListBuckets(GoInt64 p0, GoSlice p1);
/* Return type for GetNext */

View File

@ -62,6 +62,28 @@ bool BoltDB::listBucketsAtRoot(QString& errorOut, NameReciever cb)
return (errorOut.length() == 0);
}
bool BoltDB::getStatsJSON(std::function<void(QString)> onSuccess, std::function<void(QString)> onError)
{
auto statresp = Bolt_DBStats(this->gmsDbRef);
if (statresp.r0 == ERROR_AND_STOP_CALLING) {
QString err = QString::fromUtf8(statresp.r1, statresp.r2);
free(statresp.r1);
onError(err);
return false;
} else if (statresp.r0 == REAL_MESSAGE) {
QString json = QString::fromUtf8(statresp.r1, statresp.r2);
free(statresp.r1);
onSuccess(json);
return true;
} else {
// ?? shouldn't be reachable
return false;
}
}
BoltDB::~BoltDB()
{
auto err = ::Bolt_Close(this->gmsDbRef);

View File

@ -18,6 +18,8 @@ public:
bool listBucketsAtRoot(QString& errorOut, NameReciever cb);
bool getStatsJSON(std::function<void(QString)> onSuccess, std::function<void(QString)> onError);
~BoltDB();
};

View File

@ -157,6 +157,26 @@ void MainWindow::on_bucketTree_currentItemChanged(QTreeWidgetItem *current, QTre
}
ui->tabWidget->setVisible(true);
if (current->parent() == nullptr) {
// Selected a database
auto *bdb = GET_BDB(current);
ui->propertiesArea->clear();
bdb->getStatsJSON([=](QString j) {
ui->propertiesArea->setPlainText(j);
}, [=](QString error) {
QMessageBox qmb;
qmb.setText(tr("Error retrieving database statistics: %1").arg(error));
qmb.exec();
});
} else {
// Selected a bucket
// Load the data tab
// TODO
ui->propertiesArea->clear();
}
// refresh properties for the currently selected tree item...
}

View File

@ -74,7 +74,7 @@
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QPlainTextEdit" name="plainTextEdit">
<widget class="QPlainTextEdit" name="propertiesArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>