45 Commits

Author SHA1 Message Date
2a9f06588b voiddb: only supported on linux 2026-01-04 11:24:40 +13:00
8ee74e16c2 doc: changelog for v2.1.0 2026-01-04 11:21:03 +13:00
96630dc940 makefile: add test-redis command 2026-01-04 11:05:50 +13:00
85e245658e autoconfig: update v0.5.0 (nicer string editors/labels) 2026-01-04 11:05:42 +13:00
1de694cb88 table/binary: hide extra APPNAME label from autoconfig editor 2026-01-02 19:14:14 +13:00
312898ab3b doc: update README and TODO 2026-01-02 19:14:05 +13:00
19e36ca615 pogreb: initial support + editing + compact 2026-01-02 17:50:18 +13:00
e1403f8e7d doc: update CHANGELOG and TODO 2026-01-02 17:36:02 +13:00
eecdc2b5f2 voiddb: initial support 2026-01-02 17:35:48 +13:00
beff8bc323 config: show multiple connection errors
Not clear why this fixed it
2026-01-02 16:35:49 +13:00
06d939b06e ui: enforce smaller toolbar icon size 2025-12-29 18:24:32 +13:00
addabd85f8 app: add 'set cell to null' button (no-op), separate toolbars into 3 2025-12-29 18:24:26 +13:00
85659885ab doc: update TODO 2025-12-28 19:30:28 +13:00
f34f2f84dc table: show nullable cells as grey 2025-12-28 19:30:23 +13:00
cbc14b261c sqlite: always use extra rowid column as primary key 2025-12-28 19:24:04 +13:00
4f29d531c1 sqlite: use GetCell for preserving typed data through update/insert 2025-12-28 19:21:54 +13:00
b1634e92d4 table: add getCell for dynamic values 2025-12-28 19:21:22 +13:00
4ce9b753e9 sqlite: hide sqlite_sequence and _stat1 tables 2025-12-28 19:04:48 +13:00
1c2567dc3c sqlite: remove builtin LIMIT for now 2025-12-28 19:04:40 +13:00
f2def1371b ui: fix text in context menu when toggling toolbar 2025-12-28 18:44:55 +13:00
4a3e37cdc4 sqliteclidriver: declare all columns are nullable BLOBs 2025-12-28 18:38:22 +13:00
f165853c6b sqlite: always rely on column information from query cursor 2025-12-28 18:28:08 +13:00
93ce3d4a90 ui: non-queryable databases should disable entire tab 2025-12-28 18:27:50 +13:00
88346852b3 ui: when adding new db, always start on properties tab 2025-12-28 18:27:41 +13:00
d15d42c37e sqlite: refactor to use strongly typed column data 2025-12-28 18:02:56 +13:00
76581b9454 table_binary: improve performance by eliding large data values for display 2025-12-28 18:02:28 +13:00
5c9f165aa7 table_binary, _string: show more detailed type errors 2025-12-28 18:02:18 +13:00
a576138428 table_dynamic: use correct format specifier for type information in error 2025-12-28 18:02:00 +13:00
f7f3bfb035 table: add dynamicColumn{}, use for sqlite 2025-12-23 16:46:12 +13:00
53c90bf0dc table: no need for ds_normal, setting delegate to nil is sufficient 2025-12-23 16:45:56 +13:00
2f3c956549 fix execquery being called twice 2025-12-23 15:56:31 +13:00
7c441ecc50 embeddedversions: clickable links to module dependencies 2025-12-23 15:53:24 +13:00
f75a161acd table: remove columnType abstraction 2025-12-23 15:38:02 +13:00
0002c82594 table: reuse delegate, move customization into interface method 2025-12-23 15:28:29 +13:00
13fedfa2f6 doc: update README and TODO 2025-12-22 19:48:36 +13:00
8b06ccef48 buntdb: add support, including editing+shrink 2025-12-22 18:43:48 +13:00
17d6b5172d ui: use compress icon for bolt-zip tool 2025-12-22 18:23:13 +13:00
708e8072ff sqlite: support ssh connections 2025-12-22 18:17:41 +13:00
c8125d2c84 sqliteclidriver: add ssh backend 2025-12-22 18:17:35 +13:00
a5138a51f3 sqliteclidriver: refactor cmd handling to support other implementations 2025-12-22 18:17:29 +13:00
02b5a8fd48 sqliteclidriver: add more comments, expose DriverName const 2025-12-22 18:17:06 +13:00
b2118c9196 config: add omitempty for many db types 2025-12-22 18:16:35 +13:00
5aa76a465c sshtunnel: add icons for connection modes, add omitempty 2025-12-22 18:16:11 +13:00
f3e729b023 assets: add compress, key, page_key icons 2025-12-22 18:15:55 +13:00
5c7a99d16b makefile: autogenerate embed.qrc from asset files 2025-12-22 18:15:49 +13:00
55 changed files with 1632 additions and 471 deletions

View File

@@ -1,5 +1,25 @@
# Changelog
2026-01-04 v2.1.0
- SQLite: Support SSH tunnel
- SQLite: Strict type handling, support nullable columns, always rely on `rowid` as PK
- SQLite: Remove hardcoded LIMIT
- SQLite: Hide internal sqlite_sequence and sqlite_stat1 tables
- BuntDB: Initial support, including editing
- VoidDB: Initial support, including editing and multiple keyspace management
- Pogreb: Initial support, including compaction
- Fix an issue with SQL queries running twice
- Fix an issue with not showing multiple connection errors from the connection manager dialog
- Truncate large binary column display in grid
- UI: Add icons for SSH/Password connection options, for Bolt/Zip conversion tool
- UI: Show 'null' as grey in tables
- UI: Clickable links to Go.mod dependencies in 'Driver versions' data table
- UI: When connecting to a new DB, always start on the Properties tab
- UI: Allow toggling separate toolbar sections in context menu
- UI: Disable Query tab for non-queryable database types
- UI: Fix extra labels appearing when editing large binary columns
2025-12-20 v2.0.0
- Merge yvbolt and QBolt together

View File

@@ -9,6 +9,7 @@ GO_WINRES ?= ~/go/bin/go-winres
.PHONY: generate
generate:
/bin/bash -c '( echo "<RCC>" ; echo " <qresource prefix=\"/\">" ; for f in assets/* ; do echo " <file>$$f</file>" ; done ; echo " </qresource>" ; echo "</RCC>" ) > embed.qrc'
$(MIQT_UIC) -InFile mainwindow.ui -OutFile mainwindow.go -Qt6
$(MIQT_UIC) -InFile connectionDialog.ui -OutFile connectionDialog.go -Qt6
$(MIQT_UIC) -InFile connectionManagerDialog.ui -OutFile connectionManagerDialog.go -Qt6
@@ -65,3 +66,7 @@ clean:
.PHONY: test-mongo
test-mongo:
sudo docker run --rm -p 127.0.0.1:27017:27017 -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=toor mongo:latest
.PHONY: test-redis
test-redis:
sudo docker run --rm -p 127.0.0.1:6379:6379 redis:latest

View File

@@ -18,12 +18,13 @@ A graphical interface for multiple databases.
## Supported databases
There are currently 15 supported databases:
There are currently 18 supported databases:
Database |Read |Editing |Query |Connection options |Context menu actions
-------------|------|---------|------|--------------------|--------
Badger v4 |Yes |Yes |No |Encrypted, readonly, in-memory |Backup, restore, compact
Bitcask |Yes |Yes |No |Readonly, autorecovery |Backup
BuntDB |Yes |Yes |No |In-memory |Shrink
Bolt |Yes |Yes |No |Readonly |Create/delete child buckets, import/export as zip
Debconf |Yes |No |No | |
Freedesktop.org Secret Service |Yes |No | No | |Unlock, create new collection
@@ -32,11 +33,13 @@ LMDB |Yes |Yes |No |Multi-DB, readonly |Create/delete child d
LotusDB |Yes |Yes |No | |
MongoDB |Yes |No |Yes |SSH tunnel |Create/delete child databases and collections
Pebble |Yes |Yes |No |Readonly, in-memory |
Pogreb |Yes |Yes |No | |Compact
Redis |Yes |No |Yes |SSH tunnel, RESP v3 |
RoseDB |Yes |Yes |No | |
SQLite |Yes |Yes |Yes |CLI driver, in-memory |Vacuum, export
SQLite |Yes |Yes |Yes |**SSH tunnel**, CLI driver, in-memory |Vacuum, export
SSH Agent |Yes |No |No |Unix/TCP |Lock, unlock
Starskey |Yes |Yes |No |Compression |
VoidDB |Yes |Yes |No |Multi-keyspace |Create/delete child keyspaces
## License

37
TODO
View File

