29 Commits

Author SHA1 Message Date
2a1d0fa036 etcd: support v2 as well as v3 2026-01-27 08:04:46 +13:00
5b9963eb77 rename kvstore_ApplyChanges -> ApplyChanges_binColumn 2026-01-27 08:03:59 +13:00
ca7c827e75 etcd: initial support (v3 only) 2026-01-24 18:52:16 +13:00
fd913fa1eb qbolt: use full installed list of qstyles 2026-01-24 17:47:07 +13:00
8e5f003e29 doc: update TODO, README, CHANGELOG 2026-01-24 17:06:06 +13:00
28afd05199 ui: add appearance changer (qstyle, density, row backgrounds) 2026-01-24 16:51:40 +13:00
99e138aa94 tooltips: show badger/bolt full paths, show in connmgr + main area 2026-01-24 16:16:11 +13:00
518b66b270 config: refactor connector.String() to separate function [...]
- lmdb: adds (readonly) to default names
- sqlite/ssh: focus on DB name
2026-01-24 16:05:15 +13:00
ee066ec7e7 ui: fix 'failed to save' error if we fail to load config dialog 2026-01-24 15:33:20 +13:00
638d2e69eb ui/mainwindow: reduce main padding, reduce data tab padding 2026-01-24 15:29:58 +13:00
894f730706 ui/connection: better dialog size for instant connection 2026-01-24 15:29:47 +13:00
4498542e71 config: use non-conflicting names when saving new entries 2026-01-24 15:23:23 +13:00
a1345f1c24 table: hovering integers show converted timestamp in tooltip 2026-01-22 22:22:42 +13:00
73bc1c050b table: add context menu actions, support setting cell null 2026-01-22 22:22:23 +13:00
6a5605e067 table: show data type when hovering column header 2026-01-22 22:21:01 +13:00
f345860468 doc: update TODO 2026-01-22 18:27:04 +13:00
965a257ebb badger: fix extra data appearing in k/v pairs 2026-01-22 17:00:51 +13:00
fc9d1b54de doc: update TODO 2026-01-17 10:29:02 +13:00
0d04effe90 buntdb: support advanced options 2026-01-17 10:11:51 +13:00
ee1ff5582f bolt: support advanced options 2026-01-17 10:02:18 +13:00
029f79d800 badger: allow resetting advanced options struct 2026-01-16 19:29:28 +13:00
ea0ee78f2e autoconfig: upgrade v0.5->v0.6 (fix int sizes, scroll dialogs, autoupgrade field types, re-reset buttons) 2026-01-16 19:21:18 +13:00
9774a8690b doc: update TODO 2026-01-13 19:19:08 +13:00
3a66197c2c sqlite/sqliteclidriver: fix crash if zero rows in table 2026-01-13 19:19:06 +13:00
a2badc6964 sqlite: clidriver doesn't like "!=", use "<>" instead 2026-01-13 19:10:21 +13:00
aee1a7ede1 badger: support fully advanced configuration 2026-01-13 19:07:33 +13:00
1b5c97abca main: add --config-export, --config-import CLI flags 2026-01-13 19:07:19 +13:00
1c37b71414 sshtunnel: fix warning in test output 2026-01-13 19:07:04 +13:00
e9bdbb8066 doc: update TODO 2026-01-11 14:21:24 +13:00
46 changed files with 1290 additions and 237 deletions

View File

@@ -1,5 +1,23 @@
# Changelog
Unreleased vNext
- Badger, Bolt, BuntDB: Support full advanced configuration options
- Badger, Bolt: Show full paths to database file on hover
- SQLite CLI/SSH driver: Fix a syntax issue browsing tables, fix an issue if a table has zero rows
- Allow exporting configuration via new `--config-export` and `--config-import` command-line arguments
- UI: Show column's datatype in hover tooltip
- UI: Add context menu actions to data view
- UI: Allow setting cells to NULL
- UI: Detect integer Unix timestamps (seconds or milliseconds) and show local+UTC time in hover tooltip
- UI: Allow configuring the appearance - Qt Style, Density/Padding, and alternating row backgrounds
- UI: Reduce default padding in the main window
- UI: Update autoconfig library to v0.6.0: large configuration dialogs now scrollable, adds "reset to default" buttons
- UI: Show basic database properties when hovering connection in Connection Manager and in main tree view
- Connection Manager: Add `(2)` prefixes when saving new connections
- Fix an issue with uninitialized slice data appearing in binary data columns, affecting at least Badger
- Fix a cosmetic issue Connection Manager saying "fail to save" error messages if we fail to load
2026-01-04 v2.1.0
- SQLite: Support SSH tunnel

View File

@@ -70,3 +70,11 @@ test-mongo:
.PHONY: test-redis
test-redis:
sudo docker run --rm -p 127.0.0.1:6379:6379 redis:latest
.PHONY: test-etcd
test-etcd:
# v3.5 series: last version to support both etcd v2 and v3 APIs
# Optional: can use `--experimental-enable-v2v3 ''` flag to map v2 API into the v3 namespace,
# otherwise they are separate storages
# Test URL: http://127.0.0.1:2379/
sudo docker run --rm -p 2379:2379 -p 2380:2380 gcr.io/etcd-development/etcd:v3.5.26 /usr/local/bin/etcd --name s1 --enable-v2 --experimental-enable-v2v3 'mapping-prefix-here' --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379

View File

@@ -4,29 +4,38 @@ A graphical interface for multiple databases.
## Features
- Native desktop application, running on Linux, Windows, macOS, and Android
- Lightweight native desktop application, running on Linux, Windows, macOS, and Android
- Supports many database types
- Connect to multiple databases at once
- Browse table/bucket content
- Use context menu to perform special table/bucket actions
- Edit content, and add/delete rows for supported databases
- "Set cell to null" via context menu
- View database/bucket statistics and metadata
- Run custom SQL queries
- Select text to run partial query
- Optimised grid renderer
- Uses virtual-scrolling and a type-safe column-store
- Safe handling for non-UTF8 key and data fields
- Hex viewer for binary data
- Detect integer Unix timestamps (seconds or milliseconds) and show local+UTC time in hover tooltip
- Configurable appearance (style, density, alternating row backgrounds)
- Connection Manager saves connections with AEAD AES256-GCM using OS keychain
- Command-line feature to import/export saved connections
- SSH tunnel for supported databases
## Supported databases
There are currently 18 supported databases:
There are currently 19 supported databases:
Database |Read |Editing |Query |Connection options |Context menu actions
-------------|------|---------|------|--------------------|--------
Badger v4 |Yes |Yes |No |Encrypted, readonly, in-memory |Backup, restore, compact
Badger v4 |Yes |Yes |No |Encrypted, readonly, in-memory, advanced |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
BuntDB |Yes |Yes |No |In-memory, advanced |Shrink
Bolt |Yes |Yes |No |Readonly, advanced |Create/delete child buckets, import/export as zip
Debconf |Yes |No |No | |
Etcd |Yes |Yes |No |v2/v3 |(v2) Create/delete child databases
Freedesktop.org Secret Service |Yes |No | No | |Unlock, create new collection
LevelDB |Yes |Yes |No |Readonly |
LMDB |Yes |Yes |No |Multi-DB, readonly |Create/delete child databases

22
TODO
View File

@@ -23,10 +23,12 @@
- MySQL (& MariaDB/TiDB)
- Postgres
- CLI using psql
- Firebird/interbase (embedded and remote)
- 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
- DuckDB https://github.com/duckdb/duckdb-go
- Other K/V stores from https://github.com/smallnest/kvbench
- Windows registry
- Allow entering path for quick navigation
@@ -38,9 +40,6 @@
- CloverDB (built on Bolt/Badger) - https://github.com/ostafen/clover
- APCu - need some sort of hook into the storage engine
- UnisonDB - https://github.com/ankur-anand/unisondb
- Etcd
- v2: hierarchal
- v3: flat key namespace
- CSV file
- Allow querying with sqlite or duckDB?
- Parquet file
@@ -62,10 +61,13 @@
- Generic ODBC, database/sql, ...
- Other language DBs
- C, C++
- Berkeley BDB
- Tokyo Cabinet, Kyoto Cabinet, Tkrzw
- 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)
- Other classic DBM (Samba tdb, GNU gdbm, ...)
- `/var/cache/man/index.db` is a gdbm file
- RocksDB
- https://github.com/tecbot/gorocksdb Go bindings, need pkg-config rocksdb
- Rust
@@ -85,7 +87,7 @@
- https://github.com/litements/litexplore
- Badger:
- v1/v2/v3 support
- option to use namespace separators for virtual buckets
- option to use namespace separators for virtual buckets / isolate specific key ranges?
- SQLite:
- drop table doesn't autorefresh nav since callback is late
- more accurate type handling
@@ -94,7 +96,6 @@
- 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
- set cell null
- other special objects
- triggers? udf functions?
- virtual tables, shadow tables
@@ -103,7 +104,9 @@
- both show in pragma_table_list()
- integrity checks / quick_check
- attach additional db to same connection ("schemas")
- view the contents of an index, using imposter tables - https://sqlite.org/imposter.html
- ~~autoincrement: if column is autoincrement and left blank on insert, do not populate in INSERT statement~~ works with implicitly null columns
- BUG: non-nullable columns are being detected as nullable
- LMDB: dupsort mode (duplicate keys / entries-per-key)
- MongoDB
- UI for replica sets, ssl certs, cluster, custom auth database
@@ -114,6 +117,8 @@
- drop multidb doesn't autorefresh nav
- SSH tunnel
- option to use external/system SSH
- Popup prompt for SSHkey password
- Dynamic SSH_AUTH_SOCK env instead of static
- SSH over Cockpit
- Performance
- Warning if data table is filtered to 1000 rows, or add pagination
@@ -127,3 +132,10 @@
- Export all data from all buckets within a DB
- Reconnect
- Connection manager: clone entry
- Lotus, Rose, Pebble, ...: Support other advanced options
- UI: Save appearance settings to file
- UI: Apply appearance settings to query result table
- UI: List all available QStyles
- Etcd:
- Support SSH tunnel
- Other actions, compaction, backup/restore, ...

BIN
assets/vendor_etcd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

View File

@@ -13,7 +13,12 @@ import (
)
type DBConnector interface {
Connect(context.Context) (loadedDatabase, string, error)
Connect(context.Context) (loadedDatabase, error)
fmt.Stringer
}
type DetailedStringer interface {
DetailedString() string
}
type ConnectionConfig struct {
@@ -23,6 +28,7 @@ type ConnectionConfig struct {
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"`
Etcd *etcdConn `ylabel:"etcd" yicon:":/assets/vendor_etcd.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"`
@@ -63,10 +69,15 @@ func (cc *ConnectionConfig) Icon() string {
return yicon
}
// String is used as the connection's name when (A) connecting directly, to show
// in the left-hand nav; and (B) when saving a new connection, the saved name
// It's usually a simple, single word or filename.
func (cc *ConnectionConfig) String() string {
if selection, err := cc.selection(); err == nil {
if stringer, ok := selection.(fmt.Stringer); ok {
return stringer.String()
if candidate := stringer.String(); candidate != "" && candidate != "." {
return candidate
}
}
}
@@ -77,6 +88,24 @@ func (cc *ConnectionConfig) String() string {
return string(cc.Type)
}
// Tooltip is used as the hover tooltip in the connection manager.
// It can show more detail (e.g. full path spec).
// If there is no useful more detail, returns empty-string.
func (cc *ConnectionConfig) Tooltip() string {
// Try DetailedString() if there is such a method
if selection, err := cc.selection(); err == nil {
if getDetails, ok := selection.(DetailedStringer); ok {
if candidate := getDetails.DetailedString(); candidate != "" && candidate != "." {
return candidate
}
}
}
// Otherwise - just same as .String()
return cc.String()
}
func (cc *ConnectionConfig) selection() (DBConnector, error) {
selection := reflect.ValueOf(cc).Elem().FieldByName(string(cc.Type))
if !selection.IsValid() {
@@ -91,10 +120,10 @@ func (cc *ConnectionConfig) selection() (DBConnector, error) {
return con, nil
}
func (cc *ConnectionConfig) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (cc *ConnectionConfig) Connect(ctx context.Context) (loadedDatabase, error) {
dbc, err := cc.selection()
if err != nil {
return nil, "", fmt.Errorf("Invalid database engine %q", cc.Type)
return nil, fmt.Errorf("Invalid database engine %q", cc.Type)
}
return dbc.Connect(ctx)
@@ -117,6 +146,7 @@ func (f *App) showConnectDialog(config *ConnectionConfig) {
dlg.ConnectDialog.SetParent2(f.ui.MainWindow.QWidget, qt.Dialog)
dlg.ConnectDialog.SetModal(true)
dlg.ConnectDialog.SetAttribute(qt.WA_DeleteOnClose)
dlg.formLayout.SetSizeConstraint(qt.QLayout__SetMinAndMaxSize) // Expand dialog to fit form content
saver := autoconfig.MakeConfigArea(config, dlg.formLayout)
@@ -132,15 +162,17 @@ func (f *App) showConnectDialog(config *ConnectionConfig) {
// Connect -> get ld
ctx := context.Background() // TODO do in background thread?
ld, displayName, err := config.Connect(ctx)
ld, err := config.Connect(ctx)
if err != nil {
_ = qt.QMessageBox_Critical(dlg.ConnectDialog.QWidget, APPNAME, fmt.Sprintf("Connecting to %s database: %s", config.Type, err.Error()))
// Prevent the dialog from closing: do not call super()
return
}
displayName := config.String()
// Add ld to mainwindow
f.addTopLevelDatabaseConnection(ld, displayName)
f.addTopLevelDatabaseConnection(ld, displayName, config.Tooltip())
// Connection OK
// Offer to save into connection-manager
@@ -190,6 +222,8 @@ func (f *App) TrySaveIntoConnectionManager(cc *ConnectionConfig, displayName str
displayName = cc.String()
}
displayName = data.getNonConflictingName(displayName)
data.Entries = append(data.Entries, SavedConfigEntry{
Description: displayName,
Connection: *cc,
@@ -205,7 +239,7 @@ func (f *App) OnMnuConnectionManagerClick() {
data, err := f.getConnectionManagerContents()
if err != nil {
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, ConnMgrSaveError{err}.Error())
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, ConnMgrLoadError{err}.Error())
return
}
@@ -221,6 +255,10 @@ func (f *App) OnMnuConnectionManagerClick() {
itm.SetText(0, entry.Description)
itm.SetIcon(0, qt.NewQIcon4(entry.Connection.Icon()))
if tooltip := entry.Connection.Tooltip(); tooltip != "" && tooltip != entry.Description {
itm.SetToolTip(0, tooltip)
}
dlg.treeWidget.AddTopLevelItem(itm)
}
@@ -255,7 +293,7 @@ func (f *App) OnMnuConnectionManagerClick() {
entry := data.Entries[dlg.treeWidget.IndexFromItem(itm).Row()]
ld, _, err := entry.Connection.Connect(ctx)
ld, err := entry.Connection.Connect(ctx)
if err != nil {
_ = qt.QMessageBox_Critical(dlg.connectionManagerDialog.QWidget, APPNAME, fmt.Sprintf("Connecting to %s database: %s", entry.Connection.Type, err.Error()))
return false
@@ -264,7 +302,7 @@ func (f *App) OnMnuConnectionManagerClick() {
// Add ld to mainwindow
// Don't use the displayName from the Connect() function - use the saved
// displayname instead
f.addTopLevelDatabaseConnection(ld, entry.Description)
f.addTopLevelDatabaseConnection(ld, entry.Description, entry.Connection.Tooltip())
return true
}
@@ -350,6 +388,8 @@ func (f *App) OnMnuConnectionManagerClick() {
autoconfig.OpenDialog(&obj, dlg.connectionManagerDialog.QWidget, "New connection", func() {
obj.Description = data.getNonConflictingName(obj.Description)
data.Entries = append(data.Entries, obj)
addEntryFor(obj)

View File

@@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/zalando/go-keyring"
@@ -27,12 +28,36 @@ type SavedConfig struct {
Entries []SavedConfigEntry
}
// getNonConflictingName returns a version of the input name that does not
// conflict with any existing saved entry.
// It adds " (2)", " (3)", etc. prefixes.
func (s *SavedConfig) getNonConflictingName(nameSuggest string) string {
existingNames := make(map[string]struct{}, len(s.Entries))
for _, e := range s.Entries {
existingNames[e.Description] = struct{}{}
}
i := 0
for {
i++ // starts at 1
testName := nameSuggest
if i > 1 {
testName += ` (` + strconv.Itoa(i) + `)`
}
if _, ok := existingNames[testName]; !ok {
return testName
}
}
}
const (
saveSettingsFilename = `settings.dat`
keychainUserName = `settings-encryption-key`
)
func (f *App) getConnectionManagerContents() (*SavedConfig, error) {
func (f *App) getConnectionManagerContentsJson() ([]byte, error) {
cfgd, err := os.UserConfigDir()
if err != nil {
return nil, err
@@ -42,13 +67,6 @@ func (f *App) getConnectionManagerContents() (*SavedConfig, error) {
ciphertext, err := os.ReadFile(filepath.Join(cfgd, APPNAME, saveSettingsFilename))
if err != nil {
if os.IsNotExist(err) {
// No file exists. Use blank
return &SavedConfig{
UserAgent: APPNAME,
}, nil
}
return nil, err
}
@@ -77,8 +95,19 @@ func (f *App) getConnectionManagerContents() (*SavedConfig, error) {
return nil, err
}
plaintext, err := cw.Open(ciphertext[:0], nil, ciphertext, nil) // @ref https://pkg.go.dev/crypto/cipher#AEAD
return cw.Open(ciphertext[:0], nil, ciphertext, nil) // @ref https://pkg.go.dev/crypto/cipher#AEAD
}
func (f *App) getConnectionManagerContents() (*SavedConfig, error) {
plaintext, err := f.getConnectionManagerContentsJson()
if err != nil {
if os.IsNotExist(err) {
// No file exists. Use blank
return &SavedConfig{
UserAgent: APPNAME,
}, nil
}
return nil, err
}
@@ -99,6 +128,21 @@ func (f *App) getConnectionManagerContents() (*SavedConfig, error) {
}
func (f *App) saveConnectionManagerContents(sc *SavedConfig) error {
// Force update the saved version
sc.UserAgent = APPNAME + `/` + appVersion // e.g. QBolt/v0.0.0-devel
// Marshal
plaintext, err := json.Marshal(sc)
if err != nil {
return err
}
return f.saveConnectionManagerContentsJson(plaintext)
}
func (f *App) saveConnectionManagerContentsJson(plaintext []byte) error {
cfgd, err := os.UserConfigDir()
if err != nil {
return err
@@ -158,16 +202,6 @@ func (f *App) saveConnectionManagerContents(sc *SavedConfig) error {
}
}
// Force update the saved version
sc.UserAgent = APPNAME + `/` + appVersion // e.g. QBolt/v0.0.0-devel
// Marshal
plaintext, err := json.Marshal(sc)
if err != nil {
return err
}
// Encrypt
encryptionKeyBytes, err := hex.DecodeString(details)

View File

@@ -4,6 +4,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"os"
"path/filepath"
@@ -65,7 +66,7 @@ func (ld *badgerLoadedDatabase) RenderForNav(f *tableState, bucketPath []string)
func (n *badgerLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string) error {
return n.db.Update(func(txn *badger.Txn) error {
return kvstore_ApplyChanges(f, txn.Set, txn.Delete)
return ApplyChanges_binColumn(f, txn.Set, txn.Delete)
})
}
@@ -137,6 +138,19 @@ var _ editableLoadedDatabase = &badgerLoadedDatabase{} // interface assertion
//
type BadgerResettableOptions badger.Options
func (bao *BadgerResettableOptions) Reset() {
if bao == nil {
return
}
opts := badger.DefaultOptions("")
opts.Logger = nil // Have to wipe this out otherwise we can't JSON marshal our struct
*bao = BadgerResettableOptions(opts)
}
type badgerConnection struct {
Type autoconfig.OneOf
Disk *struct {
@@ -145,6 +159,9 @@ type badgerConnection struct {
Encryption *encryptionKey
} `json:",omitempty"`
Memory *struct{} `json:",omitempty"`
Advanced *struct {
*BadgerResettableOptions `ylabel:"Options"`
} `json:",omitempty"`
}
type encryptionKey struct {
@@ -172,37 +189,65 @@ func (e encryptionKey) Get() ([]byte, error) {
}
}
func (bdc *badgerConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
if bdc.Disk != nil {
opts := badger.DefaultOptions(string(bdc.Disk.Directory))
func (bdc *badgerConnection) String() string {
return filepath.Base(bdc.DetailedString())
}
func (bdc *badgerConnection) DetailedString() string {
if bdc.Type == "Disk" {
return string(bdc.Disk.Directory)
} else if bdc.Type == "Memory" {
return `:memory:` // SQLite-style naming
} else if bdc.Type == "Advanced" {
return bdc.Advanced.BadgerResettableOptions.Dir
}
return "" // unreachable
}
var _ DBConnector = &badgerConnection{} // interface assertion
func (bdc *badgerConnection) Connect(ctx context.Context) (loadedDatabase, error) {
var opts badger.Options
// Basic options
if bdc.Type == "Disk" {
opts = badger.DefaultOptions(string(bdc.Disk.Directory))
opts.ReadOnly = bdc.Disk.Readonly
opts.MetricsEnabled = false
if bdc.Disk.Encryption != nil {
ehx, err := bdc.Disk.Encryption.Get()
if err != nil {
return nil, "", fmt.Errorf("Loading encryption key: %w", err)
return nil, fmt.Errorf("Loading encryption key: %w", err)
}
if !(len(ehx) == 16 || len(ehx) == 24 || len(ehx) == 32) {
return nil, "", fmt.Errorf("Encryption key must be 16/24/32 bytes long, got %d", len(ehx))
return nil, fmt.Errorf("Encryption key must be 16/24/32 bytes long, got %d", len(ehx))
}
opts.EncryptionKey = ehx
}
} else if bdc.Type == "Memory" {
opts = badger.DefaultOptions("").WithInMemory(true)
} else if bdc.Type == "Advanced" {
if bdc.Advanced.BadgerResettableOptions == nil {
return nil, errors.New("Options not provided")
}
opts = badger.Options(*bdc.Advanced.BadgerResettableOptions)
// Reinstate default logger that we wiped out
tmpOpts := badger.DefaultOptions("")
opts.Logger = tmpOpts.Logger
}
db, err := badger.Open(opts)
if err != nil {
return nil, "", err
return nil, err
}
return &badgerLoadedDatabase{db: db}, filepath.Base(string(bdc.Disk.Directory)), nil
} else { // memory
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
if err != nil {
return nil, "", err
}
return &badgerLoadedDatabase{db: db}, `:memory:`, nil // SQLite-style naming
}
return &badgerLoadedDatabase{db: db}, nil
}

View File

@@ -53,7 +53,7 @@ func (ld *bitcaskLdb) RenderForNav(f *tableState, bucketPath []string) error {
}
func (n *bitcaskLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return kvstore_ApplyChanges(
return ApplyChanges_binColumn(
f,
func(k, v []byte) error { return n.db.Put(bitcask.Key(k), bitcask.Value(v)) },
func(k []byte) error { return n.db.Delete(bitcask.Key(k)) },
@@ -98,7 +98,7 @@ func (c *bitcaskDBConnection) Reset() {
c.AutoRecovery = true
}
func (c *bitcaskDBConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (c *bitcaskDBConnection) Connect(ctx context.Context) (loadedDatabase, error) {
db, err := bitcask.Open(
string(c.Directory),
@@ -106,8 +106,14 @@ func (c *bitcaskDBConnection) Connect(ctx context.Context) (loadedDatabase, stri
bitcask.WithAutoRecovery(c.AutoRecovery),
)
if err != nil {
return nil, "", err
return nil, err
}
return &bitcaskLdb{db: db}, filepath.Base(string(c.Directory)), nil
return &bitcaskLdb{db: db}, nil
}
func (c *bitcaskDBConnection) String() string {
return filepath.Base(string(c.Directory))
}
var _ DBConnector = &bitcaskDBConnection{} // interface assertion

View File

@@ -21,30 +21,56 @@ type boltLoadedDatabase struct {
db *bbolt.DB
}
type boltAdvancedOptions struct {
bbolt.Options
}
func (bao *boltAdvancedOptions) Reset() {
bao.Options = *bbolt.DefaultOptions
// Interfaces not JSON marshallable
bao.OpenFile = nil
bao.Logger = nil
}
func (bao *boltAdvancedOptions) String() string {
return "Configured" // Override bbolt.Options.String() for autoconfig
}
type boltConfig struct {
Path autoconfig.ExistingFile `yfilter:"Bolt database (*.db);;All files (*)"`
Readonly bool
AdvancedOptions *boltAdvancedOptions `json:",omitempty"`
}
func (bc *boltConfig) String() string { // n.b. only used for default names in connection manager
return filepath.Base(string(bc.Path))
var _ DBConnector = &boltConfig{} // interface assertion
func (bc *boltConfig) String() string {
ret := filepath.Base(string(bc.Path))
if bc.Readonly {
ret += " (read-only)"
}
return ret
}
func (bc *boltConfig) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (bc *boltConfig) DetailedString() string {
return string(bc.Path)
}
func (bc *boltConfig) Connect(ctx context.Context) (loadedDatabase, error) {
opts := bbolt.Options{
Timeout: 1 * time.Second,
ReadOnly: bc.Readonly,
}
if bc.AdvancedOptions != nil {
// Use them instead
// Q? fixup OpenFile/Logger?
opts = bc.AdvancedOptions.Options
}
db, err := bbolt.Open(string(bc.Path), 0644, &opts)
if err != nil {
return nil, "", fmt.Errorf("Failed to load database '%s': %w", bc.Path, err)
}
displayName := filepath.Base(string(bc.Path))
if bc.Readonly {
displayName += " (read-only)"
return nil, fmt.Errorf("Failed to load database '%s': %w", bc.Path, err)
}
ld := &boltLoadedDatabase{
@@ -52,7 +78,7 @@ func (bc *boltConfig) Connect(ctx context.Context) (loadedDatabase, string, erro
db: db,
}
return ld, displayName, nil
return ld, nil
}
func (ld *boltLoadedDatabase) DriverName() string {
@@ -107,10 +133,10 @@ func (ld *boltLoadedDatabase) RenderForNav(f *tableState, bucketPath []string) e
return nil
}
// kvstore_ApplyChanges is a helper function to apply edits to K/V stores that
// ApplyChanges_binColumn is a helper function to apply edits to K/V stores that
// can use a common abstraction.
// It always uses the "popupData" type i.e. []byte.
func kvstore_ApplyChanges(f *tableState, Put func(k, v []byte) error, Delete func(k []byte) error) error {
// It always uses the "binColumn" type i.e. []byte.
func ApplyChanges_binColumn(f *tableState, Put func(k, v []byte) error, Delete func(k []byte) error) error {
// Columns are two binColumn
keyCol := f.columns[0].(*binColumn)
@@ -174,7 +200,7 @@ func (n *boltLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string) er
// Get current bucket handle
b := boltTargetBucket(tx, bucketPath)
return kvstore_ApplyChanges(f, b.Put, b.Delete)
return ApplyChanges_binColumn(f, b.Put, b.Delete)
})
}

View File

@@ -32,7 +32,7 @@ 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
// That would stop us from using ApplyChanges_binColumn that only works with
// []byte data, so, fake []byte casts ourselves
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
@@ -54,7 +54,7 @@ func (ld *buntLdb) RenderForNav(f *tableState, bucketPath []string) error {
func (n *buntLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return n.db.Update(func(tx *buntdb.Tx) error {
return kvstore_ApplyChanges(
return ApplyChanges_binColumn(
f,
func(k, v []byte) error {
_, _, err := tx.Set(string(k), string(v), nil)
@@ -91,7 +91,7 @@ var _ editableLoadedDatabase = &buntLdb{} // interface assertion
//
type buntDBConnection struct {
type BuntDBLocation struct {
Type autoconfig.OneOf
Disk *struct {
@@ -100,7 +100,37 @@ type buntDBConnection struct {
Memory *struct{} `json:",omitempty"`
}
func (ldc *buntDBConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
type buntDBAdvancedOptions struct {
buntdb.Config
}
func (bao *buntDBAdvancedOptions) Reset() {
// buntdb does not expose the default configuration, it's only set in the
// DB .Open() constructor
// Extract the defaults out from a temporary `:memory:` database
if memDb, err := buntdb.Open(`:memory:`); err == nil {
defer memDb.Close()
_ = memDb.ReadConfig(&bao.Config)
}
}
type buntDBConnection struct {
BuntDBLocation
AdvancedOptions *buntDBAdvancedOptions `json:",omitempty"`
}
var _ DBConnector = &buntDBConnection{} // interface assertion
func (ldc *buntDBConnection) String() string {
if ldc.Disk != nil {
return filepath.Base(string(ldc.Disk.File))
} else {
return `:memory:`
}
}
func (ldc *buntDBConnection) Connect(ctx context.Context) (loadedDatabase, error) {
var path string
if ldc.Disk != nil {
@@ -111,8 +141,16 @@ func (ldc *buntDBConnection) Connect(ctx context.Context) (loadedDatabase, strin
db, err := buntdb.Open(path)
if err != nil {
return nil, "", err
return nil, err
}
return &buntLdb{db: db}, filepath.Base(path), nil
if ldc.AdvancedOptions != nil {
err = db.SetConfig(ldc.AdvancedOptions.Config)
if err != nil {
_ = db.Close()
return nil, err
}
}
return &buntLdb{db: db}, nil
}

View File

@@ -99,23 +99,29 @@ type debconfConnection struct {
Database autoconfig.ExistingFile `yfilter:"Debconf database (*.dat);;All files (*)"`
}
var _ DBConnector = &debconfConnection{} // interface assertion
func (dc *debconfConnection) Reset() {
if runtime.GOOS == "linux" {
dc.Database = "/var/cache/debconf/config.dat" // Prefill default path
}
}
func (dc *debconfConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (dc *debconfConnection) String() string {
return filepath.Base(string(dc.Database))
}
func (dc *debconfConnection) Connect(ctx context.Context) (loadedDatabase, error) {
fh, err := os.OpenFile(string(dc.Database), os.O_RDONLY, 0400)
if err != nil {
return nil, "", err
return nil, err
}
defer fh.Close()
db, err := debconf.Parse(fh)
if err != nil {
return nil, "", err
return nil, err
}
return &debconfLoadedDatabase{db: db}, filepath.Base(string(dc.Database)), nil
return &debconfLoadedDatabase{db: db}, nil
}

View File

@@ -51,11 +51,17 @@ var _ loadedDatabase = &evLdb{} // interface assertion
type evLdbConnection struct{}
func (dc *evLdbConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
mods, ok := debug.ReadBuildInfo()
if !ok {
return nil, "", errors.New("Missing build info")
var _ DBConnector = &evLdbConnection{} // interface assertion
func (dc *evLdbConnection) String() string {
return APPNAME
}
return &evLdb{mods: mods}, APPNAME, nil
func (dc *evLdbConnection) Connect(ctx context.Context) (loadedDatabase, error) {
mods, ok := debug.ReadBuildInfo()
if !ok {
return nil, errors.New("Missing build info")
}
return &evLdb{mods: mods}, nil
}

319
db_etcd.go Normal file
View File

@@ -0,0 +1,319 @@
package main
import (
"context"
"fmt"
"strings"
"time"
"github.com/mappu/autoconfig"
qt "github.com/mappu/miqt/qt6"
etcd2 "go.etcd.io/etcd/client/v2"
etcd3 "go.etcd.io/etcd/client/v3"
)
///////////////////////////
// Client v3
///////////////////////////
type etcd3Ldb struct {
cl *etcd3.Client
}
func (ld *etcd3Ldb) DriverName() string {
return "etcd v3"
}
func (ld *etcd3Ldb) Properties(bucketPath []string) (string, error) {
return "", nil // No properties
}
func (ld *etcd3Ldb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
ctx := context.TODO()
resp, err := ld.cl.Get(ctx, "", etcd3.WithPrefix())
if err != nil {
return err
}
for _, kv := range resp.Kvs {
// Strange - reading data, you get it as a []byte, but setting it, you use strings
f.AddRow_PK_Data(kv.Key, kv.Key, kv.Value)
}
f.Ready()
return nil
}
func (n *etcd3Ldb) ApplyChanges(f *tableState, bucketPath []string) error {
ctx := context.TODO()
// TODO use a transaction
put := func(k, v []byte) error {
_, err := n.cl.Put(ctx, string(k), string(v))
return err
}
del := func(k []byte) error {
_, err := n.cl.Delete(ctx, string(k))
return err
}
return ApplyChanges_binColumn(f, put, del)
}
func (ld *etcd3Ldb) NavChildren(bucketPath []string) ([]string, error) {
// TODO: auth, members, ...
return []string{}, nil // No children
}
func (ld *etcd3Ldb) NavContext(bucketPath []string) ([]contextAction, error) {
return nil, nil // no actions
}
func (ld *etcd3Ldb) Close() {
_ = ld.cl.Close()
}
var _ loadedDatabase = &etcd3Ldb{} // interface assertion
var _ editableLoadedDatabase = &etcd3Ldb{} // interface assertion
///////////////////////////
// Client v2
///////////////////////////
type etcd2Ldb struct {
cl etcd2.Client // interface, by value
}
func (ld *etcd2Ldb) DriverName() string {
return "etcd v2"
}
func (ld *etcd2Ldb) Properties(bucketPath []string) (string, error) {
return "", nil // No properties
}
// etcd2_dirPath always has a leading + trailing `/` character.
func etcd2_dirPath(bucketPath []string) string {
if len(bucketPath) == 0 {
return `/`
}
return `/` + strings.Join(bucketPath, `/`) + `/`
}
func (ld *etcd2Ldb) RenderForNav(f *tableState, bucketPath []string) error {
// Load data
// Etcd v2 always uses string types, not []byte types
// However we use []byte columns anyway to get access to ApplyChanges_binColumn
f.SetupColumns([]TableColumn{&binColumn{}, &binColumn{}}, []string{"Key", "Value"})
// In etcd v2, the bucketPath should always turn into something with a final /
dirPath := etcd2_dirPath(bucketPath)
ctx := context.TODO()
resp, err := etcd2.NewKeysAPI(ld.cl).Get(ctx, dirPath, nil) // TODO any way to request only non-directories here?
if err != nil {
return err
}
if !resp.Node.Dir {
return fmt.Errorf("Path %q expected directory, got data", dirPath)
}
for _, child := range resp.Node.Nodes {
if child.Dir {
continue // Only looking for data here, not directories
}
if !strings.HasPrefix(child.Key, dirPath) {
return fmt.Errorf("Requested contents of %q but entry %q is missing expected prefix", dirPath, child.Key)
}
realKey := child.Key[len(dirPath):]
f.AddRow_PK_Data([]byte(realKey), []byte(realKey), []byte(child.Value))
}
f.Ready()
return nil
}
func (n *etcd2Ldb) ApplyChanges(f *tableState, bucketPath []string) error {
ctx := context.TODO()
ka := etcd2.NewKeysAPI(n.cl)
dirPath := etcd2_dirPath(bucketPath) // Has trailing slash
// TODO use a transaction
put := func(k, v []byte) error {
_, err := ka.Set(ctx, dirPath+string(k), string(v), nil)
return err
}
del := func(k []byte) error {
_, err := ka.Delete(ctx, dirPath+string(k), nil)
return err
}
return ApplyChanges_binColumn(f, put, del)
}
func (ld *etcd2Ldb) NavChildren(bucketPath []string) ([]string, error) {
// In etcd v2, the bucketPath should always turn into something with a final /
dirPath := etcd2_dirPath(bucketPath) // Has trailing slash
ctx := context.TODO()
resp, err := etcd2.NewKeysAPI(ld.cl).Get(ctx, dirPath, nil) // TODO any way to request only directories here?
if err != nil {
return nil, err
}
if !resp.Node.Dir {
return nil, fmt.Errorf("Path %q expected directory, got data", dirPath)
}
var ret []string
for _, child := range resp.Node.Nodes {
if !child.Dir {
continue // Only looking for data here, not directories
}
if !strings.HasPrefix(child.Key, dirPath) {
return nil, fmt.Errorf("Requested contents of %q but entry %q is missing expected prefix", dirPath, child.Key)
}
realKey := child.Key[len(dirPath):]
ret = append(ret, realKey)
}
return ret, nil
}
func (ld *etcd2Ldb) createDirectory(sender *qt.QTreeWidgetItem, bucketPath []string) error {
dirName := qt.QInputDialog_GetText(sender.TreeWidget().QWidget, APPNAME, "Enter a name for the new directory:")
if dirName == "" {
return nil // cancel
}
ctx := context.TODO()
ka := etcd2.NewKeysAPI(ld.cl)
newDirKey := etcd2_dirPath(bucketPath) + `/` + dirName
_, err := ka.Set(ctx, newDirKey, "", &etcd2.SetOptions{Dir: true})
return err
// TODO move the UI to select the newly created bucket
}
func (ld *etcd2Ldb) deleteDirectory(sender *qt.QTreeWidgetItem, bucketPath []string) error {
dirKey := etcd2_dirPath(bucketPath)
if !vcl_confirm_dialog(sender.TreeWidget().QWidget, fmt.Sprintf("Are you sure you want to delete the bucket %q and all its contents?", dirKey)) {
return nil // cancelled
}
ctx := context.TODO()
ka := etcd2.NewKeysAPI(ld.cl)
_, err := ka.Delete(ctx, dirKey, &etcd2.DeleteOptions{Dir: true, Recursive: true})
return err
// TODO The app tries to refresh the non-existent bucket which results in an error
// Need a way to move the current selection up to the parent level
}
func (ld *etcd2Ldb) NavContext(bucketPath []string) ([]contextAction, error) {
ret := []contextAction{
contextAction{"Create directory...", ld.createDirectory},
}
if len(bucketPath) > 0 {
ret = append(ret, contextAction{"Delete directory...", ld.deleteDirectory})
}
return ret, nil
}
func (ld *etcd2Ldb) Close() {
// v2 has nothing to close in the client
}
var _ loadedDatabase = &etcd2Ldb{} // interface assertion
var _ editableLoadedDatabase = &etcd2Ldb{} // interface assertion
///////////////////////////
// Connection
///////////////////////////
type etcdConn struct {
Endpoints []string
Username string
Password autoconfig.Password
H1 autoconfig.Header `ylabel:"Protocol version:" json:",omitempty"`
Protocol struct {
Type autoconfig.OneOf
V3 *struct{} `ylabel:"v3" json:",omitempty"`
V2 *struct{} `ylabel:"v2" json:",omitempty"`
}
}
var _ DBConnector = &etcdConn{} // interface assertion
func (c *etcdConn) String() string {
if len(c.Endpoints) == 1 {
return c.Endpoints[0]
} else if len(c.Endpoints) > 1 {
return fmt.Sprintf("%d endpoints", c.Endpoints)
} else {
return ""
}
}
func (c *etcdConn) Connect(ctx context.Context) (loadedDatabase, error) {
if c.Protocol.V3 != nil {
cfg := etcd3.Config{
Endpoints: c.Endpoints,
Username: c.Username,
Password: string(c.Password),
DialTimeout: 5 * time.Second,
// TODO SSH tunnel
}
cl, err := etcd3.New(cfg)
if err != nil {
return nil, err
}
return &etcd3Ldb{cl: cl}, nil
} else if c.Protocol.V2 != nil {
cfg := etcd2.Config{
Endpoints: c.Endpoints,
Username: c.Username,
Password: string(c.Password),
// TODO SSH tunnel
}
cl, err := etcd2.New(cfg)
if err != nil {
return nil, err
}
return &etcd2Ldb{cl: cl}, nil
} else {
return nil, fmt.Errorf("Unknown protocol version %q", c.Protocol.Type)
}
}

View File

@@ -54,7 +54,7 @@ func (n *leveldbLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string)
return fmt.Errorf("OpenTransaction: %w", err)
}
err = kvstore_ApplyChanges(
err = ApplyChanges_binColumn(
f,
func(k, v []byte) error { return txn.Put(k, v, nil) },
func(k []byte) error { return txn.Delete(k, nil) },
@@ -89,14 +89,24 @@ type leveldbConnection struct {
Readonly bool
}
func (pdc *leveldbConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &leveldbConnection{} // interface assertion
func (pdc *leveldbConnection) String() string {
ret := filepath.Base(string(pdc.Directory))
if pdc.Readonly {
ret += " (read-only)"
}
return ret
}
func (pdc *leveldbConnection) Connect(ctx context.Context) (loadedDatabase, error) {
var o opt.Options
o.ReadOnly = pdc.Readonly
db, err := leveldb.OpenFile(string(pdc.Directory), &o)
if err != nil {
return nil, "", err
return nil, err
}
return &leveldbLoadedDatabase{db: db}, filepath.Base(string(pdc.Directory)), nil
return &leveldbLoadedDatabase{db: db}, nil
}

View File

@@ -107,7 +107,7 @@ func (ld *lmdbDatabase) ApplyChanges(f *tableState, bucketPath []string) error {
return err
}
return kvstore_ApplyChanges(
return ApplyChanges_binColumn(
f,
func(k, v []byte) error { return txn.Put(dbi, k, v, 0) },
func(k []byte) error { return txn.Del(dbi, k, nil) },
@@ -249,11 +249,22 @@ type lmdbConnection struct {
Readonly bool
}
func (pdc *lmdbConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &lmdbConnection{} // interface assertion
func (pdc *lmdbConnection) String() string {
if pdc.Storage.Directory != nil {
return filepath.Base(string(*pdc.Storage.Directory))
} else if pdc.Storage.File != nil {
return filepath.Base(string(pdc.Storage.File.Path))
}
return "" // unreachable
}
func (pdc *lmdbConnection) Connect(ctx context.Context) (loadedDatabase, error) {
env, err := lmdb.NewEnv()
if err != nil {
return nil, "", err
return nil, err
}
var openPath string
@@ -277,8 +288,8 @@ func (pdc *lmdbConnection) Connect(ctx context.Context) (loadedDatabase, string,
err = env.Open(openPath, flags, 0644)
if err != nil {
_ = env.Close()
return nil, "", err
return nil, err
}
return &lmdbDatabase{db: env, isMulti: isMulti}, filepath.Base(openPath), nil
return &lmdbDatabase{db: env, isMulti: isMulti}, nil
}

View File

@@ -45,7 +45,7 @@ func (ld *lotusLdb) RenderForNav(f *tableState, bucketPath []string) error {
func (n *lotusLdb) ApplyChanges(f *tableState, bucketPath []string) error {
txn := n.db.NewBatch(lotusdb.DefaultBatchOptions)
err := kvstore_ApplyChanges(f, txn.Put, txn.Delete)
err := ApplyChanges_binColumn(f, txn.Put, txn.Delete)
if err != nil {
return err
}
@@ -74,15 +74,21 @@ type lotusDBConnection struct {
Directory autoconfig.ExistingDirectory
}
func (ldc *lotusDBConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &lotusDBConnection{} // interface assertion
func (ldc *lotusDBConnection) String() string {
return filepath.Base(string(ldc.Directory))
}
func (ldc *lotusDBConnection) Connect(ctx context.Context) (loadedDatabase, error) {
opts := lotusdb.DefaultOptions // copy
opts.DirPath = string(ldc.Directory)
db, err := lotusdb.Open(opts)
if err != nil {
return nil, "", err
return nil, err
}
return &lotusLdb{db: db}, filepath.Base(string(ldc.Directory)), nil
return &lotusLdb{db: db}, nil
}

View File

@@ -293,12 +293,18 @@ type mongoConnection struct {
SSH_Tunnel *SSHTunnel
}
var _ DBConnector = &mongoConnection{} // interface assertion
func (moc *mongoConnection) Reset() {
moc.Conn.Mode = "Connection_String"
moc.Conn.Connection_String = address_of("mongodb://localhost:27017")
}
func (moc *mongoConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (moc *mongoConnection) String() string {
return "MongoDB" // TODO could be improved
}
func (moc *mongoConnection) Connect(ctx context.Context) (loadedDatabase, error) {
ctx, _ = context.WithTimeout(ctx, 5*time.Second) // shadow parent ctx
@@ -312,7 +318,7 @@ func (moc *mongoConnection) Connect(ctx context.Context) (loadedDatabase, string
if moc.SSH_Tunnel != nil {
sshc, err := moc.SSH_Tunnel.Open(ctx)
if err != nil {
return nil, "", err
return nil, err
}
opts.Dialer = sshc // interface implements DialContext()
@@ -326,7 +332,7 @@ func (moc *mongoConnection) Connect(ctx context.Context) (loadedDatabase, string
client, err := mongo.Connect(opts)
if err != nil {
return nil, "", err
return nil, err
}
ret.client = client
@@ -335,14 +341,14 @@ func (moc *mongoConnection) Connect(ctx context.Context) (loadedDatabase, string
err = client.Ping(ctx, readpref.Primary())
if err != nil {
return nil, "", err
return nil, err
}
// We should be able to ListDatabases - there may be an authentication error
_, err = client.ListDatabaseNames(ctx, bson.D{})
if err != nil {
return nil, "", err
return nil, err
}
return &ret, "MongoDB", nil
return &ret, nil
}

View File

@@ -57,7 +57,7 @@ func (n *pebbleLoadedDatabase) ApplyChanges(f *tableState, bucketPath []string)
txn := n.db.NewBatch()
err := kvstore_ApplyChanges(
err := ApplyChanges_binColumn(
f,
func(k, v []byte) error { return txn.Set(k, v, nil) },
func(k []byte) error { return txn.Delete(k, nil) },
@@ -95,7 +95,17 @@ type pebbleConnection struct {
Memory *struct{} `json:",omitempty"`
}
func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &pebbleConnection{} // interface assertion
func (pdc *pebbleConnection) String() string {
if pdc.Disk != nil {
return filepath.Base(string(pdc.Disk.Directory))
} else {
return `:memory:` // SQLite-style naming
}
}
func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, error) {
opts := (&pebble.Options{}).EnsureDefaults()
if pdc.Disk != nil {
@@ -103,18 +113,18 @@ func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, strin
db, err := pebble.Open(string(pdc.Disk.Directory), opts)
if err != nil {
return nil, "", err
return nil, err
}
return &pebbleLoadedDatabase{db: db}, filepath.Base(string(pdc.Disk.Directory)), nil
return &pebbleLoadedDatabase{db: db}, nil
} else {
// Memory != nil
db, err := pebble.Open("", &pebble.Options{FS: vfs.NewMem()})
if err != nil {
return nil, "", err
return nil, err
}
return &pebbleLoadedDatabase{db: db}, `:memory:`, nil // SQLite-style naming
return &pebbleLoadedDatabase{db: db}, nil
}
}

View File

@@ -47,7 +47,7 @@ func (ld *pogrebLdb) RenderForNav(f *tableState, bucketPath []string) error {
}
func (n *pogrebLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return kvstore_ApplyChanges(f, n.db.Put, n.db.Delete)
return ApplyChanges_binColumn(f, n.db.Put, n.db.Delete)
}
func (ld *pogrebLdb) NavChildren(bucketPath []string) ([]string, error) {
@@ -85,11 +85,17 @@ 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
var _ DBConnector = &pogrebConn{} // interface assertion
func (c *pogrebConn) String() string {
return filepath.Base(string(c.Directory))
}
return &pogrebLdb{db: db}, filepath.Base(string(c.Directory)), nil
func (c *pogrebConn) Connect(ctx context.Context) (loadedDatabase, error) {
db, err := pogreb.Open(string(c.Directory), nil)
if err != nil {
return nil, err
}
return &pogrebLdb{db: db}, nil
}

View File

@@ -19,11 +19,17 @@ type redisConnectionOptions struct {
SSH_Tunnel *SSHTunnel
}
var _ DBConnector = &redisConnectionOptions{} // interface assertion
func (config *redisConnectionOptions) String() string {
return config.Address.Address
}
func (config *redisConnectionOptions) Reset() {
config.Address.Port = 6379
}
func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDatabase, error) {
ld := &redisLoadedDatabase{
currentDb: 0,
@@ -40,7 +46,7 @@ func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDataba
if config.SSH_Tunnel != nil {
sshc, err := config.SSH_Tunnel.Open(ctx)
if err != nil {
return nil, "", err
return nil, err
}
// When redis wants to open a tcp conn, don't dial directly, dial via the SSH tunnel
@@ -62,7 +68,7 @@ func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDataba
// Make an INFO request (mandatory)
info, err := ld.db.InfoMap(ctx).Result()
if err != nil {
return nil, "", fmt.Errorf("During INFO: %w", err)
return nil, fmt.Errorf("During INFO: %w", err)
}
if serverInfo, ok := info["Server"]; ok {
@@ -78,15 +84,13 @@ func (config *redisConnectionOptions) Connect(ctx context.Context) (loadedDataba
// Got a result. Must parse it
m, err := strconv.ParseInt(maxDatabases["databases"], 10, 64)
if err != nil {
return nil, "", fmt.Errorf("During CONFIG GET databases: %v", err)
return nil, fmt.Errorf("During CONFIG GET databases: %v", err)
}
ld.maxDb = int(m)
}
displayName := config.Address.Address
return ld, displayName, nil
return ld, nil
}
type redisLoadedDatabase struct {

View File

@@ -37,7 +37,7 @@ func (ld *roseLdb) RenderForNav(f *tableState, bucketPath []string) error {
}
func (n *roseLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return kvstore_ApplyChanges(f, n.db.Put, n.db.Delete)
return ApplyChanges_binColumn(f, n.db.Put, n.db.Delete)
}
func (ld *roseLdb) NavChildren(bucketPath []string) ([]string, error) {
@@ -61,14 +61,20 @@ type roseDBConn struct {
Directory autoconfig.ExistingDirectory
}
func (c *roseDBConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &roseDBConn{} // interface assertion
func (c *roseDBConn) String() string {
return filepath.Base(string(c.Directory))
}
func (c *roseDBConn) Connect(ctx context.Context) (loadedDatabase, error) {
options := rosedb.DefaultOptions // copy
options.DirPath = string(c.Directory)
db, err := rosedb.Open(options)
if err != nil {
return nil, "", err
return nil, err
}
return &roseLdb{db: db}, filepath.Base(string(c.Directory)), nil
return &roseLdb{db: db}, nil
}

View File

@@ -173,17 +173,23 @@ var _ loadedDatabase = &secretServiceDb{} // interface assertion
type secretServiceConnection struct {
}
func (ssc *secretServiceConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &secretServiceConnection{} // interface assertion
func (ssc *secretServiceConnection) String() string {
return "dbus://SessionBus/org.freedesktop.secrets"
}
func (ssc *secretServiceConnection) Connect(ctx context.Context) (loadedDatabase, error) {
svc, err := secretservice.NewSecretService()
if err != nil {
return nil, "", err
return nil, err
}
session, err := svc.OpenSession()
if err != nil {
return nil, "", err
return nil, err
}
return &secretServiceDb{svc: svc, session: session}, "dbus://SessionBus/org.freedesktop.secrets", nil
return &secretServiceDb{svc: svc, session: session}, nil
}

View File

@@ -14,6 +14,12 @@ type secretServiceConnection struct {
H1 autoconfig.Header `ylabel:"Not supported on this operating system"`
}
func (ssc *secretServiceConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &secretServiceConnection{} // interface assertion
func (ssc *secretServiceConnection) String() string {
return ""
}
func (ssc *secretServiceConnection) Connect(ctx context.Context) (loadedDatabase, error) {
return nil, "", errors.New("Not supported on this operating system")
}

View File

@@ -191,7 +191,9 @@ func populateRows(rr *sql.Rows, dest *tableState, firstColumnIsExtraRowID bool)
// Resetup table
if firstColumnIsExtraRowID {
if firstColumnIsExtraRowID && len(cNames) > 0 {
// Real SQLite driver: gives us back names even if 0 rows
// sqliteclidriver: Gives back no names if there were 0 rows
cNames = cNames[1:]
}
@@ -354,7 +356,7 @@ func (ld *sqliteLoadedDatabase) NavChildren(bucketPath []string) ([]string, erro
// 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;`)
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
}
@@ -452,7 +454,20 @@ type sqliteConnection struct {
} `json:",omitempty"`
}
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &sqliteConnection{} // interface assertion
func (sc *sqliteConnection) String() string {
if sc.Disk != nil {
return filepath.Base(string(sc.Disk.Database))
} else if sc.Memory != nil {
return `:memory:`
} else if sc.SSH != nil {
return filepath.Base(string(sc.SSH.Database)) + " (SSH)"
}
return "" // unreachable
}
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, error) {
if sc.Disk != nil {
driver := "sqlite3"
if sc.Disk.CliDriver {
@@ -461,34 +476,34 @@ func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string
db, err := sql.Open(driver, string(sc.Disk.Database))
if err != nil {
return nil, "", err
return nil, err
}
return &sqliteLoadedDatabase{db: db}, filepath.Base(string(sc.Disk.Database)), nil
return &sqliteLoadedDatabase{db: db}, nil
} else if sc.Memory != nil { // memory
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
return nil, "", err
return nil, err
}
return &sqliteLoadedDatabase{db: db}, ":memory:", nil
return &sqliteLoadedDatabase{db: db}, nil
} else if sc.SSH != nil {
if sc.SSH.SSHServer == nil {
return nil, "", errors.New("Invalid configuration")
return nil, errors.New("Invalid configuration")
}
cl, err := sc.SSH.SSHServer.Open(ctx)
if err != nil {
return nil, "", err
return nil, err
}
db := sqliteclidriver.OpenSSH(cl, sc.SSH.Database)
return &sqliteLoadedDatabase{db: db}, "SSH[" + filepath.Base(string(sc.SSH.Database)) + "]", nil
return &sqliteLoadedDatabase{db: db}, nil
} else {
return nil, "", errors.New("Invalid configuration")
return nil, errors.New("Invalid configuration")
}
}

View File

@@ -121,6 +121,12 @@ type sshAgentConn struct {
TCP *autoconfig.AddressPort `json:",omitempty"`
}
var _ DBConnector = &sshAgentConn{} // interface assertion
func (c *sshAgentConn) String() string {
return "SSH Agent" // TODO could be improved
}
func (c *sshAgentConn) Reset() {
if sshAuthSock := os.Getenv("SSH_AUTH_SOCK"); sshAuthSock != "" {
@@ -169,11 +175,11 @@ func (c *sshAgentConn) getAgent() (agent.ExtendedAgent, error) {
}
}
func (c *sshAgentConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
func (c *sshAgentConn) Connect(ctx context.Context) (loadedDatabase, error) {
agent, err := c.getAgent()
if err != nil {
return nil, "", err
return nil, err
}
return &sshAgentLdb{conn: agent}, "SSH Agent", nil
return &sshAgentLdb{conn: agent}, nil
}

View File

@@ -62,7 +62,7 @@ func (ld *starskeyLdb) RenderForNav(f *tableState, bucketPath []string) error {
}
func (n *starskeyLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return kvstore_ApplyChanges(f, n.db.Put, n.db.Delete)
return ApplyChanges_binColumn(f, n.db.Put, n.db.Delete)
}
func (ld *starskeyLdb) NavChildren(bucketPath []string) ([]string, error) {
@@ -87,7 +87,13 @@ type starskeyConnection struct {
Compression autoconfig.EnumList `yenum:"No compression;;Snappy;;S2"`
}
func (pdc *starskeyConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &starskeyConnection{} // interface assertion
func (pdc *starskeyConnection) String() string {
return filepath.Base(string(pdc.Directory))
}
func (pdc *starskeyConnection) Connect(ctx context.Context) (loadedDatabase, error) {
cfg := starskey.Config{
Permission: 0755,
@@ -108,8 +114,8 @@ func (pdc *starskeyConnection) Connect(ctx context.Context) (loadedDatabase, str
db, err := starskey.Open(&cfg)
if err != nil {
return nil, "", err
return nil, err
}
return &starskeyLdb{db: db}, filepath.Base(string(pdc.Directory)), nil
return &starskeyLdb{db: db}, nil
}

View File

@@ -93,7 +93,7 @@ func (n *voidLdb) ApplyChanges(f *tableState, bucketPath []string) error {
return err
}
return kvstore_ApplyChanges(
return ApplyChanges_binColumn(
f,
cur.Put,
func(k []byte) error {
@@ -230,7 +230,13 @@ type voidDBConn struct {
MultiKeyspace bool `ylabel:"Use multiple keyspaces"`
}
func (c *voidDBConn) Connect(ctx context.Context) (loadedDatabase, string, error) {
var _ DBConnector = &voidDBConn{} // interface assertion
func (c *voidDBConn) String() string {
return filepath.Base(string(c.Path))
}
func (c *voidDBConn) Connect(ctx context.Context) (loadedDatabase, error) {
const capacity = 1 << 40 // 1 TiB max size before returning ErrorFull
@@ -241,8 +247,8 @@ func (c *voidDBConn) Connect(ctx context.Context) (loadedDatabase, string, error
db, err := openFunc(string(c.Path), capacity)
if err != nil {
return nil, "", err
return nil, err
}
return &voidLdb{db: db, multiKeyspace: c.MultiKeyspace}, filepath.Base(string(c.Path)), nil
return &voidLdb{db: db, multiKeyspace: c.MultiKeyspace}, nil
}

View File

@@ -14,6 +14,12 @@ 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")
var _ DBConnector = &voidDBConn{} // interface assertion
func (ssc *voidDBConn) String() {
return ""
}
func (ssc *voidDBConn) Connect(ctx context.Context) (loadedDatabase, error) {
return nil, errors.New("Not supported on this operating system")
}

View File

@@ -32,6 +32,7 @@
<file>assets/vendor_cockroach.png</file>
<file>assets/vendor_debian.png</file>
<file>assets/vendor_dgraph.png</file>
<file>assets/vendor_etcd.png</file>
<file>assets/vendor_freedesktop.png</file>
<file>assets/vendor_github.png</file>
<file>assets/vendor_leveldb.png</file>

BIN
embed.rcc

Binary file not shown.

26
go.mod
View File

@@ -5,13 +5,14 @@ go 1.24.0
toolchain go1.24.4
require (
github.com/akrylysov/pogreb v0.10.2
github.com/cockroachdb/pebble v1.1.5
github.com/dgraph-io/badger/v4 v4.8.0
github.com/godbus/dbus/v5 v5.2.0
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.5.0
github.com/mappu/autoconfig v0.6.1-0.20260124043120-621a5fcf917e
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
@@ -19,8 +20,12 @@ require (
github.com/starskey-io/starskey v0.1.9
github.com/stretchr/testify v1.11.1
github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/buntdb v1.3.2
github.com/voidDB/voidDB v0.1.18
github.com/zalando/go-keyring v0.2.6
go.etcd.io/bbolt v1.4.3
go.etcd.io/etcd/client/v2 v2.305.26
go.etcd.io/etcd/client/v3 v3.6.7
go.mills.io/bitcask/v2 v2.1.5
go.mongodb.org/mongo-driver/v2 v2.4.1
golang.org/x/crypto v0.46.0
@@ -30,7 +35,6 @@ 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
@@ -39,6 +43,8 @@ require (
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 // indirect
github.com/cockroachdb/redact v1.1.6 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
@@ -49,16 +55,21 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v25.9.23+incompatible // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
github.com/hashicorp/go-immutable-radix/v2 v2.0.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.2 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattetti/filebuffer v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -73,7 +84,6 @@ require (
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
@@ -81,23 +91,29 @@ require (
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
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.etcd.io/etcd/api/v3 v3.6.7 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.6.7 // indirect
go.mongodb.org/mongo-driver v1.17.6 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260122232226-8e98ce8d340d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260122232226-8e98ce8d340d // indirect
google.golang.org/grpc v1.71.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

43
go.sum
View File

@@ -30,6 +30,10 @@ github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb h1:3bCgBvB8PbJVMX1ouCcSIxvsqKPYM7gs72o0zC76n9g=
github.com/cockroachdb/tokenbucket v0.0.0-20250429170803-42689b6311bb/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
@@ -57,6 +61,7 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.2.0 h1:3WexO+U+yg9T70v9FdHr9kCxYlazaAXUhx2VMkbfax8=
github.com/godbus/dbus/v5 v5.2.0/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
@@ -64,6 +69,8 @@ github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14j
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -73,6 +80,7 @@ github.com/google/flatbuffers v25.9.23+incompatible h1:rGZKv+wOb6QPzIdkM2KxhBZCD
github.com/google/flatbuffers v25.9.23+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -80,6 +88,8 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 h1:5ZPtiqj0JL5oKWmcsq4VMaAW5ukBEgSGXEN89zeH1Jo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3/go.mod h1:ndYquD05frm2vACXE1nsccT4oJzjhw2arTS2cpUD1PI=
github.com/hashicorp/go-immutable-radix/v2 v2.0.0 h1:nq9lQ5I71Heg2lRb2/+szuIWKY3Y73d8YKyXyN91WzU=
github.com/hashicorp/go-immutable-radix/v2 v2.0.0/go.mod h1:hgdqLXA4f6NIjRVisM1TJ9aOJVNRqKZj+xDGF6m7PBw=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
@@ -88,6 +98,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -108,12 +120,21 @@ github.com/mappu/autoconfig v0.4.1 h1:ekO7mzN+beFu7VhNfJxNlL/5wkYcP9PAl9VTG4EDxY
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/autoconfig v0.6.0 h1:pv6gFYC3eqnKzthaKzD/X+8tcCM+kiPDFZDSc/xn1b8=
github.com/mappu/autoconfig v0.6.0/go.mod h1:kca6kaYjqOwkZnY9z5YKo0oI/7Bxe2fMIHhYzXwGHEE=
github.com/mappu/autoconfig v0.6.1-0.20260124043120-621a5fcf917e h1:zVsg2l2o75SkbVOxwJXDTgT+dJ/88Wvyd263DEna4Vg=
github.com/mappu/autoconfig v0.6.1-0.20260124043120-621a5fcf917e/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=
github.com/mattetti/filebuffer v1.0.1/go.mod h1:YdMURNDOttIiruleeVr6f56OrMc+MydEnTcXwtkxNVs=
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -164,6 +185,7 @@ github.com/starskey-io/starskey v0.1.9/go.mod h1:qly4ec2C/4Y45jhpL+q4m+Uxzg3mjj0
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
@@ -209,6 +231,14 @@ github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
go.etcd.io/bbolt v1.4.3 h1:dEadXpI6G79deX5prL3QRNP6JB8UxVkqo4UPnHaNXJo=
go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E=
go.etcd.io/etcd/api/v3 v3.6.7 h1:7BNJ2gQmc3DNM+9cRkv7KkGQDayElg8x3X+tFDYS+E0=
go.etcd.io/etcd/api/v3 v3.6.7/go.mod h1:xJ81TLj9hxrYYEDmXTeKURMeY3qEDN24hqe+q7KhbnI=
go.etcd.io/etcd/client/pkg/v3 v3.6.7 h1:vvzgyozz46q+TyeGBuFzVuI53/yd133CHceNb/AhBVs=
go.etcd.io/etcd/client/pkg/v3 v3.6.7/go.mod h1:2IVulJ3FZ/czIGl9T4lMF1uxzrhRahLqe+hSgy+Kh7Q=
go.etcd.io/etcd/client/v2 v2.305.26 h1:oReO+h1y3W/CJJa8axZ/3t9S6jg0I42tNx7AWKIvfCc=
go.etcd.io/etcd/client/v2 v2.305.26/go.mod h1:oni2jI2OMezwmakWDTlZRi6VANemxGx+KIuiQBuRRpQ=
go.etcd.io/etcd/client/v3 v3.6.7 h1:9WqA5RpIBtdMxAy1ukXLAdtg2pAxNqW5NUoO2wQrE6U=
go.etcd.io/etcd/client/v3 v3.6.7/go.mod h1:2XfROY56AXnUqGsvl+6k29wrwsSbEh1lAouQB1vHpeE=
go.mills.io/bitcask/v2 v2.1.5 h1:SKPa0TPasJJZ8rNbLDvV3+lRXvdyQ0mwBobm2RH7J7w=
go.mills.io/bitcask/v2 v2.1.5/go.mod h1:ZQFykoTTCvMwy24lBstZhSRQuleYIB4EzWKSOgEv6+k=
go.mongodb.org/mongo-driver v1.17.6 h1:87JUG1wZfWsr6rIz3ZmpH90rL5tea7O3IHuSwHUpsss=
@@ -225,6 +255,10 @@ go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -286,8 +320,17 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto/googleapis/api v0.0.0-20260122232226-8e98ce8d340d h1:tUKoKfdZnSjTf5LW7xpG4c6SZ3Ozisn5eumcoTuMEN4=
google.golang.org/genproto/googleapis/api v0.0.0-20260122232226-8e98ce8d340d/go.mod h1:p3MLuOwURrGBRoEyFHBT3GjUwaCQVKeNqqWxlcISGdw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260122232226-8e98ce8d340d h1:xXzuihhT3gL/ntduUZwHECzAn57E8dA6l8SOtYWdD8Q=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260122232226-8e98ce8d340d/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI=
google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

111
main.go
View File

@@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"strings"
"github.com/mappu/miqt/qt6/mainthread"
"github.com/mappu/autoconfig"
qt "github.com/mappu/miqt/qt6"
"github.com/mappu/miqt/qt6/mainthread"
)
const (
@@ -20,6 +21,8 @@ const (
type App struct {
ui *MainWindowUi
currentDensity int
contentTbl *tableState
resultsTbl *tableState
@@ -33,6 +36,8 @@ func newApp() *App {
a := &App{}
autoconfig.SetEnumStringOptions(`qstyle`, qt.QStyleFactory_Keys())
a.dbs_next = 0
a.dbs = make(map[int]loadedDatabase, 0)
@@ -55,6 +60,8 @@ func newApp() *App {
a.ui.actionE_xit.OnTriggered(a.OnMnuFileExitClick)
a.ui.action_Appearance.OnTriggered(a.OnMnuAppearance)
a.ui.mnuExecute.OnTriggered(a.OnQueryExecute)
a.ui.mnuDriverVersions.OnTriggered(a.OnMenuHelpVersion)
@@ -117,8 +124,38 @@ func main() {
// no need to change anything here
qt.NewQApplication(os.Args)
app := newApp()
if len(os.Args) > 1 {
switch os.Args[1] {
case "--config-export":
content, err := app.getConnectionManagerContentsJson()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
fmt.Println(string(content))
os.Exit(0)
case "--config-import":
content, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
err = app.saveConnectionManagerContentsJson(content)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
os.Exit(0)
case "--help":
fmt.Println("Usage: " + APPNAME + " [--config-export|--config-import]")
os.Exit(0)
}
}
app.ui.MainWindow.Show()
qt.QApplication_Exec()
@@ -128,6 +165,63 @@ func (f *App) OnMnuFileExitClick() {
f.ui.MainWindow.Close()
}
type appearanceProps struct {
QtStyle autoconfig.EnumString `yenum:"qstyle"`
Density autoconfig.EnumList `yenum:"System Default;;Compact;;Padded"`
AlternatingRowColours bool
}
func (f *App) OnMnuAppearance() {
var opts appearanceProps
// Current style from QApplication_Style().Name() is lowercase, but the
// style list has title-case
// First-character-uppercase-only does not work for Qt6 "Adwaita-Dark" style
// Get the whole list and do a manual case-insensitive match
// Assume it's first-character-uppercase-only
currentStyleName := qt.QApplication_Style().Name()
for _, check := range qt.QStyleFactory_Keys() {
if strings.ToLower(check) == currentStyleName {
currentStyleName = check
break
}
}
opts.QtStyle = autoconfig.EnumString(currentStyleName)
opts.Density = autoconfig.EnumList(f.currentDensity)
opts.AlternatingRowColours = f.contentTbl.tbl.AlternatingRowColors()
autoconfig.OpenDialog(&opts, f.ui.MainWindow.QWidget, "Appearance...", func() {
qt.QApplication_SetStyleWithStyle(string(opts.QtStyle))
vhh := f.contentTbl.tbl.VerticalHeader()
vhh.ResetDefaultSectionSize()
f.contentTbl.tbl.SetStyleSheet("") // Default density
if opts.Density == 0 {
// nothing
} else if opts.Density == 1 {
vhh.SetDefaultSectionSize(0) // vhh.DefaultSectionSize() - 10)
// Default 30, seems to not go below 25
// Breeze: can only reach 29, Windows: can only reach 25, Fusion: can reach 21
} else if opts.Density == 2 {
vhh.SetDefaultSectionSize(vhh.DefaultSectionSize() + 5)
// Setting stylesheet: can only add additional horizontal padding
f.contentTbl.tbl.SetStyleSheet(`QTableView::item { padding: 6px; background: transparent; }`)
}
f.currentDensity = int(opts.Density)
// TODO also apply all customizations to data result pane
f.contentTbl.tbl.SetAlternatingRowColors(opts.AlternatingRowColours)
// TODO persist
})
}
func (f *App) OnMnuHelpHomepage() {
url := qt.NewQUrl3(HOMEPAGE_URL)
ok := qt.QDesktopServices_OpenUrl(url)
@@ -141,13 +235,13 @@ func (f *App) OnMnuHelpHomepage() {
func (f *App) OnMenuHelpVersion() {
connector := evLdbConnection{}
ld, name, err := connector.Connect(context.Background())
ld, err := connector.Connect(context.Background())
if err != nil {
qt.QMessageBox_Warning(f.ui.MainWindow.QWidget, APPNAME, err.Error())
return
}
f.addTopLevelDatabaseConnection(ld, name)
f.addTopLevelDatabaseConnection(ld, connector.String(), "")
}
func (f *App) OnNavContextPopup(pos *qt.QPoint) {
@@ -477,7 +571,6 @@ 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
@@ -620,7 +713,7 @@ func (f *App) NavLoadChildren(item *qt.QTreeWidgetItem, bucketPath []string) err
return nil
}
func (f *App) addTopLevelDatabaseConnection(ld loadedDatabase, displayName string) {
func (f *App) addTopLevelDatabaseConnection(ld loadedDatabase, displayName, tooltip string) {
nav := qt.NewQTreeWidgetItem()
nav.SetText(0, displayName)
@@ -640,6 +733,10 @@ func (f *App) addTopLevelDatabaseConnection(ld loadedDatabase, displayName strin
nav.SetData(0, LoadedDatabaseIdRole, qt.NewQVariant4(ldID))
nav.SetData(0, BucketPathBSliceRole, qt.NewQVariant12(emptyData))
if tooltip != "" && tooltip != displayName {
nav.SetToolTip(0, tooltip)
}
f.ui.Buckets.AddTopLevelItem(nav)
// For a newly added DB, switch us back to the Properties pane

View File

@@ -33,6 +33,7 @@ type MainWindowUi struct {
menu_Help *qt.QMenu
menu_Data *qt.QMenu
menu_Tools *qt.QMenu
menu_View *qt.QMenu
statusbar *qt.QStatusBar
tbConnect *qt.QToolBar
tbData *qt.QToolBar
@@ -49,7 +50,7 @@ type MainWindowUi struct {
actionApply_changes *qt.QAction
actionConnectionManager *qt.QAction
actionCreate_Bolt_database_from_zip *qt.QAction
actionSet_cell_to_null *qt.QAction
action_Appearance *qt.QAction
}
// NewMainWindowUi creates all Qt widget classes for MainWindow.
@@ -149,14 +150,10 @@ func NewMainWindowUi() *MainWindowUi {
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.action_Appearance = qt.NewQAction()
action_Appearance__objectName := qt.NewQAnyStringView3("action_Appearance")
ui.action_Appearance.SetObjectName(*action_Appearance__objectName)
action_Appearance__objectName.Delete() // setter copied value
ui.centralwidget = qt.NewQWidget(ui.MainWindow.QWidget)
centralwidget__objectName := qt.NewQAnyStringView3("centralwidget")
ui.centralwidget.SetObjectName(*centralwidget__objectName)
@@ -165,7 +162,7 @@ func NewMainWindowUi() *MainWindowUi {
gridLayout__objectName := qt.NewQAnyStringView3("gridLayout")
ui.gridLayout.SetObjectName(*gridLayout__objectName)
gridLayout__objectName.Delete() // setter copied value
ui.gridLayout.SetContentsMargins(11, 11, 11, 11)
ui.gridLayout.SetContentsMargins(0, 0, 0, 0)
ui.gridLayout.SetSpacing(6)
ui.splitter = qt.NewQSplitter(ui.centralwidget)
splitter__objectName := qt.NewQAnyStringView3("splitter")
@@ -177,6 +174,7 @@ func NewMainWindowUi() *MainWindowUi {
Buckets__objectName := qt.NewQAnyStringView3("Buckets")
ui.Buckets.SetObjectName(*Buckets__objectName)
Buckets__objectName.Delete() // setter copied value
ui.Buckets.SetFrameShape(qt.QFrame__NoFrame)
ui.Buckets.SetUniformRowHeights(true)
ui.Buckets.SetHeaderHidden(true)
/* miqt-uic: no handler for Buckets attribute 'headerVisible' */
@@ -212,9 +210,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.propertiesBox.SetReadOnly(true)
ui.gridLayout_2.AddWidget2(ui.propertiesBox.QWidget, 0, 0)
icon12 := qt.NewQIcon()
icon12.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabProperties, icon12, "")
icon11 := qt.NewQIcon()
icon11.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabProperties, icon11, "")
ui.tabData = qt.NewQWidget(ui.tabWidget.QWidget)
tabData__objectName := qt.NewQAnyStringView3("tabData")
ui.tabData.SetObjectName(*tabData__objectName)
@@ -223,7 +221,7 @@ func NewMainWindowUi() *MainWindowUi {
verticalLayout__objectName := qt.NewQAnyStringView3("verticalLayout")
ui.verticalLayout.SetObjectName(*verticalLayout__objectName)
verticalLayout__objectName.Delete() // setter copied value
ui.verticalLayout.SetContentsMargins(11, 11, 11, 11)
ui.verticalLayout.SetContentsMargins(2, 2, 2, 2)
ui.verticalLayout.SetSpacing(6)
ui.contentBox = qt.NewQTableView(ui.tabData)
contentBox__objectName := qt.NewQAnyStringView3("contentBox")
@@ -233,9 +231,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
ui.verticalLayout.AddWidget(ui.contentBox.QWidget)
icon13 := qt.NewQIcon()
icon13.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabData, icon13, "")
icon12 := qt.NewQIcon()
icon12.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabData, icon12, "")
ui.tabQuery = qt.NewQWidget(ui.tabWidget.QWidget)
tabQuery__objectName := qt.NewQAnyStringView3("tabQuery")
ui.tabQuery.SetObjectName(*tabQuery__objectName)
@@ -244,7 +242,7 @@ func NewMainWindowUi() *MainWindowUi {
verticalLayout_2__objectName := qt.NewQAnyStringView3("verticalLayout_2")
ui.verticalLayout_2.SetObjectName(*verticalLayout_2__objectName)
verticalLayout_2__objectName.Delete() // setter copied value
ui.verticalLayout_2.SetContentsMargins(11, 11, 11, 11)
ui.verticalLayout_2.SetContentsMargins(2, 2, 2, 2)
ui.verticalLayout_2.SetSpacing(6)
ui.splitter_2 = qt.NewQSplitter(ui.tabQuery)
splitter_2__objectName := qt.NewQAnyStringView3("splitter_2")
@@ -267,9 +265,9 @@ func NewMainWindowUi() *MainWindowUi {
ui.splitter_2.AddWidget(ui.queryResult.QWidget)
ui.verticalLayout_2.AddWidget(ui.splitter_2.QWidget)
icon14 := qt.NewQIcon()
icon14.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabQuery, icon14, "")
icon13 := qt.NewQIcon()
icon13.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
ui.tabWidget.AddTab2(ui.tabQuery, icon13, "")
ui.splitter.AddWidget(ui.tabWidget.QWidget)
ui.gridLayout.AddWidget2(ui.splitter.QWidget, 0, 0)
@@ -308,16 +306,21 @@ 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")
ui.menu_Tools.SetObjectName(*menu_Tools__objectName)
menu_Tools__objectName.Delete() // setter copied value
ui.menu_Tools.QWidget.AddAction(ui.actionCreate_Bolt_database_from_zip)
ui.menu_View = qt.NewQMenu(ui.menubar.QWidget)
menu_View__objectName := qt.NewQAnyStringView3("menu_View")
ui.menu_View.SetObjectName(*menu_View__objectName)
menu_View__objectName.Delete() // setter copied value
ui.menu_View.QWidget.AddAction(ui.action_Appearance)
ui.menubar.AddMenu(ui.menu_File)
ui.menubar.AddMenu(ui.menu_Data)
ui.menubar.AddMenu(ui.menu_Query)
ui.menubar.AddMenu(ui.menu_View)
ui.menubar.AddMenu(ui.menu_Tools)
ui.menubar.AddMenu(ui.menu_Help)
ui.MainWindow.SetMenuBar(ui.menubar)
@@ -348,7 +351,6 @@ func NewMainWindowUi() *MainWindowUi {
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")
@@ -389,7 +391,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.action_Appearance.SetText(qt.QMainWindow_Tr("&Appearance..."))
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"))
@@ -398,6 +400,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.menu_View.SetTitle(qt.QMenuBar_Tr("&View"))
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

@@ -19,6 +19,18 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
@@ -28,6 +40,9 @@
<bool>false</bool>
</property>
<widget class="QTreeWidget" name="Buckets">
<property name="frameShape">
<enum>QFrame::Shape::NoFrame</enum>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
@@ -83,6 +98,18 @@
<string>Data</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTableView" name="contentBox">
<property name="verticalScrollMode">
@@ -104,6 +131,18 @@
<string>Query</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
@@ -177,7 +216,6 @@
<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">
@@ -186,9 +224,16 @@
</property>
<addaction name="actionCreate_Bolt_database_from_zip"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
<string>&amp;View</string>
</property>
<addaction name="action_Appearance"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Data"/>
<addaction name="menu_Query"/>
<addaction name="menu_View"/>
<addaction name="menu_Tools"/>
<addaction name="menu_Help"/>
</widget>
@@ -240,7 +285,6 @@
<addaction name="actionRefresh"/>
<addaction name="actionAddRow"/>
<addaction name="actionDelete_row"/>
<addaction name="actionSet_cell_to_null"/>
<addaction name="actionApply_changes"/>
</widget>
<widget class="QToolBar" name="tbQuery">
@@ -409,16 +453,9 @@
<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>
<action name="action_Appearance">
<property name="text">
<string>Set cell to null</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
<string>&amp;Appearance...</string>
</property>
</action>
</widget>

View File

@@ -136,9 +136,10 @@ func (s SSHTunnel) Open(ctx context.Context) (*ssh.Client, error) {
cfg.HostKeyCallback = ssh.InsecureIgnoreHostKey()
} else if s.HostVerification.ExternalKnownHostsFile != nil {
cb, err := knownhosts.New(string(s.HostVerification.ExternalKnownHostsFile.Path))
loadPath := string(s.HostVerification.ExternalKnownHostsFile.Path)
cb, err := knownhosts.New(loadPath)
if err != nil {
return nil, fmt.Errorf("Parsing known_hosts file %q: %w")
return nil, fmt.Errorf("Parsing known_hosts file %q: %w", loadPath, err)
}
cfg.HostKeyCallback = cb

143
table.go
View File

@@ -5,6 +5,7 @@ import (
)
type TableColumn interface {
DataType() string
SetRowCount(newlen int)
SetCell(aRow int, data any)
GetCell(aRow int) any // only needed for editing
@@ -19,8 +20,13 @@ type EditAdvancedTableColumn interface {
CreateEditor(parent *qt.QWidget, aRow int, resolve, reject func())
}
type TooltipColumn interface {
Tooltip(aRow int) *qt.QVariant
}
type NullableTableColumn interface {
CellIsNull(aRow int) bool
SetCellNull(aRow int)
}
const (
@@ -153,6 +159,26 @@ func (ts *tableState) SetCell(aRow, aCol int, data any) {
ts.columns[aCol].SetCell(aRow, data)
}
func (ts *tableState) IsColumnNullable(aCol int) bool {
_, ok := ts.columns[aCol].(NullableTableColumn)
return ok
}
func (ts *tableState) SetCellNull(aRow, aCol int) bool {
if aRow >= ts.rowCount {
panic("SetCell with too large row")
}
setNull, ok := ts.columns[aCol].(NullableTableColumn)
if !ok {
return false
}
setNull.SetCellNull(aRow)
ts.dataIsEdited(aRow, aCol)
return true
}
// SetRowPrimaryKey
// The slice data will be copied.
func (ts *tableState) SetRowPrimaryKey(aRow int, data []byte) {
@@ -194,6 +220,12 @@ func (ts *tableState) DeleteSelectedRows() {
// this won't find all rows, just fully-selected rows from clicking on the
// vertical header bar
ts.DeleteRows(rows...)
}
// DeleteSelectedRows marks the rows for deletion.
func (ts *tableState) DeleteRows(rows ...qt.QModelIndex) {
for _, row := range rows {
row_ := row.Row() // your boat
@@ -234,6 +266,36 @@ func (ts *tableState) InsertNewRow() {
ts.OnEdited()
}
// dataIsEdited updates the updateRows array, and emits our OnEdited signal.
func (ts *tableState) dataIsEdited(aRow, aCol int) {
// If this is an insert row, no need to patch updateRows
if _, ok := ts.insertRows[aRow]; ok {
// nothing to do
} else {
// If this row was marked for deletion, this new edit takes priority
delete(ts.deleteRows, aRow)
// Set background colour
cells, ok := ts.updateRows[aRow]
if !ok {
cells = make([]int, 0, 1)
}
if slice_contains(cells, aCol) {
// already ok
} else {
cells = append(cells, aCol)
}
ts.updateRows[aRow] = cells
}
// Emit signal
// TODO ideally this would run after this function returned?
ts.OnEdited()
}
func NewTableState(tbl *qt.QTableView) *tableState {
// Stylistic changes
@@ -266,6 +328,14 @@ func NewTableState(tbl *qt.QTableView) *tableState {
}
return qt.NewQVariant11(ts.columnLabels[section])
} else if role == int(qt.ToolTipRole) && orientation == qt.Horizontal {
if section >= len(ts.columnLabels) {
return qt.NewQVariant() // invalid request
}
tooltip := `Data type: ` + ts.columns[section].DataType()
return qt.NewQVariant11(tooltip)
}
return super(section, orientation, role)
@@ -304,6 +374,13 @@ func NewTableState(tbl *qt.QTableView) *tableState {
return qt.NewQVariant() // just default
case int(qt.ToolTipRole):
if tipper, ok := ts.columns[aCol].(TooltipColumn); ok {
return tipper.Tooltip(aRow)
}
return qt.NewQVariant() // no tooltip
case int(qt.EditRole):
// Supplying to the editor, return a QVariant of raw editing type
@@ -348,31 +425,7 @@ func NewTableState(tbl *qt.QTableView) *tableState {
// Update content
ts.columns[aCol].ApplySimpleChange(aRow, value)
// If this is an insert row, no need to patch updateRows
if _, ok := ts.insertRows[aRow]; ok {
// nothing to do
} else {
// If this row was marked for deletion, this new edit takes priority
delete(ts.deleteRows, aRow)
// Set background colour
cells, ok := ts.updateRows[aRow]
if !ok {
cells = make([]int, 0, 1)
}
if slice_contains(cells, aCol) {
// already ok
} else {
cells = append(cells, aCol)
}
ts.updateRows[aRow] = cells
}
// Emit signal
// TODO ideally this would run after this function returned?
ts.OnEdited()
ts.dataIsEdited(aRow, aCol)
// Done
return true
@@ -402,6 +455,46 @@ func NewTableState(tbl *qt.QTableView) *tableState {
}
})
tbl.SetContextMenuPolicy(qt.CustomContextMenu)
tbl.OnCustomContextMenuRequested(func(pos *qt.QPoint) {
idx := tbl.IndexAt(pos)
if !idx.IsValid() {
return // No popup
}
mnu := qt.NewQMenu(tbl.QWidget)
mnu.SetAttribute(qt.WA_DeleteOnClose)
_ = mnu.AddSection("Row")
if ts.allowEdit {
deleteRowAction := mnu.AddAction2(qt.NewQIcon4(`:/assets/delete.png`), "Delete row")
deleteRowAction.OnTriggered(func() {
ts.DeleteRows(*idx)
})
}
_ = mnu.AddSection("Cell")
if ts.allowEdit {
editCellAction := mnu.AddAction2(qt.NewQIcon4(`:/assets/pencil.png`), "Edit cell...")
editCellAction.OnTriggered(func() {
tbl.Edit(idx)
})
}
if ts.IsColumnNullable(idx.Column()) {
setCellNullAction := mnu.AddAction2(qt.NewQIcon4(`:/assets/note_delete.png`), "Set cell to null")
setCellNullAction.OnTriggered(func() {
ts.SetCellNull(idx.Row(), idx.Column())
})
}
mnu.Popup(tbl.Viewport().MapToGlobalWithQPoint(pos))
})
// Set target QTableView's model
tbl.SetModel(model.QAbstractItemModel)

View File

@@ -13,6 +13,10 @@ type binColumn struct {
vals [][]byte
}
func (*binColumn) DataType() string {
return "Binary"
}
func (bc *binColumn) SetRowCount(newlen int) {
bc.vals = slice_set_len(bc.vals, newlen)
}
@@ -23,7 +27,10 @@ func (bc *binColumn) SetCell(aRow int, data any) {
panic(fmt.Sprintf("bad data type (got %T)", data))
}
bc.vals[aRow] = str
// TODO Use slice_dup() here because many iterator loops reuse the backing []byte
// slice. However it would be more efficient if slice_dup() was explicitly called
// only by each the DB implementation that really needs it
bc.vals[aRow] = slice_dup(str)
}
func (bc *binColumn) GetCell(aRow int) any {

View File

@@ -13,6 +13,10 @@ type bsonColumn struct {
vals []bson.D
}
func (*bsonColumn) DataType() string {
return "BSON"
}
func (bc *bsonColumn) SetRowCount(newlen int) {
bc.vals = slice_set_len(bc.vals, newlen)
}

View File

@@ -10,6 +10,10 @@ type dynamicColumn struct {
vals []any
}
func (*dynamicColumn) DataType() string {
return "Dynamic"
}
func (sc *dynamicColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}

View File

@@ -8,6 +8,10 @@ type goModuleColumn struct {
vals []string
}
func (*goModuleColumn) DataType() string {
return "Go Module"
}
func (sc *goModuleColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"time"
qt "github.com/mappu/miqt/qt6"
)
@@ -10,6 +11,10 @@ type int64Column struct {
vals []int64
}
func (*int64Column) DataType() string {
return "Integer"
}
func (sc *int64Column) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
@@ -35,6 +40,37 @@ func (sc *int64Column) Display(aRow int) *qt.QVariant {
return qt.NewQVariant6(sc.vals[aRow])
}
func makeIntegerTooltip(val int64) *qt.QVariant {
// If this looks like a unix timestamp, convert it
const dateFormatNice = "2006-01-02 15:04:05 MST -07:00"
if 1000000000 <= val && val <= 5000000000 { // circa year 2001 -> 2128
// Show the timestamp in UTC and in the OS's current location
return qt.NewQVariant11(
"Unix timestamp (seconds):\n" +
time.Unix(val, 0).UTC().Format(dateFormatNice) + "\n" +
time.Unix(val, 0).Local().Format(dateFormatNice))
}
if 1000000000000 <= val && val <= 5000000000000 { // circa year 2001 -> 2128
// Show the timestamp in UTC and in the OS's current location
return qt.NewQVariant11(
"Unix timestamp (milliseconds):\n" +
time.Unix(val/1000, val%1000).UTC().Format(dateFormatNice) + "\n" +
time.Unix(val/1000, val%1000).Local().Format(dateFormatNice))
}
// Not in the normal time looking range
return qt.NewQVariant() // invalid
}
func (sc *int64Column) Tooltip(aRow int) *qt.QVariant {
return makeIntegerTooltip(sc.vals[aRow])
}
func (sc *int64Column) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
@@ -60,3 +96,4 @@ func (sc *int64Column) IndicateBlue() bool {
}
var _ TableColumn = &int64Column{}
var _ TooltipColumn = &int64Column{}

View File

@@ -11,6 +11,10 @@ type sqlNullInt64Column struct {
vals []sql.NullInt64
}
func (*sqlNullInt64Column) DataType() string {
return "Integer (Nullable)"
}
func (sc *sqlNullInt64Column) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
@@ -37,10 +41,22 @@ func (sc *sqlNullInt64Column) Display(aRow int) *qt.QVariant {
}
}
func (sc *sqlNullInt64Column) Tooltip(aRow int) *qt.QVariant {
cell := sc.vals[aRow]
if cell.Valid {
return makeIntegerTooltip(cell.Int64)
}
return qt.NewQVariant()
}
func (sc *sqlNullInt64Column) CellIsNull(aRow int) bool {
return !sc.vals[aRow].Valid
}
func (sc *sqlNullInt64Column) SetCellNull(aRow int) {
sc.vals[aRow] = sql.NullInt64{Valid: false}
}
func (sc *sqlNullInt64Column) Inspect(parent *qt.QWidget, aRow int) {
// do nothing
}
@@ -68,3 +84,4 @@ func (sc *sqlNullInt64Column) IndicateBlue() bool {
var _ TableColumn = &sqlNullInt64Column{}
var _ NullableTableColumn = &sqlNullInt64Column{}
var _ TooltipColumn = &sqlNullInt64Column{}

View File

@@ -11,6 +11,10 @@ type sqlNullStringColumn struct {
vals []sql.NullString
}
func (*sqlNullStringColumn) DataType() string {
return "String (Nullable)"
}
func (sc *sqlNullStringColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}
@@ -32,6 +36,10 @@ func (sc *sqlNullStringColumn) CellIsNull(aRow int) bool {
return !sc.vals[aRow].Valid
}
func (sc *sqlNullStringColumn) SetCellNull(aRow int) {
sc.vals[aRow] = sql.NullString{Valid: false}
}
func (sc *sqlNullStringColumn) Display(aRow int) *qt.QVariant {
cell := sc.vals[aRow]
if cell.Valid {

View File

@@ -10,6 +10,10 @@ type stringColumn struct {
vals []string
}
func (*stringColumn) DataType() string {
return "String"
}
func (sc *stringColumn) SetRowCount(newlen int) {
sc.vals = slice_set_len(sc.vals, newlen)
}