@@ -1,19 +1,18 @@
- BUG: Connecting to multiple DBs from connection manager: if one has an error, the error popup from the others is lost
- BUG: ExecQuery being called multiple times on error?
- Drag and drop database into UI (QBolt parity)
- Merge with QBolt
- Portable mode (portable.txt or portable/ dir)
- Syntax highlighting in editor
- Autorefresh
- Sshagent
- want to trigger an async refresh from inside the LDB after lock/unlock
- support adding/removing keys (will need per-row actions)
- SSH: knownhost parser is stricter than openssh, does not support hostname if there is known a knownhost for the IP address
- Bolt: import/export should support passworded zips
- Table: BSON view can't see data
- Table: quick filter
- QSortFilterProxyModel
- Cancellation
- Loading animations for connection + queries
- Delay rendering properties/data tab until tab is focused
- Mutation
- Debconf: Support insert/update/delete
- Redis: Support insert/update/delete
@@ -26,6 +25,8 @@
- CLI using psql
- Lungo: Mini embeddable Mongo - https://github.com/256dpi/lungo
- MSSQL (recursive navigation for instances)
- NutsDB https://github.com/nutsdb/nutsdb
- Sniper https://github.com/recoilme/sniper
- Other K/V stores from https://github.com/smallnest/kvbench
- Windows registry
- Allow entering path for quick navigation
@@ -36,7 +37,6 @@
- Chai (built on Pebble) - https://github.com/chaisql/chai
- CloverDB (built on Bolt/Badger) - https://github.com/ostafen/clover
- APCu - need some sort of hook into the storage engine
- VoidDB - https://github.com/voidDB/voidDB
- UnisonDB - https://github.com/ankur-anand/unisondb
- Etcd
- v2: hierarchal
@@ -57,7 +57,6 @@
- Not-quite-DBs
- IRC client
- Docker daemon (images, containers, ...)
- ssh-agent
- ssh known-hosts
- golang.org/x/crypto/ssh/knownhosts - already using this package
- Generic ODBC, database/sql, ...
@@ -67,6 +66,8 @@
- https://github.com/TerraTech/go-tokyocabinet needs pkg-config tokyocabinet
- https://github.com/estraier/tkrzw-go needs pkg-config tkrzw
- cdb (DJB's Constant Database)
- RocksDB
- https://github.com/tecbot/gorocksdb Go bindings, need pkg-config rocksdb
- Rust
- Stoolap https://github.com/stoolap/stoolap
- Rust, needs C binding layer https://github.com/mozilla/cbindgen
@@ -75,8 +76,11 @@
- SQLite CLI driver:
- Context support
- Write support
- Attach to SSH tunnel
- Type handling for columns
- Binary data is losing its \uXXXX escaping and appearing as string
- Unix timestamps are appearing with scientific notation
- Configure binary path
- Error handling: if an error occurs, listing db tables has problems/shows separators
- https://ricardoanderegg.com/posts/sqlite-remote-explorer-gui/
- https://github.com/litements/litexplore
- Badger:
@@ -85,17 +89,29 @@
- SQLite:
- drop table doesn't autorefresh nav since callback is late
- more accurate type handling
- binary data currently shows as "<<binary>>", edits wrongly
- generated columns, hidden columns
- switch to table_xinfo
- https://sqlite.org/gencol.html - probably want to show
- https://sqlite.org/vtab.html#hiddencol hidden columns - probably want to leave hidden (option to show??)
- views
- other special objects (triggers? udf functions?)
- remove current hardcoded LIMIT 1000
- attach additional db to same connection
- set cell null
- other special objects
- triggers? udf functions?
- virtual tables, shadow tables
- toggle showing system tables
- e.g. sqlite_schema a.k.a. sqlite_master not present in default list; sqlite_sequence, is present
- both show in pragma_table_list()
- integrity checks / quick_check
- attach additional db to same connection ("schemas")
- ~~autoincrement: if column is autoincrement and left blank on insert, do not populate in INSERT statement~~ works with implicitly null columns
- LMDB: dupsort mode (duplicate keys / entries-per-key)
- MongoDB
- UI for replica sets, ssl certs, cluster, custom auth database
- SSH tunnel: error `ssh: tcpChan: deadline not supported` - needs workaround
- Backup/restore
- drop db/collection doesn't autorefresh nav since server is asynchronous
- VoidDB:
- drop multidb doesn't autorefresh nav
- SSH tunnel
- option to use external/system SSH
- SSH over Cockpit
@@ -110,3 +126,4 @@
- Export all data from grid
- Export all data from all buckets within a DB
- Reconnect
- Connection manager: clone entry

BIN
assets/compress.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

BIN
assets/key.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

BIN
assets/note_delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

BIN
assets/page_key.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

BIN
assets/vendor_buntdb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

BIN
assets/vendor_pogreb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 B

BIN
assets/vendor_voiddb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

View File

@@ -22,6 +22,7 @@ type ConnectionConfig struct {
Badger *badgerConnection `ylabel:"BadgerDB v4" yicon:":/assets/vendor_dgraph.png" json:",omitempty"`
Bitcask *bitcaskDBConnection `yicon:":/assets/vendor_riak.png" json:",omitempty"`
Bolt *boltConfig `yicon:":/assets/vendor_github.png" json:",omitempty"`
BuntDB *buntDBConnection `ylabel:"BuntDB" yicon:":/assets/vendor_buntdb.png" json:",omitempty"`
Debconf *debconfConnection `yicon:":/assets/vendor_debian.png" json:",omitempty"`
SecretService *secretServiceConnection `ylabel:"Freedesktop.org Secret Service" yicon:":/assets/vendor_freedesktop.png" json:",omitempty"`
LevelDB *leveldbConnection `ylabel:"LevelDB" yicon:":/assets/vendor_leveldb.png" json:",omitempty"`
@@ -29,11 +30,13 @@ type ConnectionConfig struct {
LotusDB *lotusDBConnection `ylabel:"LotusDB" yicon:":/assets/vendor_lotus.png" json:",omitempty"`
MongoDB *mongoConnection `ylabel:"MongoDB" yicon:":/assets/vendor_mongodb.png" json:",omitempty"`
Pebble *pebbleConnection `yicon:":/assets/vendor_cockroach.png" json:",omitempty"`
Pogreb *pogrebConn `yicon:":/assets/vendor_pogreb.png" json:",omitempty"`
Redis *redisConnectionOptions `yicon:":/assets/vendor_redis.png" json:",omitempty"`
RoseDB *roseDBConn `ylabel:"RoseDB" yicon:":/assets/vendor_rosedb.png" json:",omitempty"`
SQLite *sqliteConnection `ylabel:"SQLite" yicon:":/assets/vendor_sqlite.png" json:",omitempty"`
SSHAgent *sshAgentConn `yicon:":/assets/vendor_ssh.png" json:",omitempty"`
Starskey *starskeyConnection `yicon:":/assets/vendor_starskey.png" json:",omitempty"`
VoidDB *voidDBConn `ylabel:"VoidDB" yicon:":/assets/vendor_voiddb.png" json:",omitempty"`
}
func NewConnectionConfig() *ConnectionConfig {
@@ -278,7 +281,8 @@ func (f *App) OnMnuConnectionManagerClick() {
itms := dlg.treeWidget.SelectedItems()
var ok bool = true
for _, itm := range itms {
ok = ok && connectToItem(itm) // connect to selected
itmConnectOK := connectToItem(itm) // connect to selected
ok = ok && itmConnectOK
}
if ok {

View File

@@ -31,7 +31,7 @@ func (ld *badgerLoadedDatabase) RenderForNav(f *tableState, bucketPath []string)
// Load data
// Badger always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
err := ld.db.View(func(txn *badger.Txn) error {
@@ -143,8 +143,8 @@ type badgerConnection struct {
Directory autoconfig.ExistingDirectory
Readonly bool
Encryption *encryptionKey
}
Memory *struct{}
} `json:",omitempty"`
Memory *struct{} `json:",omitempty"`
}
type encryptionKey struct {

View File

@@ -30,7 +30,7 @@ func (ld *bitcaskLdb) Properties(bucketPath []string) (string, error) {
func (ld *bitcaskLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
cur := ld.db.Iterator()
defer cur.Close()

View File

@@ -75,7 +75,7 @@ func (ld *boltLoadedDatabase) RenderForNav(f *tableState, bucketPath []string) e
// Load data
// Bolt always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
err := ld.db.View(func(tx *bbolt.Tx) error {
b := boltTargetBucket(tx, bucketPath)

118
db_bunt.go Normal file
View File

@@ -0,0 +1,118 @@
package main
import (
"context"
"fmt"
"path/filepath"
"strings"
"github.com/mappu/autoconfig"
qt "github.com/mappu/miqt/qt6"
"github.com/tidwall/buntdb"
)
type buntLdb struct {
db *buntdb.DB
}
func (ld *buntLdb) DriverName() string {
return "BuntDB"
}
func (ld *buntLdb) Properties(bucketPath []string) (string, error) {
idxInfo, err := ld.db.Indexes()
if err != nil {
return "", err
}
return fmt.Sprintf("Indexes (%d):\n%s", len(idxInfo), "-"+strings.Join(idxInfo, "\n- ")+"\n"), nil
}
func (ld *buntLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
// Interestingly, BuntDB internally uses string data, not []byte data
// That would stop us from using kvstore_ApplyChanges that only works with
// []byte data, so, fake []byte casts ourselves
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
err := ld.db.View(func(tx *buntdb.Tx) error {
return tx.Ascend("", func(k, v string) bool {
f.AddRow_PK_Data([]byte(k), []byte(k), []byte(v))
return true
})
})
if err != nil {
return err
}
// Valid
f.Ready()
return nil
}
func (n *buntLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return n.db.Update(func(tx *buntdb.Tx) error {
return kvstore_ApplyChanges(
f,
func(k, v []byte) error {
_, _, err := tx.Set(string(k), string(v), nil)
return err
},
func(k []byte) error {
_, err := tx.Delete(string(k))
return err
},
)
})
}
func (ld *buntLdb) doShrink(sender *qt.QTreeWidgetItem, bucketPath []string) error {
return ld.db.Shrink()
}
func (ld *buntLdb) NavChildren(bucketPath []string) ([]string, error) {
return []string{}, nil // No children
}
func (ld *buntLdb) NavContext(bucketPath []string) ([]contextAction, error) {
return []contextAction{
{"Shrink", ld.doShrink},
}, nil
}
func (ld *buntLdb) Close() {
_ = ld.db.Close()
}
var _ loadedDatabase = &buntLdb{} // interface assertion
var _ editableLoadedDatabase = &buntLdb{} // interface assertion
//
type buntDBConnection struct {
Type autoconfig.OneOf
Disk *struct {
File autoconfig.ExistingFile
} `json:",omitempty"`
Memory *struct{} `json:",omitempty"`
}
func (ldc *buntDBConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var path string
if ldc.Disk != nil {
path = string(ldc.Disk.File)
} else {
path = `:memory:` // Special string known by driver
}
db, err := buntdb.Open(path)
if err != nil {
return nil, "", err
}
return &buntLdb{db: db}, filepath.Base(path), nil
}

View File

@@ -44,7 +44,11 @@ func (ld *debconfLoadedDatabase) RenderForNav(f *tableState, bucketPath []string
indexes := make(map[string]int)
f.SetupColumns(slice_repeat(columnType_inlineText, len(ld.db.AllColumnNames)), ld.db.AllColumnNames)
cols := make([]TableColumn, 0, len(ld.db.AllColumnNames))
for i := 0; i < len(ld.db.AllColumnNames); i++ {
cols = append(cols, &stringColumn{})
}
f.SetupColumns(cols, ld.db.AllColumnNames)
for i, cname := range ld.db.AllColumnNames {
indexes[cname] = i

View File

@@ -24,7 +24,7 @@ func (ld *evLdb) Properties(bucketPath []string) (string, error) {
func (ld *evLdb) RenderForNav(f *tableState, bucketPath []string) error {
f.SetupColumns([]columnType{columnType_inlineText, columnType_inlineText, columnType_inlineText}, []string{"Library", "Version", "Hash"})
f.SetupColumns([]TableColumn{&goModuleColumn{}, &stringColumn{}, &stringColumn{}}, []string{"Library", "Version", "Hash"})
for _, dep := range ld.mods.Deps {
f.AddRowData(dep.Path, dep.Version, dep.Sum)

View File

@@ -34,7 +34,7 @@ func (ld *leveldbLoadedDatabase) RenderForNav(f *tableState, bucketPath []string
// Load data
// leveldb always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
itn := ld.db.NewIterator(nil, nil)
defer itn.Release()

View File

@@ -41,7 +41,7 @@ func (ld *lmdbDatabase) RenderForNav(f *tableState, bucketPath []string) error {
// LMDB always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
err := ld.db.View(func(txn *lmdb.Txn) error {
var dbi lmdb.DBI
@@ -238,10 +238,10 @@ var _ editableLoadedDatabase = &lmdbDatabase{} // interface assertion
type lmdbConnection struct {
Storage struct {
Type autoconfig.OneOf
Directory *autoconfig.ExistingDirectory
Directory *autoconfig.ExistingDirectory `json:",omitempty"`
File *struct {
Path autoconfig.ExistingFile `yfilter:"LMDB database (*.mdb);;All files (*)"`
}
} `json:",omitempty"`
}
MultiDB *struct {
Slots int

View File

@@ -24,7 +24,7 @@ func (ld *lotusLdb) Properties(bucketPath []string) (string, error) {
func (ld *lotusLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
cur, err := ld.db.NewIterator(lotusdb.IteratorOptions{})
if err != nil {

View File

@@ -82,7 +82,7 @@ func (ld *mongoLdb) RenderForNav(f *tableState, bucketPath []string) error {
} else if len(bucketPath) == 2 {
f.SetupColumns([]columnType{columnType_inlineText, columnType_bsonDoc}, []string{"_id", "Document"})
f.SetupColumns([]TableColumn{&stringColumn{}, &bsonColumn{}}, []string{"_id", "Document"})
db := ld.client.Database(bucketPath[0])
coll := db.Collection(bucketPath[1])
@@ -239,7 +239,7 @@ func (ld *mongoLdb) ExecQuery(query string, bucketPath []string, resultArea *tab
return fmt.Errorf("Decoding response: %w", err)
}
resultArea.SetupColumns([]columnType{columnType_popupData}, []string{"Response"})
resultArea.SetupColumns([]TableColumn{&binColumn{}}, []string{"Response"})
resultArea.AddRowData(responseJson)
resultArea.Ready()
return nil
@@ -287,7 +287,7 @@ type mongoConnection struct {
Conn struct {
Mode autoconfig.OneOf
Connection_String *string
Connection_String *string `json:",omitempty"`
}
SSH_Tunnel *SSHTunnel

View File

@@ -30,7 +30,7 @@ func (ld *pebbleLoadedDatabase) RenderForNav(f *tableState, bucketPath []string)
// Load data
// pebble always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
itr, err := ld.db.NewIterWithContext(ctx, nil)
if err != nil {
@@ -91,8 +91,8 @@ type pebbleConnection struct {
Disk *struct {
Directory autoconfig.ExistingDirectory
Readonly bool
}
Memory *struct{}
} `json:",omitempty"`
Memory *struct{} `json:",omitempty"`
}
func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {

95
db_pogreb.go Normal file
View File

@@ -0,0 +1,95 @@
package main
import (
"context"
"errors"
"fmt"
"path/filepath"
"github.com/akrylysov/pogreb"
"github.com/mappu/autoconfig"
qt "github.com/mappu/miqt/qt6"
)
type pogrebLdb struct {
db *pogreb.DB
}
func (ld *pogrebLdb) DriverName() string {
return "Pogreb"
}
func (ld *pogrebLdb) Properties(bucketPath []string) (string, error) {
m := ld.db.Metrics()
return fmt.Sprintf("Metrics: %#v\n", m), nil
}
func (ld *pogrebLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
itn := ld.db.Items()
for {
k, v, err := itn.Next()
if err != nil {
if errors.Is(err, pogreb.ErrIterationDone) {
break
}
return err // Real error
}
f.AddRow_PK_Data(k, k, v)
}
f.Ready()
return nil
}
func (n *pogrebLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return kvstore_ApplyChanges(f, n.db.Put, n.db.Delete)
}
func (ld *pogrebLdb) NavChildren(bucketPath []string) ([]string, error) {
return []string{}, nil // No children
}
func (ld *pogrebLdb) compactDB(sender *qt.QTreeWidgetItem, bucketPath []string) error {
info, err := ld.db.Compact()
if err != nil {
return err
}
qt.QMessageBox_Information(sender.TreeWidget().QWidget, APPNAME,
fmt.Sprintf("Compaction completed successfully.\n\nStatistics: %#v", info))
return nil
}
func (ld *pogrebLdb) NavContext(bucketPath []string) ([]contextAction, error) {
return []contextAction{
{"Compact", ld.compactDB},
}, nil
}
func (ld *pogrebLdb) Close() {
_ = ld.db.Close()
}
var _ loadedDatabase = &pogrebLdb{} // interface assertion
var _ editableLoadedDatabase = &pogrebLdb{} // interface assertion
//
type pogrebConn struct {
Directory autoconfig.ExistingDirectory
}
func (c *pogrebConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
db, err := pogreb.Open(string(c.Directory), nil)
if err != nil {
return nil, "", err
}
return &pogrebLdb{db: db}, filepath.Base(string(c.Directory)), nil
}

View File

@@ -142,7 +142,7 @@ func (ld *redisLoadedDatabase) RenderForNav(f *tableState, bucketPath []string)
// Redis always uses Key string, Type string, Value []byte as the columns
f.SetupColumns(
[]columnType{columnType_popupData, columnType_inlineText, columnType_popupData},
[]TableColumn{&binColumn{}, &stringColumn{}, &binColumn{}},
[]string{"Key", "Type", "Value"},
)
@@ -240,7 +240,7 @@ func (ld *redisLoadedDatabase) ExecQuery(query string, _ []string, resultArea *t
return fmt.Errorf("The redis query returned an error: %w", err)
}
resultArea.SetupColumns([]columnType{columnType_inlineText}, []string{"Result"})
resultArea.SetupColumns([]TableColumn{&stringColumn{}}, []string{"Result"})
// The result is probably a single value or a string slice
switch ret := ret.(type) {

View File

@@ -25,7 +25,7 @@ func (ld *roseLdb) Properties(bucketPath []string) (string, error) {
func (ld *roseLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
ld.db.Ascend(func(k, v []byte) (bool, error) {
f.AddRow_PK_Data(k, k, v)

View File

@@ -37,7 +37,7 @@ func (ld *secretServiceDb) RenderForNav(f *tableState, bucketPath []string) erro
} else if len(bucketPath) == 1 {
f.SetupColumns(
[]columnType{columnType_inlineText, columnType_inlineText, columnType_inlineText, columnType_inlineText, columnType_inlineText, columnType_popupData},
[]TableColumn{&stringColumn{}, &stringColumn{}, &stringColumn{}, &stringColumn{}, &stringColumn{}, &binColumn{}},
[]string{"ID", "Label", "Attributes", "ContentType", "Parameters", "Value"},
)

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"path/filepath"
"reflect"
"strings"
"qbolt/sqliteclidriver"
@@ -55,8 +56,6 @@ func (ld *sqliteLoadedDatabase) Properties(bucketPath []string) (string, error)
func (ld *sqliteLoadedDatabase) RenderForNav(f *tableState, bucketPath []string) error {
ctx := context.TODO()
if len(bucketPath) == 0 {
return nil
@@ -68,36 +67,17 @@ func (ld *sqliteLoadedDatabase) RenderForNav(f *tableState, bucketPath []string)
// Render for specific table
tableName := bucketPath[1]
// Load column details
// Use SELECT form instead of common PRAGMA table_info so we can just get names
// We could possibly get this from the main data select, but this will
// work even when there are 0 results
columnNames, err := ld.sqliteGetColumnNamesForTable(tableName)
if err != nil {
return fmt.Errorf("Failed to load columns for table %q: %w", tableName, err)
}
populateColumns(columnNames, f)
// Find primary key, if any
var primaryKeyIdx int = -1
if primaryKeyColumnName, err := ld.getPrimaryKeyForTable(ctx, ld.db, tableName); err == nil {
if search, ok := slice_find(columnNames, primaryKeyColumnName); ok {
primaryKeyIdx = search
}
}
// Select count(*) so we know to display a warning if there are too many entries
// TODO
// Select * with small limit
datar, err := ld.db.Query(`SELECT * FROM "` + tableName + `" LIMIT 1000`) // WARNING can't prepare this parameter, but it comes from the DB (trusted)
datar, err := ld.db.Query(`SELECT rowid, * FROM [` + tableName + `]`) // WARNING can't prepare this parameter, but it comes from the DB (trusted)
if err != nil {
return fmt.Errorf("Failed to load data for table %q: %w", tableName, err)
}
defer datar.Close()
err = populateRows(datar, f, primaryKeyIdx)
err = populateRows(datar, f, true)
if err != nil {
return err
}
@@ -140,34 +120,108 @@ func (ld *sqliteLoadedDatabase) sqliteGetColumnNamesForTable(tableName string) (
return ret, nil
}
func populateColumns(names []string, dest *tableState) {
// FIXME better column types?
dest.SetupColumns(slice_repeat(columnType_inlineText, len(names)), names)
}
func populateRows(rr *sql.Rows, dest *tableState, pk_index int) error {
func populateRows(rr *sql.Rows, dest *tableState, firstColumnIsExtraRowID bool) error {
numColumns := len(dest.columns)
for rr.Next() {
fields := make([]interface{}, numColumns)
pfields := make([]interface{}, numColumns)
for i := 0; i < numColumns; i += 1 {
pfields[i] = &fields[i]
var pfields []interface{} = nil
cNames, err := rr.Columns()
if err != nil {
return err
}
cTypes, err := rr.ColumnTypes()
if err != nil {
return err
}
if len(cNames) != len(cTypes) {
return errors.New("unexpected column metadata mismatch") // assert
}
numColumns = len(cNames)
rrMakeCtypes := []TableColumn{}
for i := 0; i < len(cTypes); i++ {
if firstColumnIsExtraRowID && i == 0 {
pfields = append(pfields, new(int64))
continue
}
nullable, ok := cTypes[i].Nullable()
if !ok {
return errors.New("can't tell if column is nullable?")
}
// TODO support all SQLite column names/type-affinities
// TODO support nullable variants for all types here
// @ref https://www.sqlite.org/datatype3.html
switch cTypes[i].DatabaseTypeName() {
case "BLOB":
// Binary column
rrMakeCtypes = append(rrMakeCtypes, &binColumn{})
pfields = append(pfields, new([]byte))
case "INTEGER":
if nullable {
rrMakeCtypes = append(rrMakeCtypes, &sqlNullInt64Column{})
pfields = append(pfields, new(sql.NullInt64))
} else {
rrMakeCtypes = append(rrMakeCtypes, &int64Column{})
pfields = append(pfields, new(int64))
}
default:
if nullable {
rrMakeCtypes = append(rrMakeCtypes, &sqlNullStringColumn{})
pfields = append(pfields, new(sql.NullString))
} else {
rrMakeCtypes = append(rrMakeCtypes, &stringColumn{})
pfields = append(pfields, new(string))
}
}
}
// Resetup table
if firstColumnIsExtraRowID {
cNames = cNames[1:]
}
dest.SetupColumns(rrMakeCtypes, cNames)
for rr.Next() {
err := rr.Scan(pfields...)
if err != nil {
return fmt.Errorf("Scan: %w", err)
}
rpos := dest.AddRow()
for i := 0; i < len(fields); i += 1 {
dest.SetCell(rpos, i, formatAny(fields[i])) // FIXME stop doing string conversion here
}
if pk_index >= 0 {
dest.SetRowPrimaryKey(rpos, []byte(formatAny(fields[pk_index]))) // FIXME stop doing string conversion here
if firstColumnIsExtraRowID {
dest.SetRowPrimaryKey(rpos, int64_to_binary8(*(pfields[0].(*int64))))
for i := 1; i < numColumns; i += 1 { // skip first column
interior := reflect.ValueOf(pfields[i]).Elem().Interface()
dest.SetCell(rpos, i-1, interior)
}
} else {
// all columns
for i := 0; i < numColumns; i += 1 {
interior := reflect.ValueOf(pfields[i]).Elem().Interface()
dest.SetCell(rpos, i, interior)
}
}
}
@@ -182,14 +236,7 @@ func (ld *sqliteLoadedDatabase) ExecQuery(query string, _ []string, resultArea *
defer rr.Close()
columns, err := rr.Columns()
if err != nil {
return err
}
populateColumns(columns, resultArea)
err = populateRows(rr, resultArea, -1)
err = populateRows(rr, resultArea, false)
if err != nil {
return err
}
@@ -202,12 +249,6 @@ type RowQueryContexter interface {
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func (n *sqliteLoadedDatabase) getPrimaryKeyForTable(ctx context.Context, tx RowQueryContexter, tableName string) (string, error) {
var primaryColumnName string
err := tx.QueryRowContext(ctx, `SELECT l.name FROM pragma_table_info(?) as l WHERE l.pk = 1;`, tableName).Scan(&primaryColumnName)
return primaryColumnName, err
}
func (n *sqliteLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string) (retErr error) {
if len(bucketPath) != 2 {
@@ -232,33 +273,27 @@ func (n *sqliteLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string)
}
}()
// Query sqlite table metadata to determine which of these is the PRIMARY KEY
primaryColumnName, err := n.getPrimaryKeyForTable(ctx, tx, tableName)
if err != nil {
return fmt.Errorf("Finding primary key for update: %w", err)
}
// SQLite can only LIMIT 1 on update/delete if it was compiled with
// SQLITE_ENABLE_UPDATE_DELETE_LIMIT, which isn't the case for the mattn
// cgo library
// Skip that, and just rely on primary key uniqueness
// Edit
for rowid, editcells := range f.updateRows {
for aRow, editcells := range f.updateRows {
stmt := `UPDATE [` + tableName + `] SET `
params := []interface{}{} // FIXME reinstate types for the driver (although SQLite doesn't mind)
params := []interface{}{}
for ct, cell := range editcells {
if ct > 0 {
stmt += `, `
}
stmt += `[` + f.columnLabels[cell] + `] = ?`
params = append(params, (f.columns[cell].(*stringColumn)).vals[rowid]) // FIXME stop doing string conversion
params = append(params, f.columns[cell].GetCell(aRow))
}
stmt += ` WHERE [` + primaryColumnName + `] = ?`
stmt += ` WHERE [rowid] = ?`
// Update by primary key (stored separately)
pkVal := string(f.primaryKeys[rowid]) // FIXME avoid string marshalling
pkVal := binary8_to_int64(f.primaryKeys[aRow])
params = append(params, pkVal)
_, err = tx.ExecContext(ctx, stmt, params...)
@@ -268,10 +303,10 @@ func (n *sqliteLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string)
}
// Delete by key (affects rowids after re-render)
for rowid, _ := range f.deleteRows {
pkVal := string(f.primaryKeys[rowid]) // FIXME avoid string marshalling
for aRow, _ := range f.deleteRows {
pkVal := binary8_to_int64(f.primaryKeys[aRow])
stmt := `DELETE FROM [` + tableName + `] WHERE [` + primaryColumnName + `] = ?`
stmt := `DELETE FROM [` + tableName + `] WHERE [rowid] = ?`
_, err = tx.ExecContext(ctx, stmt, pkVal)
if err != nil {
@@ -280,16 +315,16 @@ func (n *sqliteLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string)
}
// Insert all new entries
for rowid, _ := range f.insertRows {
for aRow, _ := range f.insertRows {
stmt := `INSERT INTO [` + tableName + `] ([` + strings.Join(f.columnLabels, `], [`) + `]) VALUES (`
params := []interface{}{} // FIXME reinstate types for the driver (although SQLite doesn't mind)
params := []interface{}{}
for colid := 0; colid < len(f.columnLabels); colid++ {
if colid > 0 {
stmt += `, `
}
stmt += "?"
params = append(params, (f.columns[colid].(*stringColumn)).vals[rowid]) // FIXME stop doing string conversion
params = append(params, f.columns[colid].GetCell(aRow))
}
stmt += `)`
@@ -316,7 +351,10 @@ func (ld *sqliteLoadedDatabase) NavChildren(bucketPath []string) ([]string, erro
}
if len(bucketPath) == 1 && bucketPath[0] == sqliteTablesCaption {
rr, err := ld.db.Query(`SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC;`)
// The sequence and stat1 tables are not marked as hidden tables
// They are created automatically when using (A) autoincrement and (B) ???.
rr, err := ld.db.Query(`SELECT name FROM sqlite_master WHERE type='table' AND name != 'sqlite_sequence' AND name != 'sqlite_stat1' ORDER BY name ASC;`)
if err != nil {
return nil, err
}
@@ -406,8 +444,12 @@ type sqliteConnection struct {
Disk *struct {
Database autoconfig.ExistingFile `yfilter:"SQLite database (*.db *.db3 *.sqlite *.sqlite3);;All files (*)"`
CliDriver bool `ylabel:"Use experimental CLI driver"`
}
Memory *struct{}
} `json:",omitempty"`
Memory *struct{} `json:",omitempty"`
SSH *struct {
SSHServer *SSHTunnel
Database string
} `json:",omitempty"`
}
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
@@ -424,12 +466,29 @@ func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string
return &sqliteLoadedDatabase{db: db}, filepath.Base(string(sc.Disk.Database)), nil
} else { // memory
} else if sc.Memory != nil { // memory
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
return nil, "", err
}
return &sqliteLoadedDatabase{db: db}, ":memory:", nil
} else if sc.SSH != nil {
if sc.SSH.SSHServer == nil {
return nil, "", errors.New("Invalid configuration")
}
cl, err := sc.SSH.SSHServer.Open(ctx)
if err != nil {
return nil, "", err
}
db := sqliteclidriver.OpenSSH(cl, sc.SSH.Database)
return &sqliteLoadedDatabase{db: db}, "SSH[" + filepath.Base(string(sc.SSH.Database)) + "]", nil
} else {
return nil, "", errors.New("Invalid configuration")
}
}

View File

@@ -31,7 +31,7 @@ func (ld *sshAgentLdb) RenderForNav(f *tableState, bucketPath []string) error {
return err
}
f.SetupColumns([]columnType{columnType_inlineText, columnType_inlineText, columnType_popupData}, []string{"Comment", "Type", "Public Key"})
f.SetupColumns([]TableColumn{&stringColumn{}, &stringColumn{}, &binColumn{}}, []string{"Comment", "Type", "Public Key"})
for _, key := range keys {
// The publicKey blob is the effective primary-key for DB manipulation
@@ -117,8 +117,8 @@ var _ loadedDatabase = &sshAgentLdb{} // interface assertion
type sshAgentConn struct {
Type autoconfig.OneOf
Unix *autoconfig.ExistingFile
TCP *autoconfig.AddressPort
Unix *autoconfig.ExistingFile `json:",omitempty"`
TCP *autoconfig.AddressPort `json:",omitempty"`
}
func (c *sshAgentConn) Reset() {

View File

@@ -26,7 +26,7 @@ func (ld *starskeyLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
// Starskey always uses Key + Value as the columns
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
// It's possible to create a transaction in Starskey, but you can't enumerate keys
// within the transaction - doesn't really help us

248
db_voiddb_linux.go Normal file
View File

@@ -0,0 +1,248 @@
package main
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"github.com/mappu/autoconfig"
qt "github.com/mappu/miqt/qt6"
"github.com/voidDB/voidDB"
"github.com/voidDB/voidDB/common"
"github.com/voidDB/voidDB/cursor"
)
type voidLdb struct {
db *voidDB.Void
multiKeyspace bool
}
func (ld *voidLdb) DriverName() string {
return "VoidDB"
}
func (ld *voidLdb) Properties(bucketPath []string) (string, error) {
return "", nil
}
// cursor gets a VoidDB cursor for the given transaction and bucketPath.
func (ld *voidLdb) cursor(txn *voidDB.Txn, bucketPath []string) (*cursor.Cursor, error) {
if ld.multiKeyspace {
if len(bucketPath) == 0 {
return nil, errors.New("No data at VoidDB root keyspace when in multi-keyspace mode")
}
return txn.OpenCursor([]byte(bucketPath[0]))
} else {
if len(bucketPath) != 0 {
return nil, errors.New("Invalid navigation")
}
return txn.Cursor, nil // The Txn embeds a new cursor over the default keyspace
}
}
func (ld *voidLdb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
if ld.multiKeyspace && len(bucketPath) == 0 {
// Nothing to see/do in the default keyspace, sorry
// Exit without calling .Ready()
return nil
}
err := ld.db.View(func(tx *voidDB.Txn) error {
cur, err := ld.cursor(tx, bucketPath)
if err != nil {
return err
}
for {
k, v, err := cur.GetNext()
if err != nil {
if errors.Is(err, common.ErrorNotFound) {
break // Reached end
}
return fmt.Errorf("GetNext: %w", err) // Some other real error
}
f.AddRow_PK_Data(k, k, v)
}
return nil
})
if err != nil {
return err
}
f.Ready()
return nil
}
func (n *voidLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return n.db.Update(true, func(tx *voidDB.Txn) error {
cur, err := n.cursor(tx, bucketPath)
if err != nil {
return err
}
return kvstore_ApplyChanges(
f,
cur.Put,
func(k []byte) error {
// To delete keys in VoidDB, first move the cursor to the target
_, err := cur.Get(k)
if err != nil {
return fmt.Errorf("Finding key %q for deletion: %w", formatUtf8(k), err)
}
return cur.Del()
},
)
})
}
func (ld *voidLdb) NavChildren(bucketPath []string) ([]string, error) {
if len(bucketPath) == 0 && ld.multiKeyspace {
// In multi-db mode, the root keyspace is filled with pointers to
// other keyspaces
// Iterate the names
var rootNames []string
err := ld.db.View(func(tx *voidDB.Txn) error {
for {
k, _, err := tx.GetNext()
if err != nil {
if errors.Is(err, common.ErrorNotFound) {
return nil // Reached end
}
return fmt.Errorf("GetNext: %w", err) // Some other real error
}
rootNames = append(rootNames, string(k))
}
})
if err != nil {
return nil, err
}
return rootNames, nil
}
return []string{}, nil // No children
}
// addKeyspace is valid only in multi-keyspace mode.
func (ld *voidLdb) addKeyspace(sender *qt.QTreeWidgetItem, bucketPath []string) error {
if len(bucketPath) != 0 {
return errors.New("Can only add keyspaces at the root")
}
ksName := qt.QInputDialog_GetText(sender.TreeWidget().QWidget, APPNAME, "Enter a name for the new keyspace:")
if ksName == "" {
return nil // cancel
}
return ld.db.Update(true, func(tx *voidDB.Txn) error {
_, err := tx.OpenCursor([]byte(ksName))
return err
})
}
// deleteKeyspace is valid only in multi-keyspace mode. It deletes the target
// keyspace and all its content.
func (ld *voidLdb) deleteKeyspace(sender *qt.QTreeWidgetItem, bucketPath []string) error {
if len(bucketPath) != 1 {
return errors.New("Invalid navigation")
}
if !vcl_confirm_dialog(sender.TreeWidget().QWidget, fmt.Sprintf("Are you sure you want to delete the keyspace %q?", bucketPath[0])) {
return nil // cancelled
}
return ld.db.Update(true, func(tx *voidDB.Txn) error {
// Open the keyspace
cur, err := tx.OpenCursor([]byte(bucketPath[0]))
if err != nil {
return err
}
// Delete all its content
for {
_, _, err := cur.GetNext()
if err != nil {
if errors.Is(err, common.ErrorNotFound) {
break // Done
}
return fmt.Errorf("GetNext: %w", err) // real error
}
err = cur.Del()
if err != nil {
return err
}
}
// Delete the root-level keyspace pointer
// In VoidDB you delete by moving the cursor to the target item first
_, err = tx.Get([]byte(bucketPath[0]))
if err != nil {
return err
}
return tx.Del()
})
}
func (ld *voidLdb) NavContext(bucketPath []string) ([]contextAction, error) {
if ld.multiKeyspace {
if len(bucketPath) == 0 {
return []contextAction{
{"Add keyspace...", ld.addKeyspace},
}, nil
} else {
return []contextAction{
{"Delete keyspace...", ld.deleteKeyspace},
}, nil
}
}
return nil, nil // No supported actions
}
func (ld *voidLdb) Close() {
_ = ld.db.Close()
}
var _ loadedDatabase = &voidLdb{} // interface assertion
var _ editableLoadedDatabase = &voidLdb{} // interface assertion
//
type voidDBConn struct {
Path autoconfig.ExistingFile
MultiKeyspace bool `ylabel:"Use multiple keyspaces"`
}
func (c *voidDBConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
const capacity = 1 << 40 // 1 TiB max size before returning ErrorFull
openFunc := voidDB.OpenVoid
if _, err := os.Stat(string(c.Path)); os.IsNotExist(err) {
openFunc = voidDB.NewVoid
}
db, err := openFunc(string(c.Path), capacity)
if err != nil {
return nil, "", err
}
return &voidLdb{db: db, multiKeyspace: c.MultiKeyspace}, filepath.Base(string(c.Path)), nil
}

19
db_voiddb_other.go Normal file
View File

@@ -0,0 +1,19 @@
//go:build !linux
// +build !linux
package main
import (
"context"
"errors"
"github.com/mappu/autoconfig"
)
type voidDBConn struct {
H1 autoconfig.Header `ylabel:"Not supported on this operating system"`
}
func (ssc *voidDBConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
return nil, "", errors.New("Not supported on this operating system")
}

View File

@@ -1,21 +1,24 @@
<RCC>
<qresource prefix="/">
<file>assets/vendor_qt.png</file>
<file>assets/connect.png</file>
<file>assets/disconnect.png</file>
<file>assets/database_key.png</file>
<file>assets/help.png</file>
<file>assets/add.png</file>
<file>assets/arrow_refresh.png</file>
<file>assets/chart_bar.png</file>
<file>assets/compress.png</file>
<file>assets/connect.png</file>
<file>assets/database.png</file>
<file>assets/database_add.png</file>
<file>assets/database_delete.png</file>
<file>assets/database_key.png</file>
<file>assets/database_lightning.png</file>
<file>assets/database_save.png</file>
<file>assets/delete.png</file>
<file>assets/disconnect.png</file>
<file>assets/help.png</file>
<file>assets/key.png</file>
<file>assets/lightning.png</file>
<file>assets/lightning_go.png</file>
<file>assets/note_delete.png</file>
<file>assets/page_key.png</file>
<file>assets/pencil.png</file>
<file>assets/pencil_add.png</file>
<file>assets/pencil_delete.png</file>
@@ -25,6 +28,7 @@
<file>assets/table_add.png</file>
<file>assets/table_delete.png</file>
<file>assets/table_save.png</file>
<file>assets/vendor_buntdb.png</file>
<file>assets/vendor_cockroach.png</file>
<file>assets/vendor_debian.png</file>
<file>assets/vendor_dgraph.png</file>
@@ -35,11 +39,14 @@
<file>assets/vendor_lotus.png</file>
<file>assets/vendor_mongodb.png</file>
<file>assets/vendor_mysql.png</file>
<file>assets/vendor_pogreb.png</file>
<file>assets/vendor_qt.png</file>
<file>assets/vendor_redis.png</file>
<file>assets/vendor_riak.png</file>
<file>assets/vendor_rosedb.png</file>
<file>assets/vendor_sqlite.png</file>
<file>assets/vendor_ssh.png</file>
<file>assets/vendor_starskey.png</file>
<file>assets/vendor_voiddb.png</file>
</qresource>
</RCC>

BIN
embed.rcc

Binary file not shown.

12
go.mod
View File

@@ -11,7 +11,7 @@ require (
github.com/google/uuid v1.6.0
github.com/ledgerwatch/lmdb-go v1.18.2
github.com/lotusdblabs/lotusdb/v2 v2.1.0
github.com/mappu/autoconfig v0.4.1
github.com/mappu/autoconfig v0.5.0
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf
github.com/mattn/go-sqlite3 v1.14.32
github.com/redis/go-redis/v9 v9.17.2
@@ -30,6 +30,7 @@ require (
al.essio.dev/pkg/shellescape v1.6.0 // indirect
github.com/DataDog/zstd v1.5.7 // indirect
github.com/abcum/lcp v0.0.0-20201209214815-7a3f3840be81 // indirect
github.com/akrylysov/pogreb v0.10.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -71,7 +72,16 @@ require (
github.com/rosedblabs/wal v1.3.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/buntdb v1.3.2 // indirect
github.com/tidwall/gjson v1.14.3 // indirect
github.com/tidwall/grect v0.1.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/rtred v0.1.2 // indirect
github.com/tidwall/tinyqueue v0.1.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/voidDB/voidDB v0.1.18 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.2.0 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect

23
go.sum
View File

@@ -4,6 +4,8 @@ github.com/DataDog/zstd v1.5.7 h1:ybO8RBeh29qrxIhCA9E8gKY6xfONU9T6G6aP9DTKfLE=
github.com/DataDog/zstd v1.5.7/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/abcum/lcp v0.0.0-20201209214815-7a3f3840be81 h1:uHogIJ9bXH75ZYrXnVShHIyywFiUZ7OOabwd9Sfd8rw=
github.com/abcum/lcp v0.0.0-20201209214815-7a3f3840be81/go.mod h1:6ZvnjTZX1LNo1oLpfaJK8h+MXqHxcBFBIwkgsv+xlv0=
github.com/akrylysov/pogreb v0.10.2 h1:e6PxmeyEhWyi2AKOBIJzAEi4HkiC+lKyCocRGlnDi78=
github.com/akrylysov/pogreb v0.10.2/go.mod h1:pNs6QmpQ1UlTJKDezuRWmaqkgUE2TuU0YTWyqJZ7+lI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
@@ -104,6 +106,8 @@ github.com/lotusdblabs/lotusdb/v2 v2.1.0 h1:rCBrwED8Po12FzrxxX4zppxoHb2O+sCtddyW
github.com/lotusdblabs/lotusdb/v2 v2.1.0/go.mod h1:MyOEvqL3Hxm3HiBOYZ4BlZBnqCIcc2QQkF34VBD76fk=
github.com/mappu/autoconfig v0.4.1 h1:ekO7mzN+beFu7VhNfJxNlL/5wkYcP9PAl9VTG4EDxYs=
github.com/mappu/autoconfig v0.4.1/go.mod h1:kca6kaYjqOwkZnY9z5YKo0oI/7Bxe2fMIHhYzXwGHEE=
github.com/mappu/autoconfig v0.5.0 h1:pSune+YObUOZmo8PXhxg41PsmcJJ8mP0L/3juDicUhE=
github.com/mappu/autoconfig v0.5.0/go.mod h1:kca6kaYjqOwkZnY9z5YKo0oI/7Bxe2fMIHhYzXwGHEE=
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf h1:SmBzNUevLUzu1msJ5xzWH/Kot+GtOtoz0u9la42dRU4=
github.com/mappu/miqt v0.12.1-0.20251106063543-466b60e47edf/go.mod h1:xFg7ADaO1QSkmXPsPODoKe/bydJpRG9fgCYyIDl/h1U=
github.com/mattetti/filebuffer v1.0.1 h1:gG7pyfnSIZCxdoKq+cPa8T0hhYtD9NxCdI4D7PTjRLM=
@@ -165,8 +169,27 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/buntdb v1.3.2 h1:qd+IpdEGs0pZci37G4jF51+fSKlkuUTMXuHhXL1AkKg=
github.com/tidwall/buntdb v1.3.2/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg=
github.com/tidwall/grect v0.1.4/go.mod h1:9FBsaYRaR0Tcy4UwefBX/UDcDcDy9V5jUcxHzv2jd5Q=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/voidDB/voidDB v0.1.18 h1:Y2a+2nle/EUZTfM9uuIAAbeRlaxMVejFIE1K4kR8on0=
github.com/voidDB/voidDB v0.1.18/go.mod h1:Yj7wPJtpUHq27xPRsZmyUIlCIYize+VlxK5pHtMRoK0=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.2.0 h1:bYKF2AEwG5rqd1BumT4gAnvwU/M9nBp2pTSxeZw7Wvs=

15
main.go
View File

@@ -43,6 +43,11 @@ func newApp() *App {
// different QStyles
a.ui.propertiesBox.SetStyleSheet("background-color: transparent;")
// These properties are not supported by miqt-uic yet
a.ui.tbConnect.SetIconSize(qt.NewQSize2(16, 16))
a.ui.tbData.SetIconSize(qt.NewQSize2(16, 16))
a.ui.tbQuery.SetIconSize(qt.NewQSize2(16, 16))
//
a.ui.actionConnect.OnTriggered(a.OnMnuConnectClick)
@@ -97,8 +102,6 @@ func newApp() *App {
// a.ui.queryInput.OnTextChanged(a.OnQueryTextChanged) // apply syntax highlighting
a.ui.mnuExecute.OnTriggered(a.OnQueryExecute)
a.ui.queryInput.SetFont(vcl_monospace())
a.resultsTbl = NewTableState(a.ui.queryResult)
@@ -474,6 +477,7 @@ func (f *App) refreshContent(node *qt.QTreeWidgetItem) {
f.ui.actionApply_changes.SetEnabled(false) // will be enabled after add/delete/edit
f.ui.actionDelete_row.SetEnabled(editable)
f.ui.actionAddRow.SetEnabled(editable)
f.ui.actionSet_cell_to_null.SetEnabled(false) // TODO
f.contentTbl.SetAllowEditing(editable)
// Toggle the Query functionality
@@ -482,6 +486,9 @@ func (f *App) refreshContent(node *qt.QTreeWidgetItem) {
f.ui.queryResult.SetEnabled(queryable)
f.ui.mnuExecute.SetEnabled(queryable)
tabindex_Query := f.ui.tabWidget.IndexOf(f.ui.tabQuery)
f.ui.tabWidget.SetTabEnabled(tabindex_Query, queryable) // If we were on the query tab at this time, Qt automatically moves us back 1 tab off it
// We're in charge of common status bar text updates
// Find database displayname
f.ui.MainWindow.StatusBar().ShowMessage(f.DatabaseDisplayName(node) + " | " + ld.DriverName())
@@ -634,6 +641,10 @@ func (f *App) addTopLevelDatabaseConnection(ld loadedDatabase, displayName strin
nav.SetData(0, BucketPathBSliceRole, qt.NewQVariant12(emptyData))
f.ui.Buckets.AddTopLevelItem(nav)
// For a newly added DB, switch us back to the Properties pane
f.ui.tabWidget.SetCurrentIndex(0)
f.ui.Buckets.SetCurrentItem(nav) // Select new element
f.handleNavExpansion(nav, 0) // Load child contents but do not recurse further

View File

@@ -34,7 +34,9 @@ type MainWindowUi struct {
menu_Data *qt.QMenu
menu_Tools *qt.QMenu
statusbar *qt.QStatusBar
toolBar *qt.QToolBar
tbConnect *qt.QToolBar
tbData *qt.QToolBar
tbQuery *qt.QToolBar
actionE_xit *qt.QAction
mnuExecute *qt.QAction
mnuDriverVersions *qt.QAction
@@ -47,6 +49,7 @@ type MainWindowUi struct {
actionApply_changes *qt.QAction
actionConnectionManager *qt.QAction
actionCreate_Bolt_database_from_zip *qt.QAction
actionSet_cell_to_null *qt.QAction
}
// NewMainWindowUi creates all Qt widget classes for MainWindow.
@@ -143,6 +146,17 @@ func NewMainWindowUi() *MainWindowUi {
actionCreate_Bolt_database_from_zip__objectName := qt.NewQAnyStringView3("actionCreate_Bolt_database_from_zip")
ui.actionCreate_Bolt_database_from_zip.SetObjectName(*actionCreate_Bolt_database_from_zip__objectName)
actionCreate_Bolt_database_from_zip__objectName.Delete() // setter copied value
icon10 := qt.NewQIcon()
icon10.AddFile4(":/assets/compress.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.actionCreate_Bolt_database_from_zip.SetIcon(icon10)
ui.actionSet_cell_to_null = qt.NewQAction()
actionSet_cell_to_null__objectName := qt.NewQAnyStringView3("actionSet_cell_to_null")
ui.actionSet_cell_to_null.SetObjectName(*actionSet_cell_to_null__objectName)
actionSet_cell_to_null__objectName.Delete() // setter copied value
icon11 := qt.NewQIcon()
icon11.AddFile4(":/assets/note_delete.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.actionSet_cell_to_null.SetIcon(icon11)
/* miqt-uic: no handler for QAction property 'menuRole' */
ui.centralwidget = qt.NewQWidget(ui.MainWindow.QWidget)
centralwidget__objectName := qt.NewQAnyStringView3("centralwidget")
ui.centralwidget.SetObjectName(*centralwidget__objectName)
@@ -198,9 +212,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.propertiesBox.SetReadOnly(true)
ui.gridLayout_2.AddWidget2(ui.propertiesBox.QWidget, 0, 0)
icon10 := qt.NewQIcon()
icon10.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabProperties, icon10, "")
icon12 := qt.NewQIcon()
icon12.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabProperties, icon12, "")
ui.tabData = qt.NewQWidget(ui.tabWidget.QWidget)
tabData__objectName := qt.NewQAnyStringView3("tabData")
ui.tabData.SetObjectName(*tabData__objectName)
@@ -219,9 +233,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
ui.verticalLayout.AddWidget(ui.contentBox.QWidget)
icon11 := qt.NewQIcon()
icon11.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabData, icon11, "")
icon13 := qt.NewQIcon()
icon13.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabData, icon13, "")
ui.tabQuery = qt.NewQWidget(ui.tabWidget.QWidget)
tabQuery__objectName := qt.NewQAnyStringView3("tabQuery")
ui.tabQuery.SetObjectName(*tabQuery__objectName)
@@ -253,9 +267,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.splitter_2.AddWidget(ui.queryResult.QWidget)
ui.verticalLayout_2.AddWidget(ui.splitter_2.QWidget)
icon12 := qt.NewQIcon()
icon12.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabQuery, icon12, "")
icon14 := qt.NewQIcon()
icon14.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabQuery, icon14, "")
ui.splitter.AddWidget(ui.tabWidget.QWidget)
ui.gridLayout.AddWidget2(ui.splitter.QWidget, 0, 0)
@@ -294,6 +308,7 @@ func NewMainWindowUi() *MainWindowUi {
ui.menu_Data.AddSeparator()
ui.menu_Data.QWidget.AddAction(ui.actionAddRow)
ui.menu_Data.QWidget.AddAction(ui.actionDelete_row)
ui.menu_Data.QWidget.AddAction(ui.actionSet_cell_to_null)
ui.menu_Data.QWidget.AddAction(ui.actionApply_changes)
ui.menu_Tools = qt.NewQMenu(ui.menubar.QWidget)
menu_Tools__objectName := qt.NewQAnyStringView3("menu_Tools")
@@ -311,23 +326,39 @@ func NewMainWindowUi() *MainWindowUi {
ui.statusbar.SetObjectName(*statusbar__objectName)
statusbar__objectName.Delete() // setter copied value
ui.MainWindow.SetStatusBar(ui.statusbar)
ui.toolBar = qt.NewQToolBar(ui.MainWindow.QWidget)
toolBar__objectName := qt.NewQAnyStringView3("toolBar")
ui.toolBar.SetObjectName(*toolBar__objectName)
toolBar__objectName.Delete() // setter copied value
/* miqt-uic: no handler for toolBar property 'iconSize' */
ui.toolBar.SetToolButtonStyle(qt.ToolButtonIconOnly)
ui.MainWindow.AddToolBar(qt.TopToolBarArea, ui.toolBar)
/* miqt-uic: no handler for toolBar attribute 'toolBarBreak' */
ui.toolBar.QWidget.AddAction(ui.actionConnectionManager)
ui.toolBar.QWidget.AddAction(ui.actionConnect)
ui.toolBar.AddSeparator()
ui.toolBar.QWidget.AddAction(ui.actionRefresh)
ui.toolBar.QWidget.AddAction(ui.actionAddRow)
ui.toolBar.QWidget.AddAction(ui.actionDelete_row)
ui.toolBar.QWidget.AddAction(ui.actionApply_changes)
ui.toolBar.AddSeparator()
ui.toolBar.QWidget.AddAction(ui.mnuExecute)
ui.tbConnect = qt.NewQToolBar(ui.MainWindow.QWidget)
tbConnect__objectName := qt.NewQAnyStringView3("tbConnect")
ui.tbConnect.SetObjectName(*tbConnect__objectName)
tbConnect__objectName.Delete() // setter copied value
/* miqt-uic: no handler for tbConnect property 'iconSize' */
ui.tbConnect.SetToolButtonStyle(qt.ToolButtonIconOnly)
ui.tbConnect.SetFloatable(false)
ui.MainWindow.AddToolBar(qt.TopToolBarArea, ui.tbConnect)
/* miqt-uic: no handler for tbConnect attribute 'toolBarBreak' */
ui.tbConnect.QWidget.AddAction(ui.actionConnectionManager)
ui.tbConnect.QWidget.AddAction(ui.actionConnect)
ui.tbData = qt.NewQToolBar(ui.MainWindow.QWidget)
tbData__objectName := qt.NewQAnyStringView3("tbData")
ui.tbData.SetObjectName(*tbData__objectName)
tbData__objectName.Delete() // setter copied value
/* miqt-uic: no handler for tbData property 'iconSize' */
ui.tbData.SetFloatable(false)
ui.MainWindow.AddToolBar(qt.TopToolBarArea, ui.tbData)
/* miqt-uic: no handler for tbData attribute 'toolBarBreak' */
ui.tbData.QWidget.AddAction(ui.actionRefresh)
ui.tbData.QWidget.AddAction(ui.actionAddRow)
ui.tbData.QWidget.AddAction(ui.actionDelete_row)
ui.tbData.QWidget.AddAction(ui.actionSet_cell_to_null)
ui.tbData.QWidget.AddAction(ui.actionApply_changes)
ui.tbQuery = qt.NewQToolBar(ui.MainWindow.QWidget)
tbQuery__objectName := qt.NewQAnyStringView3("tbQuery")
ui.tbQuery.SetObjectName(*tbQuery__objectName)
tbQuery__objectName.Delete() // setter copied value
/* miqt-uic: no handler for tbQuery property 'iconSize' */
ui.tbQuery.SetFloatable(false)
ui.MainWindow.AddToolBar(qt.TopToolBarArea, ui.tbQuery)
/* miqt-uic: no handler for tbQuery attribute 'toolBarBreak' */
ui.tbQuery.QWidget.AddAction(ui.mnuExecute)
ui.Retranslate()
@@ -358,6 +389,7 @@ func (ui *MainWindowUi) Retranslate() {
ui.actionConnectionManager.SetText(qt.QMainWindow_Tr("Connection Manager"))
ui.actionConnectionManager.SetToolTip(qt.QMainWindow_Tr("Connection Manager"))
ui.actionCreate_Bolt_database_from_zip.SetText(qt.QMainWindow_Tr("Create Bolt database from zip"))
ui.actionSet_cell_to_null.SetText(qt.QMainWindow_Tr("Set cell to null"))
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabProperties), qt.QTabWidget_Tr("Properties"))
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabData), qt.QTabWidget_Tr("Data"))
ui.tabWidget.SetTabText(ui.tabWidget.IndexOf(ui.tabQuery), qt.QTabWidget_Tr("Query"))
@@ -366,5 +398,7 @@ func (ui *MainWindowUi) Retranslate() {
ui.menu_Help.SetTitle(qt.QMenuBar_Tr("&Help"))
ui.menu_Data.SetTitle(qt.QMenuBar_Tr("&Data"))
ui.menu_Tools.SetTitle(qt.QMenuBar_Tr("&Tools"))
ui.toolBar.SetWindowTitle(qt.QMainWindow_Tr("toolBar"))
ui.tbConnect.SetWindowTitle(qt.QMainWindow_Tr("Connection Toolbar"))
ui.tbData.SetWindowTitle(qt.QMainWindow_Tr("Data Toolbar"))
ui.tbQuery.SetWindowTitle(qt.QMainWindow_Tr("Query Toolbar"))
}

View File

@@ -177,6 +177,7 @@
<addaction name="separator"/>
<addaction name="actionAddRow"/>
<addaction name="actionDelete_row"/>
<addaction name="actionSet_cell_to_null"/>
<addaction name="actionApply_changes"/>
</widget>
<widget class="QMenu" name="menu_Tools">
@@ -192,9 +193,9 @@
<addaction name="menu_Help"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<widget class="QToolBar" name="tbConnect">
<property name="windowTitle">
<string>toolBar</string>
<string>Connection Toolbar</string>
</property>
<property name="iconSize">
<size>
@@ -205,6 +206,9 @@
<property name="toolButtonStyle">
<enum>Qt::ToolButtonStyle::ToolButtonIconOnly</enum>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
@@ -213,12 +217,51 @@
</attribute>
<addaction name="actionConnectionManager"/>
<addaction name="actionConnect"/>
<addaction name="separator"/>
</widget>
<widget class="QToolBar" name="tbData">
<property name="windowTitle">
<string>Data Toolbar</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionRefresh"/>
<addaction name="actionAddRow"/>
<addaction name="actionDelete_row"/>
<addaction name="actionSet_cell_to_null"/>
<addaction name="actionApply_changes"/>
<addaction name="separator"/>
</widget>
<widget class="QToolBar" name="tbQuery">
<property name="windowTitle">
<string>Query Toolbar</string>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mnuExecute"/>
</widget>
<action name="actionE_xit">
@@ -358,10 +401,26 @@
</property>
</action>
<action name="actionCreate_Bolt_database_from_zip">
<property name="icon">
<iconset resource="embed.qrc">
<normaloff>:/assets/compress.png</normaloff>:/assets/compress.png</iconset>
</property>
<property name="text">
<string>Create Bolt database from zip</string>
</property>
</action>
<action name="actionSet_cell_to_null">
<property name="icon">
<iconset resource="embed.qrc">
<normaloff>:/assets/note_delete.png</normaloff>:/assets/note_delete.png</iconset>
</property>
<property name="text">
<string>Set cell to null</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
</property>
</action>
</widget>
<resources>
<include location="embed.qrc"/>

94
sqliteclidriver/event.go Normal file
View File

@@ -0,0 +1,94 @@
package sqliteclidriver
import (
"io"
"sync"
)
const (
evtypeStdout int = iota
evtypeStderr
evtypeExit
)
type processEvent struct {
evtype int
data []byte
err error
}
func (pe processEvent) Error() string {
if pe.err != nil {
return pe.err.Error()
}
if pe.evtype == evtypeStderr {
return string(pe.data)
}
return "<no error>"
}
func (pe processEvent) Unwrap() error {
return pe.err
}
//
func handleEvents(pw io.WriteCloser, pr, pe io.Reader, waiter func() error) (<-chan processEvent, io.WriteCloser, error) {
chEvents := make(chan processEvent, 0)
var wg sync.WaitGroup
go func() {
defer wg.Done()
processEventWorker(pr, evtypeStdout, chEvents)
}()
go func() {
defer wg.Done()
processEventWorker(pe, evtypeStderr, chEvents)
}()
wg.Add(2)
go func() {
// Only call cmd.Wait() after pipes are closed
wg.Wait()
err := waiter()
chEvents <- processEvent{
evtype: evtypeExit,
err: err,
}
close(chEvents)
}()
return chEvents, pw, nil
}
func processEventWorker(p io.Reader, evtype int, dest chan<- processEvent) {
for {
buf := make([]byte, 1024)
n, err := p.Read(buf)
if n > 0 {
dest <- processEvent{
evtype: evtype,
data: buf[0:n],
}
}
if err != nil {
dest <- processEvent{
evtype: evtype,
err: err,
}
// Assume all errors are permanent
// Ordering can produce either io.EOF, ErrClosedPipe, or PathError{"file already closed"}
return
}
}
}

View File

@@ -3,40 +3,15 @@ package sqliteclidriver
import (
"io"
"os/exec"
"sync"
)
const (
evtypeStdout int = iota
evtypeStderr
evtypeExit
)
type processEvent struct {
evtype int
data []byte
err error
func LocalBinEvents(databasePath string) (<-chan processEvent, io.WriteCloser, error) {
// TODO find a way to strictly separate parameters and paths (`--` is not supported here)
cmd := exec.Command(`/usr/bin/sqlite3`, `-noheader`, `-json`, databasePath)
return execEvents(cmd)
}
func (pe processEvent) Error() string {
if pe.err != nil {
return pe.err.Error()
}
if pe.evtype == evtypeStderr {
return string(pe.data)
}
return "<no error>"
}
func (pe processEvent) Unwrap() error {
return pe.err
}
//
func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
func execEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
pw, err := cmd.StdinPipe()
if err != nil {
@@ -58,58 +33,5 @@ func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
return nil, nil, err
}
chEvents := make(chan processEvent, 0)
var wg sync.WaitGroup
go func() {
defer wg.Done()
processEventWorker(pr, evtypeStdout, chEvents)
}()
go func() {
defer wg.Done()
processEventWorker(pe, evtypeStderr, chEvents)
}()
wg.Add(2)
go func() {
// Only call cmd.Wait() after pipes are closed
wg.Wait()
err = cmd.Wait()
chEvents <- processEvent{
evtype: evtypeExit,
err: err,
}
close(chEvents)
}()
return chEvents, pw, nil
}
func processEventWorker(p io.Reader, evtype int, dest chan<- processEvent) {
for {
buf := make([]byte, 1024)
n, err := p.Read(buf)
if n > 0 {
dest <- processEvent{
evtype: evtype,
data: buf[0:n],
}
}
if err != nil {
dest <- processEvent{
evtype: evtype,
err: err,
}
// Assume all errors are permanent
// Ordering can produce either io.EOF, ErrClosedPipe, or PathError{"file already closed"}
return
}
}
return handleEvents(pw, pr, pe, cmd.Wait)
}

View File

@@ -13,7 +13,7 @@ import (
func TestEventCmd(t *testing.T) {
cmd := exec.Command("/bin/bash", "-c", `echo "hello world"`)
ch, _, err := ExecEvents(cmd)
ch, _, err := execEvents(cmd)
if err != nil {
t.Fatal(err)
}
@@ -36,7 +36,7 @@ func TestEventCmd(t *testing.T) {
func TestEventCmdStdin(t *testing.T) {
cmd := exec.Command("/usr/bin/tr", "a-z", "A-Z")
ch, pw, err := ExecEvents(cmd)
ch, pw, err := execEvents(cmd)
if err != nil {
t.Fatal(err)
}

View File

@@ -0,0 +1,94 @@
package sqliteclidriver
import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"io"
"strconv"
"golang.org/x/crypto/ssh"
)
func SSHEvents(cl *ssh.Client, databasePath string) (<-chan processEvent, io.WriteCloser, error) {
// Client must have already been Dial()'ed
ses, err := cl.NewSession()
if err != nil {
return nil, nil, fmt.Errorf("NewSession: %w", err)
}
pw, err := ses.StdinPipe()
if err != nil {
return nil, nil, fmt.Errorf("StdinPipe: %w", err)
}
pr, err := ses.StdoutPipe()
if err != nil {
return nil, nil, fmt.Errorf("StdoutPipe: %w", err)
}
pe, err := ses.StderrPipe()
if err != nil {
return nil, nil, fmt.Errorf("StderrPipe: %w", err)
}
// FIXME use accurate Bash escaping
// TODO find a way to strictly separate parameters and paths (`--` is not supported here)
ses.Start(`/usr/bin/sqlite3 -noheader -json "` + strconv.Quote(databasePath) + `"`)
return handleEvents(pw, pr, pe, ses.Wait)
}
//
type sshDriver struct {
cl *ssh.Client
}
func (d *sshDriver) Open(connectionString string) (driver.Conn, error) {
// TODO support custom binpath from our connection string
chEvents, pw, err := SSHEvents(d.cl, connectionString)
if err != nil {
return nil, err
}
return &SCConn{
listen: chEvents,
w: pw,
}, nil
}
var _ driver.Driver = &sshDriver{} // interface assertion
//
type sshConnector struct {
connectionString string
driver *sshDriver
}
func (c *sshConnector) Connect(context.Context) (driver.Conn, error) {
// FIXME support context
return c.driver.Open(c.connectionString)
}
func (c *sshConnector) Driver() driver.Driver {
return c.driver
}
var _ driver.Connector = &sshConnector{} // interface assertion
//
// OpenSSH opens an sql.DB connection over SSH using the supplied ssh.Client
// object.
func OpenSSH(cl *ssh.Client, databasePath string) *sql.DB {
return sql.OpenDB(&sshConnector{
connectionString: databasePath,
driver: &sshDriver{
cl: cl,
},
})
}

View File

@@ -21,25 +21,26 @@ import (
"errors"
"fmt"
"io"
"os/exec"
"reflect"
"qbolt/lexer"
"github.com/google/uuid"
)
const DriverName = `sqliteclidriver`
var ErrNotSupported = errors.New("Not supported")
//
// SCDriver is a thing that can open connections to the database for a given
// connection string. It has no particular state.
type SCDriver struct{}
func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
// TODO support custom binpath from our connection string
cmd := exec.Command(`/usr/bin/sqlite3`, `-noheader`, `-json`, connectionString) // n.b. doesn't support `--`
chEvents, pw, err := ExecEvents(cmd)
chEvents, pw, err := LocalBinEvents(connectionString)
if err != nil {
return nil, err
}
@@ -53,17 +54,21 @@ func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
var _ driver.Driver = &SCDriver{} // interface assertion
func init() {
sql.Register("sqliteclidriver", &SCDriver{})
sql.Register(DriverName, &SCDriver{})
}
//
// SCConnector is a container holding a driver and connection string together.
// It is the result of parsing a sql.Open(driverName, connectionString) call
// and has not parsed anything.
type SCConnector struct {
connectionString string
driver *SCDriver
}
func (c *SCConnector) Connect(context.Context) (driver.Conn, error) {
// FIXME support context
return c.driver.Open(c.connectionString)
}
@@ -75,6 +80,7 @@ var _ driver.Connector = &SCConnector{} // interface assertion
//
// SCConn represents a single, active, open, connection to the database.
type SCConn struct {
listen <-chan processEvent
w io.WriteCloser
@@ -376,3 +382,15 @@ func (r *SCRows) Next(dest []driver.Value) error {
r.idx++
return nil
}
func (r *SCRows) ColumnTypeDatabaseTypeName(index int) string {
return "BLOB" // FIXME We are not type-safe
}
func (r *SCRows) ColumnTypeScanType(index int) reflect.Type {
return reflect.TypeOf([]byte{})
}
func (r *SCRows) ColumnTypeNullable(index int) (nullable, ok bool) {
return true, true // FIXME
}

View File

@@ -21,24 +21,24 @@ type SSHTunnel struct {
Type autoconfig.OneOf
Password *struct {
Password autoconfig.Password
}
} `yicon:":/assets/key.png" json:",omitempty"`
PrivateKeyExternal *struct {
PrivateKeyFile autoconfig.ExistingFile `ylabel:"Private Key"`
PrivateKeyFilePassword autoconfig.Password `ylabel:"Password (optional)"`
} `ylabel:"Private key (External)"`
} `ylabel:"Private key (External)" yicon:":/assets/page_key.png" json:",omitempty"`
PrivateKeyInternal *struct {
PrivateKeyContent autoconfig.MultiLineString `ylabel:"Private Key"`
PrivateKeyContentPassword autoconfig.Password `ylabel:"Password (optional)"`
} `ylabel:"Private key (Internal)"`
SSHAgent *sshAgentConn `ylabel:"SSH Agent"`
} `ylabel:"Private key (Internal)" yicon:":/assets/page_key.png" json:",omitempty"`
SSHAgent *sshAgentConn `ylabel:"SSH Agent" yicon:":/assets/vendor_ssh.png" json:",omitempty"`
}
H2 autoconfig.Header `ylabel:"Server host key:" json:",omitempty"`
HostVerification struct {
Type autoconfig.OneOf
InsecureSkipVerify *struct{}
InsecureSkipVerify *struct{} `json:",omitempty"`
ExternalKnownHostsFile *struct {
Path autoconfig.ExistingFile
}
} `json:",omitempty"`
}
}

132
table.go
View File

@@ -7,6 +7,7 @@ import (
type TableColumn interface {
SetRowCount(newlen int)
SetCell(aRow int, data any)
GetCell(aRow int) any // only needed for editing
Display(aRow int) *qt.QVariant
Inspect(parent *qt.QWidget, aRow int)
ApplySimpleChange(aRow int, data *qt.QVariant)
@@ -14,22 +15,21 @@ type TableColumn interface {
IndicateBlue() bool
}
type EditAdvancedTableColumn interface {
CreateEditor(parent *qt.QWidget, aRow int, resolve, reject func())
}
type NullableTableColumn interface {
CellIsNull(aRow int) bool
}
const (
CO_INSERT = qt.Yellow
CO_EDIT_IMPLICIT = qt.Green
CO_EDIT_EXPLICIT = qt.DarkGreen
CO_DELETE = qt.Red
CO_OBJECT = qt.Blue
)
type columnType int
const (
columnType_invalid columnType = iota
columnType_inlineText
columnType_bsonDoc
columnType_popupData
// TODO add a column type for map[string]string that can show content in a mini popup?? (Useful for redis + secretsvc)
CO_CELL_NULL = qt.Gray
)
type tableState struct {
@@ -48,19 +48,19 @@ type tableState struct {
model *qt.QAbstractTableModel
tbl *qt.QTableView
dg_normal, dg_bson, dg_binary *qt.QAbstractItemDelegate
dg_advanced *qt.QAbstractItemDelegate
}
// SetupColumns resets the table's content.
// It preserves the OnEdited callback
func (ts *tableState) SetupColumns(columns []columnType, labels []string) {
func (ts *tableState) SetupColumns(columns []TableColumn, labels []string) {
if ts.tbl.IsEnabled() {
ts.tbl.SetEnabled(false)
ts.model.BeginResetModel()
}
ts.columns = make([]TableColumn, len(columns))
ts.columns = columns
ts.columnLabels = labels
ts.SetAllowEditing(false)
@@ -69,44 +69,25 @@ func (ts *tableState) SetupColumns(columns []columnType, labels []string) {
ts.deleteRows = make(map[int]struct{}, 0)
ts.primaryKeys = nil
for aCol, ctype := range columns {
switch ctype {
case columnType_inlineText:
for aCol, _ := range columns {
ts.columns[aCol] = &stringColumn{}
// Reset renderer to something like the default Qt one
// Persist the delegate for the lifetime of this tableState - the
// QTableView does not take ownership of a supplied delegate(??)
// TODO is that true? Then why are we passing in the parent?
if ts.dg_normal == nil {
ts.dg_normal = qt.NewQStyledItemDelegate2(ts.tbl.QObject).QAbstractItemDelegate
// Column types that implement the EditAdvancedTableColumn interface
// get hooked up to the custom delegate renderer
if _, ok := ts.columns[aCol].(EditAdvancedTableColumn); ok {
if ts.dg_advanced == nil {
// Persist the delegate for the lifetime of this tableState
ts.dg_advanced = table_makeAdvancedEditorItemDelegate(ts, ts.tbl.QObject)
}
ts.tbl.SetItemDelegateForColumn(aCol, ts.dg_normal)
case columnType_popupData:
ts.columns[aCol] = &binColumn{}
ts.tbl.SetItemDelegateForColumn(aCol, ts.dg_advanced)
if ts.dg_binary == nil {
ts.dg_binary = table_makeBinaryItemDelegate(ts, ts.tbl.QObject)
}
ts.tbl.SetItemDelegateForColumn(aCol, ts.dg_binary)
case columnType_bsonDoc:
ts.columns[aCol] = &bsonColumn{}
if ts.dg_bson == nil {
ts.dg_bson = table_makeBsonItemDelegate(ts, ts.tbl.QObject)
}
ts.tbl.SetItemDelegateForColumn(aCol, ts.dg_bson)
default:
panic("bad columnType")
} else {
// Reset renderer to the default Qt one
ts.tbl.SetItemDelegateForColumn(aCol, nil)
}
}
ts.SetRowCount(0) // populate slices
}
func (ts *tableState) SetAllowEditing(allow bool) {
@@ -187,9 +168,9 @@ func (ts *tableState) SetRowPrimaryKey(aRow int, data []byte) {
func (ts *tableState) Wipeout() {
ts.SetupColumns(
[]columnType{
columnType_inlineText,
columnType_popupData,
[]TableColumn{
&stringColumn{},
&binColumn{},
},
[]string{"Key", "Value"},
)
@@ -317,6 +298,10 @@ func NewTableState(tbl *qt.QTableView) *tableState {
return qt.NewQColor2(CO_OBJECT).ToQVariant()
}
if supportsNull, ok := ts.columns[aCol].(NullableTableColumn); ok && supportsNull.CellIsNull(aRow) {
return qt.NewQColor2(CO_CELL_NULL).ToQVariant()
}
return qt.NewQVariant() // just default
case int(qt.EditRole):
@@ -423,3 +408,58 @@ func NewTableState(tbl *qt.QTableView) *tableState {
return &ts
}
func table_makeAdvancedEditorItemDelegate(ts *tableState, parent *qt.QObject) *qt.QAbstractItemDelegate {
zombie := qt.NewQStyledItemDelegate2(parent)
zombie.OnCreateEditor(func(super func(parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget, parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget {
// return a custom editor widget
aCol, aRow := index.Column(), index.Row()
self := ts.columns[aCol].(EditAdvancedTableColumn)
// The widget here is rendered stacked on top of the cell's existing DisplayRole
// It doesn't replace it
editor := qt.NewQLabel(parent)
editor.SetAutoFillBackground(true) // Hide parent
editor.SetText("Editing...")
self.CreateEditor(
editor.QWidget,
aRow,
func() {
// Signal success/finished editing
zombie.CommitData(editor.QWidget)
zombie.CloseEditor2(editor.QWidget, qt.QAbstractItemDelegate__NoHint)
},
func() {
// close editor, without, signalling commitData (this was readonly)
//zombie.CommitData(editor.QWidget)
zombie.CloseEditor2(editor.QWidget, qt.QAbstractItemDelegate__NoHint)
},
)
return editor.QWidget
})
zombie.OnSetEditorData(func(super func(editor *qt.QWidget, index *qt.QModelIndex), editor *qt.QWidget, index *qt.QModelIndex) {
// TODO we may want to conditionally do nothing here??
super(editor, index)
})
zombie.OnSetModelData(func(super func(editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex), editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex) {
// TODO we may want to conditionally do nothing here??
super(editor, model, index) // Save
})
zombie.OnUpdateEditorGeometry(func(super func(editor *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex), editor *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) {
// after having created our custom editor, set the widget's size as per the table column
editor.SetGeometryWithGeometry(option.Rect())
// super(editor, option, index)
})
return zombie.QAbstractItemDelegate
}

View File

@@ -20,14 +20,26 @@ func (bc *binColumn) SetRowCount(newlen int) {
func (bc *binColumn) SetCell(aRow int, data any) {
str, ok := data.([]byte)
if !ok {
panic("bad data type")
panic(fmt.Sprintf("bad data type (got %T)", data))
}
bc.vals[aRow] = str
}
func (bc *binColumn) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (bc *binColumn) Display(aRow int) *qt.QVariant {
return qt.NewQVariant11(formatUtf8(bc.vals[aRow]))
const showLen = 140
cell := bc.vals[aRow]
if len(cell) > showLen {
return qt.NewQVariant11(formatUtf8(cell[0:showLen]) + "...")
}
return qt.NewQVariant11(formatUtf8(cell))
}
func (bc *binColumn) Inspect(parent *qt.QWidget, aRow int) {
@@ -51,126 +63,61 @@ func (bc *binColumn) IndicateBlue() bool {
return false
}
var _ TableColumn = &binColumn{}
func (bc *binColumn) CreateEditor(parent *qt.QWidget, aRow int, resolve, reject func()) {
func table_makeBinaryItemDelegate(ts *tableState, parent *qt.QObject) *qt.QAbstractItemDelegate {
// Only called if allowEdit=true
const (
ActionMode__invalid int = iota
ActionMode_Text_Readonly // Always a popup, otherwise you would just look at it
ActionMode_Text_Editable_Popup
//ActionMode_Text_Editable_Inline // TODO
ActionMode_Hex_Readonly
)
bslice := bc.vals[aRow]
const ActionModeProperty string = `x-am`
// Check if this contains valid UTF-8 data.
// If so, show in a multiline text editor
// If not, use the hexview popup + reject all edits
zombie := qt.NewQStyledItemDelegate2(parent)
isText := utf8.Valid(bslice)
zombie.OnCreateEditor(func(super func(parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget, parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget {
// return a custom editor widget
aCol, aRow := index.Column(), index.Row()
self := ts.columns[aCol].(*binColumn)
bslice := self.vals[aRow]
// Check if this contains valid UTF-8 data.
// If so, show in a multiline text editor + allow editing if this tableState allowed editing
// If not, use the hexview popup
isText := utf8.Valid(bslice)
// The widget here is rendered stacked on top of the cell's existing DisplayRole
// It doesn't replace it
editor := qt.NewQLabel(parent)
editor.SetAutoFillBackground(true) // Hide parent
if isText && !ts.allowEdit {
editor.SetProperty(ActionModeProperty, qt.NewQVariant4(ActionMode_Text_Readonly))
editor.SetText("Viewing...")
// TODO
} else if isText && ts.allowEdit {
editor.SetProperty(ActionModeProperty, qt.NewQVariant4(ActionMode_Text_Editable_Popup))
editor.SetText("Editing...")
var textEdit autoconfig.MultiLineString
textEdit = autoconfig.MultiLineString(string(bslice))
autoconfig.OpenDialog(&textEdit, editor.QWidget, APPNAME, func() {
// Store change directly back into column store
self.vals[aRow] = []byte(string(textEdit))
// Signal success/finished editing
zombie.CommitData(editor.QWidget)
zombie.CloseEditor2(editor.QWidget, qt.QAbstractItemDelegate__NoHint)
})
} else {
// Binary data
// Popup hexview
editor.SetProperty(ActionModeProperty, qt.NewQVariant4(ActionMode_Hex_Readonly))
editor.SetText("Viewing...")
dlg := qt.NewQDialog(parent)
dlg.SetModal(true)
dlg.SetWindowTitle(fmt.Sprintf("%s - Hex view (%d bytes)", APPNAME, len(bslice)))
dlg.SetContentsMargins(0, 0, 0, 0)
layout := qt.NewQGridLayout(dlg.QWidget)
layout.SetContentsMargins(0, 0, 0, 0)
dlg.SetLayout(layout.QLayout)
hxvw := vcl_hexview(nil, bytes.NewReader(bslice), int64(len(bslice)))
layout.AddWidget2(hxvw, 0, 0)
// Dialog should be, by default, big enough to show the whole table at once
// Slightly overshoots on Breeze theme with default fonts
// TODO figure out the real width accurately
dlg.SetMinimumWidth(700)
dlg.Show()
dlg.OnFinished(func(_ int) {
// close editor, without, signalling commitData (this was readonly)
//zombie.CommitData(editor.QWidget)
zombie.CloseEditor2(editor.QWidget, qt.QAbstractItemDelegate__NoHint)
})
if isText {
var textEdit struct {
Value autoconfig.MultiLineString `ylabel:""`
}
return editor.QWidget
})
zombie.OnSetEditorData(func(super func(editor *qt.QWidget, index *qt.QModelIndex), editor *qt.QWidget, index *qt.QModelIndex) {
actionType := editor.Property("x-am").ToInt()
switch actionType {
case ActionMode_Text_Readonly:
// TODO
case ActionMode_Text_Editable_Popup:
super(editor, index) // Save
case ActionMode_Hex_Readonly:
// do nothing
default:
panic("bad actionMode in editor delegate widget")
}
})
textEdit.Value = autoconfig.MultiLineString(string(bslice))
zombie.OnSetModelData(func(super func(editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex), editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex) {
actionType := editor.Property("x-am").ToInt()
switch actionType {
case ActionMode_Text_Readonly:
// TODO
case ActionMode_Text_Editable_Popup:
super(editor, model, index) // Save
case ActionMode_Hex_Readonly:
// do nothing
default:
panic("bad actionMode in editor delegate widget")
}
})
autoconfig.OpenDialog(&textEdit, parent, APPNAME, func() {
// Store change directly back into column store
bc.vals[aRow] = []byte(string(textEdit.Value))
return zombie.QAbstractItemDelegate
// Signal success/finished editing
resolve()
})
} else {
// Binary data
// Popup hexview
dlg := qt.NewQDialog(parent)
dlg.SetModal(true)
dlg.SetWindowTitle(fmt.Sprintf("%s - Hex view (%d bytes)", APPNAME, len(bslice)))
dlg.SetContentsMargins(0, 0, 0, 0)
layout := qt.NewQGridLayout(dlg.QWidget)
layout.SetContentsMargins(0, 0, 0, 0)
dlg.SetLayout(layout.QLayout)
hxvw := vcl_hexview(nil, bytes.NewReader(bslice), int64(len(bslice)))
layout.AddWidget2(hxvw, 0, 0)
// Dialog should be, by default, big enough to show the whole table at once
// Slightly overshoots on Breeze theme with default fonts
// TODO figure out the real width accurately
dlg.SetMinimumWidth(700)
dlg.Show()
dlg.OnFinished(func(_ int) {
// close editor, without, signalling commitData (this was readonly)
reject()
})
}
}
var _ TableColumn = &binColumn{}
var _ EditAdvancedTableColumn = &binColumn{} // interface assertion

View File

@@ -26,6 +26,10 @@ func (bc *bsonColumn) SetCell(aRow int, data any) {
bc.vals[aRow] = obj
}
func (bc *bsonColumn) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (bc *bsonColumn) Display(aRow int) *qt.QVariant {
return qt.NewQVariant11(fmt.Sprintf("BSON (%d keys)", len(bc.vals[aRow])))
}
@@ -79,64 +83,20 @@ func (bc *bsonColumn) IndicateBlue() bool {
return true
}
var _ TableColumn = &bsonColumn{}
func (bc *bsonColumn) CreateEditor(parent *qt.QWidget, aRow int, resolve, reject func()) {
func table_makeBsonItemDelegate(ts *tableState, parent *qt.QObject) *qt.QAbstractItemDelegate {
zombie := qt.NewQStyledItemDelegate2(parent)
// TODO this is not currently being called because MongoDB is not marked
// as being editable
zombie.OnCreateEditor(func(super func(parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget, parent *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) *qt.QWidget {
// return a custom editor widget
ptr_bData := &bc.vals[aRow]
aCol, aRow := index.Column(), index.Row()
self := ts.columns[aCol].(*bsonColumn)
ptr_bData := &self.vals[aRow]
// The widget here is rendered stacked on top of the cell's existing DisplayRole
// It doesn't replace it
foo := qt.NewQLabel(parent)
foo.SetAutoFillBackground(true) // Hide parent
foo.SetText("Editing...")
autoconfig.OpenDialog(ptr_bData, foo.QWidget, APPNAME, func() {
// onFinished
// We're already working with the data in-pointer, nothing to do here
// However - signal to the model that it's finished,
zombie.CommitData(foo.QWidget)
zombie.CloseEditor2(foo.QWidget, qt.QAbstractItemDelegate__NoHint)
})
return foo.QWidget
// return the default editor widget
//return super(parent, option, index)
autoconfig.OpenDialog(ptr_bData, parent, APPNAME, func() {
// onFinished
// We're already working with the data in-pointer, nothing to do here
// However - signal to the model that it's finished,
resolve()
})
zombie.OnSetEditorData(func(super func(editor *qt.QWidget, index *qt.QModelIndex), editor *qt.QWidget, index *qt.QModelIndex) {
// populate the custom editor with the table's current data
// DO NOTHING HERE - we have already set the data internally
// This calls onSetData
super(editor, index)
})
zombie.OnSetModelData(func(super func(editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex), editor *qt.QWidget, model *qt.QAbstractItemModel, index *qt.QModelIndex) {
// the table has requested to save data from the editor back into the model
// DO NOTHING HERE - autoconfig{} has already updated the data internally -
// However we do need to trigger model.OnSetData so that the green colour shows?
// FIXME
super(editor, model, index)
})
zombie.OnUpdateEditorGeometry(func(super func(editor *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex), editor *qt.QWidget, option *qt.QStyleOptionViewItem, index *qt.QModelIndex) {
// after having created our custom editor, set the widget's size as per the table column
editor.SetGeometryWithGeometry(option.Rect())
// super(editor, option, index)
})
return zombie.QAbstractItemDelegate
}
var _ TableColumn = &bsonColumn{}
var _ EditAdvancedTableColumn = &binColumn{} // interface assertion

76
table_dynamic.go Normal file
View File

@@ -0,0 +1,76 @@
package main
import (
"fmt"
qt "github.com/mappu/miqt/qt6"
)
type dynamicColumn struct {
vals []any
}
func (sc *dynamicColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
func (sc *dynamicColumn) SetCell(aRow int, data any) {
sc.vals[aRow] = data
}
func (bc *dynamicColumn) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (sc *dynamicColumn) Display(aRow int) *qt.QVariant {
return sc.SimpleEditData(aRow) // same as Qt::EditDataRole
}
func (sc *dynamicColumn) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
func (sc *dynamicColumn) SimpleEditData(aRow int) *qt.QVariant {
// Try and format this usefully for display
switch vv := sc.vals[aRow].(type) {
case string:
return qt.NewQVariant11(vv)
case []byte:
return qt.NewQVariant12(vv) // TODO can we switch to the dynamic editor - just for this cell?
case int64:
return qt.NewQVariant6(vv)
case bool:
return qt.NewQVariant8(vv)
default:
panic(fmt.Sprintf("dynamicColumn missing handling for type %T", vv))
}
}
func (sc *dynamicColumn) ApplySimpleChange(aRow int, data *qt.QVariant) {
switch vv := sc.vals[aRow].(type) {
case string:
sc.vals[aRow] = data.ToString()
case []byte:
sc.vals[aRow] = data.ToByteArray()
case int64:
sc.vals[aRow] = data.ToLongLong()
case bool:
sc.vals[aRow] = data.ToBool()
default:
panic(fmt.Sprintf("dynamicColumn missing handling for type %T", vv))
}
}
func (sc *dynamicColumn) IndicateBlue() bool {
return false
}
var _ TableColumn = &dynamicColumn{}

54
table_gomodule.go Normal file
View File

@@ -0,0 +1,54 @@
package main
import (
qt "github.com/mappu/miqt/qt6"
)
type goModuleColumn struct {
vals []string
}
func (sc *goModuleColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
func (sc *goModuleColumn) SetCell(aRow int, data any) {
str, ok := data.(string)
if !ok {
panic("bad data type")
}
sc.vals[aRow] = str
}
func (sc *goModuleColumn) GetCell(aRow int) any {
return sc.vals[aRow]
}
func (sc *goModuleColumn) Display(aRow int) *qt.QVariant {
return qt.NewQVariant11(sc.vals[aRow])
}
func (sc *goModuleColumn) Inspect(parent *qt.QWidget, aRow int) {
// Convert the 'go mod' URL into a (probable) web URL
urlStr := `https://` + sc.vals[aRow] + `/`
url := qt.NewQUrl3(urlStr)
qt.QDesktopServices_OpenUrl(url) // ignore return value
}
func (sc *goModuleColumn) SimpleEditData(aRow int) *qt.QVariant {
// Works directly with the simple (inline) editor, not a custom editor
return qt.NewQVariant11(sc.vals[aRow])
}
func (sc *goModuleColumn) ApplySimpleChange(aRow int, data *qt.QVariant) {
// Works directly with the simple (inline) editor, not a custom editor
sc.vals[aRow] = data.ToString()
}
func (sc *goModuleColumn) IndicateBlue() bool {
return true
}
var _ TableColumn = &goModuleColumn{}

62
table_int64.go Normal file
View File

@@ -0,0 +1,62 @@
package main
import (
"fmt"
qt "github.com/mappu/miqt/qt6"
)
type int64Column struct {
vals []int64
}
func (sc *int64Column) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
func (sc *int64Column) SetCell(aRow int, data any) {
str, ok := data.(int64)
if !ok {
panic(fmt.Sprintf("bad data type (got %T)", data))
}
sc.vals[aRow] = str
}
func (bc *int64Column) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (sc *int64Column) Display(aRow int) *qt.QVariant {
// TODO this does not seem sufficient to get QTableView to create a spinbox
// widget by itself
// This may be related to QSpinBox having 32-bit precision
//return qt.NewQVariant4(int(sc.vals[aRow]))
return qt.NewQVariant6(sc.vals[aRow])
}
func (sc *int64Column) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
func (sc *int64Column) SimpleEditData(aRow int) *qt.QVariant {
// Works directly with the simple (inline) editor, not a custom editor
return qt.NewQVariant6(sc.vals[aRow])
}
func (sc *int64Column) ApplySimpleChange(aRow int, data *qt.QVariant) {
// Works directly with the simple (inline) editor, not a custom editor
var ok bool
val := data.ToLongLongWithOk(&ok)
if !ok {
panic("Table provided non-numeric data")
}
sc.vals[aRow] = val
}
func (sc *int64Column) IndicateBlue() bool {
return false
}
var _ TableColumn = &int64Column{}

70
table_sqlnullint64.go Normal file
View File

@@ -0,0 +1,70 @@
package main
import (
"database/sql"
"fmt"
qt "github.com/mappu/miqt/qt6"
)
type sqlNullInt64Column struct {
vals []sql.NullInt64
}
func (sc *sqlNullInt64Column) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
func (sc *sqlNullInt64Column) SetCell(aRow int, data any) {
str, ok := data.(sql.NullInt64)
if !ok {
panic(fmt.Sprintf("bad data type (got %T)", data))
}
sc.vals[aRow] = str
}
func (bc *sqlNullInt64Column) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (sc *sqlNullInt64Column) Display(aRow int) *qt.QVariant {
cell := sc.vals[aRow]
if cell.Valid {
return qt.NewQVariant6(cell.Int64)
} else {
return qt.NewQVariant11("NULL") // TODO render this somehow differently?
}
}
func (sc *sqlNullInt64Column) CellIsNull(aRow int) bool {
return !sc.vals[aRow].Valid
}
func (sc *sqlNullInt64Column) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
func (sc *sqlNullInt64Column) SimpleEditData(aRow int) *qt.QVariant {
// Works directly with the simple (inline) editor, not a custom editor
cell := sc.vals[aRow]
if cell.Valid {
return qt.NewQVariant6(cell.Int64)
} else {
return qt.NewQVariant6(0)
}
}
func (sc *sqlNullInt64Column) ApplySimpleChange(aRow int, data *qt.QVariant) {
// Works directly with the simple (inline) editor, not a custom editor
val := data.ToLongLong()
sc.vals[aRow] = sql.NullInt64{Int64: val, Valid: true}
}
func (sc *sqlNullInt64Column) IndicateBlue() bool {
return false
}
var _ TableColumn = &sqlNullInt64Column{}
var _ NullableTableColumn = &sqlNullInt64Column{}

70
table_sqlnullstring.go Normal file
View File

@@ -0,0 +1,70 @@
package main
import (
"database/sql"
"fmt"
qt "github.com/mappu/miqt/qt6"
)
type sqlNullStringColumn struct {
vals []sql.NullString
}
func (sc *sqlNullStringColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
func (sc *sqlNullStringColumn) SetCell(aRow int, data any) {
str, ok := data.(sql.NullString)
if !ok {
panic(fmt.Sprintf("bad data type (got %T)", data))
}
sc.vals[aRow] = str
}
func (bc *sqlNullStringColumn) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (sc *sqlNullStringColumn) CellIsNull(aRow int) bool {
return !sc.vals[aRow].Valid
}
func (sc *sqlNullStringColumn) Display(aRow int) *qt.QVariant {
cell := sc.vals[aRow]
if cell.Valid {
return qt.NewQVariant11(cell.String)
} else {
return qt.NewQVariant11("NULL") // TODO render this somehow differently?
}
}
func (sc *sqlNullStringColumn) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
func (sc *sqlNullStringColumn) SimpleEditData(aRow int) *qt.QVariant {
// Works directly with the simple (inline) editor, not a custom editor
cell := sc.vals[aRow]
if cell.Valid {
return qt.NewQVariant11(cell.String)
} else {
return qt.NewQVariant11("")
}
}
func (sc *sqlNullStringColumn) ApplySimpleChange(aRow int, data *qt.QVariant) {
// Works directly with the simple (inline) editor, not a custom editor
str := data.ToString()
sc.vals[aRow] = sql.NullString{String: str, Valid: true}
}
func (sc *sqlNullStringColumn) IndicateBlue() bool {
return false
}
var _ TableColumn = &sqlNullStringColumn{}
var _ NullableTableColumn = &sqlNullStringColumn{}

View File

@@ -1,6 +1,8 @@
package main
import (
"fmt"
qt "github.com/mappu/miqt/qt6"
)
@@ -15,12 +17,16 @@ func (sc *stringColumn) SetRowCount(newlen int) {
func (sc *stringColumn) SetCell(aRow int, data any) {
str, ok := data.(string)
if !ok {
panic("bad data type")
panic(fmt.Sprintf("bad data type (got %T)", data))
}
sc.vals[aRow] = str
}
func (bc *stringColumn) GetCell(aRow int) any {
return bc.vals[aRow]
}
func (sc *stringColumn) Display(aRow int) *qt.QVariant {
return qt.NewQVariant11(sc.vals[aRow])
}
@@ -30,12 +36,12 @@ func (sc *stringColumn) Inspect(parent *qt.QWidget, aRow int) {
}
func (sc *stringColumn) SimpleEditData(aRow int) *qt.QVariant {
// Theoretically don't need to return anything here for simple-edits since
// the popup editor works directly with the column-store
// Works directly with the simple (inline) editor, not a custom editor
return qt.NewQVariant11(sc.vals[aRow])
}
func (sc *stringColumn) ApplySimpleChange(aRow int, data *qt.QVariant) {
// Works directly with the simple (inline) editor, not a custom editor
sc.vals[aRow] = data.ToString()
}

View File

@@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/binary"
"encoding/gob"
"go.mongodb.org/mongo-driver/v2/bson"
@@ -117,3 +118,14 @@ func alloc_inplace[T any](target **T) {
var newObj T
*target = &newObj
}
func int64_to_binary8(i int64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(i))
return b
}
func binary8_to_int64(val []byte) int64 {
// If this is supplied with a too-short value, we will panic
return int64(binary.LittleEndian.Uint64(val))
}