Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13fedfa2f6 | |||
| 8b06ccef48 | |||
| 17d6b5172d | |||
| 708e8072ff | |||
| c8125d2c84 | |||
| a5138a51f3 | |||
| 02b5a8fd48 | |||
| b2118c9196 | |||
| 5aa76a465c | |||
| f3e729b023 | |||
| 5c7a99d16b |
1
Makefile
1
Makefile
@@ -9,6 +9,7 @@ GO_WINRES ?= ~/go/bin/go-winres
|
|||||||
|
|
||||||
.PHONY: generate
|
.PHONY: generate
|
||||||
generate:
|
generate:
|
||||||
|
/bin/bash -c '( echo "<RCC>" ; echo " <qresource prefix=\"/\">" ; for f in assets/* ; do echo " <file>$$f</file>" ; done ; echo " </qresource>" ; echo "</RCC>" ) > embed.qrc'
|
||||||
$(MIQT_UIC) -InFile mainwindow.ui -OutFile mainwindow.go -Qt6
|
$(MIQT_UIC) -InFile mainwindow.ui -OutFile mainwindow.go -Qt6
|
||||||
$(MIQT_UIC) -InFile connectionDialog.ui -OutFile connectionDialog.go -Qt6
|
$(MIQT_UIC) -InFile connectionDialog.ui -OutFile connectionDialog.go -Qt6
|
||||||
$(MIQT_UIC) -InFile connectionManagerDialog.ui -OutFile connectionManagerDialog.go -Qt6
|
$(MIQT_UIC) -InFile connectionManagerDialog.ui -OutFile connectionManagerDialog.go -Qt6
|
||||||
|
|||||||
@@ -18,12 +18,13 @@ A graphical interface for multiple databases.
|
|||||||
|
|
||||||
## Supported databases
|
## Supported databases
|
||||||
|
|
||||||
There are currently 15 supported databases:
|
There are currently 16 supported databases:
|
||||||
|
|
||||||
Database |Read |Editing |Query |Connection options |Context menu actions
|
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 |Backup, restore, compact
|
||||||
Bitcask |Yes |Yes |No |Readonly, autorecovery |Backup
|
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
|
Bolt |Yes |Yes |No |Readonly |Create/delete child buckets, import/export as zip
|
||||||
Debconf |Yes |No |No | |
|
Debconf |Yes |No |No | |
|
||||||
Freedesktop.org Secret Service |Yes |No | No | |Unlock, create new collection
|
Freedesktop.org Secret Service |Yes |No | No | |Unlock, create new collection
|
||||||
@@ -34,7 +35,7 @@ MongoDB |Yes |No |Yes |SSH tunnel |Create/delete child d
|
|||||||
Pebble |Yes |Yes |No |Readonly, in-memory |
|
Pebble |Yes |Yes |No |Readonly, in-memory |
|
||||||
Redis |Yes |No |Yes |SSH tunnel, RESP v3 |
|
Redis |Yes |No |Yes |SSH tunnel, RESP v3 |
|
||||||
RoseDB |Yes |Yes |No | |
|
RoseDB |Yes |Yes |No | |
|
||||||
SQLite |Yes |Yes |Yes |CLI driver, in-memory |Vacuum, export
|
SQLite |Yes |Yes |Yes |**SSH tunnel**, CLI driver, in-memory |Vacuum, export
|
||||||
SSH Agent |Yes |No |No |Unix/TCP |Lock, unlock
|
SSH Agent |Yes |No |No |Unix/TCP |Lock, unlock
|
||||||
Starskey |Yes |Yes |No |Compression |
|
Starskey |Yes |Yes |No |Compression |
|
||||||
|
|
||||||
|
|||||||
6
TODO
6
TODO
@@ -1,13 +1,13 @@
|
|||||||
- BUG: Connecting to multiple DBs from connection manager: if one has an error, the error popup from the others is lost
|
- BUG: Connecting to multiple DBs from connection manager: if one has an error, the error popup from the others is lost
|
||||||
- BUG: ExecQuery being called multiple times on error?
|
- BUG: ExecQuery being called multiple times on error?
|
||||||
- Drag and drop database into UI (QBolt parity)
|
- Drag and drop database into UI (QBolt parity)
|
||||||
- Merge with QBolt
|
|
||||||
- Portable mode (portable.txt or portable/ dir)
|
- Portable mode (portable.txt or portable/ dir)
|
||||||
- Syntax highlighting in editor
|
- Syntax highlighting in editor
|
||||||
- Autorefresh
|
- Autorefresh
|
||||||
- Sshagent
|
- Sshagent
|
||||||
- want to trigger an async refresh from inside the LDB after lock/unlock
|
- want to trigger an async refresh from inside the LDB after lock/unlock
|
||||||
- support adding/removing keys (will need per-row actions)
|
- support adding/removing keys (will need per-row actions)
|
||||||
|
- SSH: knownhost parser is stricter than openssh, does not support hostname if there is known a knownhost for the IP address
|
||||||
- Bolt: import/export should support passworded zips
|
- Bolt: import/export should support passworded zips
|
||||||
- Table: BSON view can't see data
|
- Table: BSON view can't see data
|
||||||
- Table: quick filter
|
- Table: quick filter
|
||||||
@@ -67,6 +67,8 @@
|
|||||||
- https://github.com/TerraTech/go-tokyocabinet needs pkg-config tokyocabinet
|
- https://github.com/TerraTech/go-tokyocabinet needs pkg-config tokyocabinet
|
||||||
- https://github.com/estraier/tkrzw-go needs pkg-config tkrzw
|
- https://github.com/estraier/tkrzw-go needs pkg-config tkrzw
|
||||||
- cdb (DJB's Constant Database)
|
- cdb (DJB's Constant Database)
|
||||||
|
- RocksDB
|
||||||
|
- https://github.com/tecbot/gorocksdb Go bindings, need pkg-config rocksdb
|
||||||
- Rust
|
- Rust
|
||||||
- Stoolap https://github.com/stoolap/stoolap
|
- Stoolap https://github.com/stoolap/stoolap
|
||||||
- Rust, needs C binding layer https://github.com/mozilla/cbindgen
|
- Rust, needs C binding layer https://github.com/mozilla/cbindgen
|
||||||
@@ -75,8 +77,8 @@
|
|||||||
- SQLite CLI driver:
|
- SQLite CLI driver:
|
||||||
- Context support
|
- Context support
|
||||||
- Write support
|
- Write support
|
||||||
- Attach to SSH tunnel
|
|
||||||
- Configure binary path
|
- Configure binary path
|
||||||
|
- Error handling: if an error occurs, listing db tables has problems/shows separators
|
||||||
- https://ricardoanderegg.com/posts/sqlite-remote-explorer-gui/
|
- https://ricardoanderegg.com/posts/sqlite-remote-explorer-gui/
|
||||||
- https://github.com/litements/litexplore
|
- https://github.com/litements/litexplore
|
||||||
- Badger:
|
- Badger:
|
||||||
|
|||||||
BIN
assets/compress.png
Normal file
BIN
assets/compress.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 892 B |
BIN
assets/key.png
Normal file
BIN
assets/key.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 583 B |
BIN
assets/page_key.png
Normal file
BIN
assets/page_key.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 907 B |
BIN
assets/vendor_buntdb.png
Normal file
BIN
assets/vendor_buntdb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 611 B |
@@ -22,6 +22,7 @@ type ConnectionConfig struct {
|
|||||||
Badger *badgerConnection `ylabel:"BadgerDB v4" yicon:":/assets/vendor_dgraph.png" json:",omitempty"`
|
Badger *badgerConnection `ylabel:"BadgerDB v4" yicon:":/assets/vendor_dgraph.png" json:",omitempty"`
|
||||||
Bitcask *bitcaskDBConnection `yicon:":/assets/vendor_riak.png" json:",omitempty"`
|
Bitcask *bitcaskDBConnection `yicon:":/assets/vendor_riak.png" json:",omitempty"`
|
||||||
Bolt *boltConfig `yicon:":/assets/vendor_github.png" json:",omitempty"`
|
Bolt *boltConfig `yicon:":/assets/vendor_github.png" json:",omitempty"`
|
||||||
|
BuntDB *buntDBConnection `ylabel:"BuntDB" yicon:":/assets/vendor_buntdb.png" json:",omitempty"`
|
||||||
Debconf *debconfConnection `yicon:":/assets/vendor_debian.png" json:",omitempty"`
|
Debconf *debconfConnection `yicon:":/assets/vendor_debian.png" json:",omitempty"`
|
||||||
SecretService *secretServiceConnection `ylabel:"Freedesktop.org Secret Service" yicon:":/assets/vendor_freedesktop.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"`
|
LevelDB *leveldbConnection `ylabel:"LevelDB" yicon:":/assets/vendor_leveldb.png" json:",omitempty"`
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ type badgerConnection struct {
|
|||||||
Directory autoconfig.ExistingDirectory
|
Directory autoconfig.ExistingDirectory
|
||||||
Readonly bool
|
Readonly bool
|
||||||
Encryption *encryptionKey
|
Encryption *encryptionKey
|
||||||
}
|
} `json:",omitempty"`
|
||||||
Memory *struct{}
|
Memory *struct{} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type encryptionKey struct {
|
type encryptionKey struct {
|
||||||
|
|||||||
118
db_bunt.go
Normal file
118
db_bunt.go
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mappu/autoconfig"
|
||||||
|
qt "github.com/mappu/miqt/qt6"
|
||||||
|
"github.com/tidwall/buntdb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type buntLdb struct {
|
||||||
|
db *buntdb.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) DriverName() string {
|
||||||
|
return "BuntDB"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) Properties(bucketPath []string) (string, error) {
|
||||||
|
idxInfo, err := ld.db.Indexes()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("Indexes (%d):\n%s", len(idxInfo), "-"+strings.Join(idxInfo, "\n- ")+"\n"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) RenderForNav(f *tableState, bucketPath []string) error {
|
||||||
|
|
||||||
|
// Load data
|
||||||
|
// Interestingly, BuntDB internally uses string data, not []byte data
|
||||||
|
// That would stop us from using kvstore_ApplyChanges that only works with
|
||||||
|
// []byte data, so, fake []byte casts ourselves
|
||||||
|
f.SetupColumns([]columnType{columnType_popupData, columnType_popupData}, []string{"Key", "Value"})
|
||||||
|
|
||||||
|
err := ld.db.View(func(tx *buntdb.Tx) error {
|
||||||
|
return tx.Ascend("", func(k, v string) bool {
|
||||||
|
f.AddRow_PK_Data([]byte(k), []byte(k), []byte(v))
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid
|
||||||
|
f.Ready()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *buntLdb) ApplyChanges(f *tableState, bucketPath []string) error {
|
||||||
|
|
||||||
|
return n.db.Update(func(tx *buntdb.Tx) error {
|
||||||
|
return kvstore_ApplyChanges(
|
||||||
|
f,
|
||||||
|
func(k, v []byte) error {
|
||||||
|
_, _, err := tx.Set(string(k), string(v), nil)
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
func(k []byte) error {
|
||||||
|
_, err := tx.Delete(string(k))
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) doShrink(sender *qt.QTreeWidgetItem, bucketPath []string) error {
|
||||||
|
return ld.db.Shrink()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) NavChildren(bucketPath []string) ([]string, error) {
|
||||||
|
return []string{}, nil // No children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) NavContext(bucketPath []string) ([]contextAction, error) {
|
||||||
|
return []contextAction{
|
||||||
|
{"Shrink", ld.doShrink},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *buntLdb) Close() {
|
||||||
|
_ = ld.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ loadedDatabase = &buntLdb{} // interface assertion
|
||||||
|
var _ editableLoadedDatabase = &buntLdb{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type buntDBConnection struct {
|
||||||
|
Type autoconfig.OneOf
|
||||||
|
|
||||||
|
Disk *struct {
|
||||||
|
File autoconfig.ExistingFile
|
||||||
|
} `json:",omitempty"`
|
||||||
|
Memory *struct{} `json:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ldc *buntDBConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
|
||||||
|
var path string
|
||||||
|
if ldc.Disk != nil {
|
||||||
|
path = string(ldc.Disk.File)
|
||||||
|
} else {
|
||||||
|
path = `:memory:` // Special string known by driver
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := buntdb.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &buntLdb{db: db}, filepath.Base(path), nil
|
||||||
|
}
|
||||||
@@ -238,10 +238,10 @@ var _ editableLoadedDatabase = &lmdbDatabase{} // interface assertion
|
|||||||
type lmdbConnection struct {
|
type lmdbConnection struct {
|
||||||
Storage struct {
|
Storage struct {
|
||||||
Type autoconfig.OneOf
|
Type autoconfig.OneOf
|
||||||
Directory *autoconfig.ExistingDirectory
|
Directory *autoconfig.ExistingDirectory `json:",omitempty"`
|
||||||
File *struct {
|
File *struct {
|
||||||
Path autoconfig.ExistingFile `yfilter:"LMDB database (*.mdb);;All files (*)"`
|
Path autoconfig.ExistingFile `yfilter:"LMDB database (*.mdb);;All files (*)"`
|
||||||
}
|
} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
MultiDB *struct {
|
MultiDB *struct {
|
||||||
Slots int
|
Slots int
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ type mongoConnection struct {
|
|||||||
Conn struct {
|
Conn struct {
|
||||||
Mode autoconfig.OneOf
|
Mode autoconfig.OneOf
|
||||||
|
|
||||||
Connection_String *string
|
Connection_String *string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_Tunnel *SSHTunnel
|
SSH_Tunnel *SSHTunnel
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ type pebbleConnection struct {
|
|||||||
Disk *struct {
|
Disk *struct {
|
||||||
Directory autoconfig.ExistingDirectory
|
Directory autoconfig.ExistingDirectory
|
||||||
Readonly bool
|
Readonly bool
|
||||||
}
|
} `json:",omitempty"`
|
||||||
Memory *struct{}
|
Memory *struct{} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
func (pdc *pebbleConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
|
|||||||
27
db_sqlite.go
27
db_sqlite.go
@@ -406,8 +406,12 @@ type sqliteConnection struct {
|
|||||||
Disk *struct {
|
Disk *struct {
|
||||||
Database autoconfig.ExistingFile `yfilter:"SQLite database (*.db *.db3 *.sqlite *.sqlite3);;All files (*)"`
|
Database autoconfig.ExistingFile `yfilter:"SQLite database (*.db *.db3 *.sqlite *.sqlite3);;All files (*)"`
|
||||||
CliDriver bool `ylabel:"Use experimental CLI driver"`
|
CliDriver bool `ylabel:"Use experimental CLI driver"`
|
||||||
}
|
} `json:",omitempty"`
|
||||||
Memory *struct{}
|
Memory *struct{} `json:",omitempty"`
|
||||||
|
SSH *struct {
|
||||||
|
SSHServer *SSHTunnel
|
||||||
|
Database string
|
||||||
|
} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string, error) {
|
||||||
@@ -424,12 +428,29 @@ func (sc *sqliteConnection) Connect(ctx context.Context) (loadedDatabase, string
|
|||||||
|
|
||||||
return &sqliteLoadedDatabase{db: db}, filepath.Base(string(sc.Disk.Database)), nil
|
return &sqliteLoadedDatabase{db: db}, filepath.Base(string(sc.Disk.Database)), nil
|
||||||
|
|
||||||
} else { // memory
|
} else if sc.Memory != nil { // memory
|
||||||
db, err := sql.Open("sqlite3", ":memory:")
|
db, err := sql.Open("sqlite3", ":memory:")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &sqliteLoadedDatabase{db: db}, ":memory:", nil
|
return &sqliteLoadedDatabase{db: db}, ":memory:", nil
|
||||||
|
|
||||||
|
} else if sc.SSH != nil {
|
||||||
|
if sc.SSH.SSHServer == nil {
|
||||||
|
return nil, "", errors.New("Invalid configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
cl, err := sc.SSH.SSHServer.Open(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
db := sqliteclidriver.OpenSSH(cl, sc.SSH.Database)
|
||||||
|
|
||||||
|
return &sqliteLoadedDatabase{db: db}, "SSH[" + filepath.Base(string(sc.SSH.Database)) + "]", nil
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return nil, "", errors.New("Invalid configuration")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ var _ loadedDatabase = &sshAgentLdb{} // interface assertion
|
|||||||
|
|
||||||
type sshAgentConn struct {
|
type sshAgentConn struct {
|
||||||
Type autoconfig.OneOf
|
Type autoconfig.OneOf
|
||||||
Unix *autoconfig.ExistingFile
|
Unix *autoconfig.ExistingFile `json:",omitempty"`
|
||||||
TCP *autoconfig.AddressPort
|
TCP *autoconfig.AddressPort `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sshAgentConn) Reset() {
|
func (c *sshAgentConn) Reset() {
|
||||||
|
|||||||
14
embed.qrc
14
embed.qrc
@@ -1,21 +1,23 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>assets/vendor_qt.png</file>
|
|
||||||
<file>assets/connect.png</file>
|
|
||||||
<file>assets/disconnect.png</file>
|
|
||||||
<file>assets/database_key.png</file>
|
|
||||||
<file>assets/help.png</file>
|
|
||||||
<file>assets/add.png</file>
|
<file>assets/add.png</file>
|
||||||
<file>assets/arrow_refresh.png</file>
|
<file>assets/arrow_refresh.png</file>
|
||||||
<file>assets/chart_bar.png</file>
|
<file>assets/chart_bar.png</file>
|
||||||
|
<file>assets/compress.png</file>
|
||||||
|
<file>assets/connect.png</file>
|
||||||
<file>assets/database.png</file>
|
<file>assets/database.png</file>
|
||||||
<file>assets/database_add.png</file>
|
<file>assets/database_add.png</file>
|
||||||
<file>assets/database_delete.png</file>
|
<file>assets/database_delete.png</file>
|
||||||
|
<file>assets/database_key.png</file>
|
||||||
<file>assets/database_lightning.png</file>
|
<file>assets/database_lightning.png</file>
|
||||||
<file>assets/database_save.png</file>
|
<file>assets/database_save.png</file>
|
||||||
<file>assets/delete.png</file>
|
<file>assets/delete.png</file>
|
||||||
|
<file>assets/disconnect.png</file>
|
||||||
|
<file>assets/help.png</file>
|
||||||
|
<file>assets/key.png</file>
|
||||||
<file>assets/lightning.png</file>
|
<file>assets/lightning.png</file>
|
||||||
<file>assets/lightning_go.png</file>
|
<file>assets/lightning_go.png</file>
|
||||||
|
<file>assets/page_key.png</file>
|
||||||
<file>assets/pencil.png</file>
|
<file>assets/pencil.png</file>
|
||||||
<file>assets/pencil_add.png</file>
|
<file>assets/pencil_add.png</file>
|
||||||
<file>assets/pencil_delete.png</file>
|
<file>assets/pencil_delete.png</file>
|
||||||
@@ -25,6 +27,7 @@
|
|||||||
<file>assets/table_add.png</file>
|
<file>assets/table_add.png</file>
|
||||||
<file>assets/table_delete.png</file>
|
<file>assets/table_delete.png</file>
|
||||||
<file>assets/table_save.png</file>
|
<file>assets/table_save.png</file>
|
||||||
|
<file>assets/vendor_buntdb.png</file>
|
||||||
<file>assets/vendor_cockroach.png</file>
|
<file>assets/vendor_cockroach.png</file>
|
||||||
<file>assets/vendor_debian.png</file>
|
<file>assets/vendor_debian.png</file>
|
||||||
<file>assets/vendor_dgraph.png</file>
|
<file>assets/vendor_dgraph.png</file>
|
||||||
@@ -35,6 +38,7 @@
|
|||||||
<file>assets/vendor_lotus.png</file>
|
<file>assets/vendor_lotus.png</file>
|
||||||
<file>assets/vendor_mongodb.png</file>
|
<file>assets/vendor_mongodb.png</file>
|
||||||
<file>assets/vendor_mysql.png</file>
|
<file>assets/vendor_mysql.png</file>
|
||||||
|
<file>assets/vendor_qt.png</file>
|
||||||
<file>assets/vendor_redis.png</file>
|
<file>assets/vendor_redis.png</file>
|
||||||
<file>assets/vendor_riak.png</file>
|
<file>assets/vendor_riak.png</file>
|
||||||
<file>assets/vendor_rosedb.png</file>
|
<file>assets/vendor_rosedb.png</file>
|
||||||
|
|||||||
8
go.mod
8
go.mod
@@ -71,6 +71,14 @@ require (
|
|||||||
github.com/rosedblabs/wal v1.3.6 // indirect
|
github.com/rosedblabs/wal v1.3.6 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
|
github.com/tidwall/btree v1.7.0 // indirect
|
||||||
|
github.com/tidwall/buntdb v1.3.2 // indirect
|
||||||
|
github.com/tidwall/gjson v1.14.3 // indirect
|
||||||
|
github.com/tidwall/grect v0.1.4 // indirect
|
||||||
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
|
github.com/tidwall/rtred v0.1.2 // indirect
|
||||||
|
github.com/tidwall/tinyqueue v0.1.1 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
github.com/xdg-go/scram v1.2.0 // indirect
|
github.com/xdg-go/scram v1.2.0 // indirect
|
||||||
|
|||||||
17
go.sum
17
go.sum
@@ -165,6 +165,23 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
|
|||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||||
|
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
|
||||||
|
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
|
||||||
|
github.com/tidwall/buntdb v1.3.2 h1:qd+IpdEGs0pZci37G4jF51+fSKlkuUTMXuHhXL1AkKg=
|
||||||
|
github.com/tidwall/buntdb v1.3.2/go.mod h1:lZZrZUWzlyDJKlLQ6DKAy53LnG7m5kHyrEHvvcDmBpU=
|
||||||
|
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
|
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
|
||||||
|
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
|
github.com/tidwall/grect v0.1.4 h1:dA3oIgNgWdSspFzn1kS4S/RDpZFLrIxAZOdJKjYapOg=
|
||||||
|
github.com/tidwall/grect v0.1.4/go.mod h1:9FBsaYRaR0Tcy4UwefBX/UDcDcDy9V5jUcxHzv2jd5Q=
|
||||||
|
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||||
|
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
|
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||||
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
|
||||||
|
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
|
||||||
|
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
|
||||||
|
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ func NewMainWindowUi() *MainWindowUi {
|
|||||||
actionCreate_Bolt_database_from_zip__objectName := qt.NewQAnyStringView3("actionCreate_Bolt_database_from_zip")
|
actionCreate_Bolt_database_from_zip__objectName := qt.NewQAnyStringView3("actionCreate_Bolt_database_from_zip")
|
||||||
ui.actionCreate_Bolt_database_from_zip.SetObjectName(*actionCreate_Bolt_database_from_zip__objectName)
|
ui.actionCreate_Bolt_database_from_zip.SetObjectName(*actionCreate_Bolt_database_from_zip__objectName)
|
||||||
actionCreate_Bolt_database_from_zip__objectName.Delete() // setter copied value
|
actionCreate_Bolt_database_from_zip__objectName.Delete() // setter copied value
|
||||||
|
icon10 := qt.NewQIcon()
|
||||||
|
icon10.AddFile4(":/assets/compress.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
|
ui.actionCreate_Bolt_database_from_zip.SetIcon(icon10)
|
||||||
ui.centralwidget = qt.NewQWidget(ui.MainWindow.QWidget)
|
ui.centralwidget = qt.NewQWidget(ui.MainWindow.QWidget)
|
||||||
centralwidget__objectName := qt.NewQAnyStringView3("centralwidget")
|
centralwidget__objectName := qt.NewQAnyStringView3("centralwidget")
|
||||||
ui.centralwidget.SetObjectName(*centralwidget__objectName)
|
ui.centralwidget.SetObjectName(*centralwidget__objectName)
|
||||||
@@ -198,9 +201,9 @@ func NewMainWindowUi() *MainWindowUi {
|
|||||||
ui.propertiesBox.SetReadOnly(true)
|
ui.propertiesBox.SetReadOnly(true)
|
||||||
|
|
||||||
ui.gridLayout_2.AddWidget2(ui.propertiesBox.QWidget, 0, 0)
|
ui.gridLayout_2.AddWidget2(ui.propertiesBox.QWidget, 0, 0)
|
||||||
icon10 := qt.NewQIcon()
|
icon11 := qt.NewQIcon()
|
||||||
icon10.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
icon11.AddFile4(":/assets/chart_bar.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
ui.tabWidget.AddTab2(ui.tabProperties, icon10, "")
|
ui.tabWidget.AddTab2(ui.tabProperties, icon11, "")
|
||||||
ui.tabData = qt.NewQWidget(ui.tabWidget.QWidget)
|
ui.tabData = qt.NewQWidget(ui.tabWidget.QWidget)
|
||||||
tabData__objectName := qt.NewQAnyStringView3("tabData")
|
tabData__objectName := qt.NewQAnyStringView3("tabData")
|
||||||
ui.tabData.SetObjectName(*tabData__objectName)
|
ui.tabData.SetObjectName(*tabData__objectName)
|
||||||
@@ -219,9 +222,9 @@ func NewMainWindowUi() *MainWindowUi {
|
|||||||
ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
ui.contentBox.SetHorizontalScrollMode(qt.QAbstractItemView__ScrollPerPixel)
|
||||||
|
|
||||||
ui.verticalLayout.AddWidget(ui.contentBox.QWidget)
|
ui.verticalLayout.AddWidget(ui.contentBox.QWidget)
|
||||||
icon11 := qt.NewQIcon()
|
icon12 := qt.NewQIcon()
|
||||||
icon11.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
icon12.AddFile4(":/assets/table.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
ui.tabWidget.AddTab2(ui.tabData, icon11, "")
|
ui.tabWidget.AddTab2(ui.tabData, icon12, "")
|
||||||
ui.tabQuery = qt.NewQWidget(ui.tabWidget.QWidget)
|
ui.tabQuery = qt.NewQWidget(ui.tabWidget.QWidget)
|
||||||
tabQuery__objectName := qt.NewQAnyStringView3("tabQuery")
|
tabQuery__objectName := qt.NewQAnyStringView3("tabQuery")
|
||||||
ui.tabQuery.SetObjectName(*tabQuery__objectName)
|
ui.tabQuery.SetObjectName(*tabQuery__objectName)
|
||||||
@@ -253,9 +256,9 @@ func NewMainWindowUi() *MainWindowUi {
|
|||||||
ui.splitter_2.AddWidget(ui.queryResult.QWidget)
|
ui.splitter_2.AddWidget(ui.queryResult.QWidget)
|
||||||
|
|
||||||
ui.verticalLayout_2.AddWidget(ui.splitter_2.QWidget)
|
ui.verticalLayout_2.AddWidget(ui.splitter_2.QWidget)
|
||||||
icon12 := qt.NewQIcon()
|
icon13 := qt.NewQIcon()
|
||||||
icon12.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
icon13.AddFile4(":/assets/lightning.png", qt.NewQSize(), qt.QIcon__Normal, qt.QIcon__Off)
|
||||||
ui.tabWidget.AddTab2(ui.tabQuery, icon12, "")
|
ui.tabWidget.AddTab2(ui.tabQuery, icon13, "")
|
||||||
ui.splitter.AddWidget(ui.tabWidget.QWidget)
|
ui.splitter.AddWidget(ui.tabWidget.QWidget)
|
||||||
|
|
||||||
ui.gridLayout.AddWidget2(ui.splitter.QWidget, 0, 0)
|
ui.gridLayout.AddWidget2(ui.splitter.QWidget, 0, 0)
|
||||||
|
|||||||
@@ -358,6 +358,10 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionCreate_Bolt_database_from_zip">
|
<action name="actionCreate_Bolt_database_from_zip">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="embed.qrc">
|
||||||
|
<normaloff>:/assets/compress.png</normaloff>:/assets/compress.png</iconset>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Create Bolt database from zip</string>
|
<string>Create Bolt database from zip</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
94
sqliteclidriver/event.go
Normal file
94
sqliteclidriver/event.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
evtypeStdout int = iota
|
||||||
|
evtypeStderr
|
||||||
|
evtypeExit
|
||||||
|
)
|
||||||
|
|
||||||
|
type processEvent struct {
|
||||||
|
evtype int
|
||||||
|
data []byte
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pe processEvent) Error() string {
|
||||||
|
if pe.err != nil {
|
||||||
|
return pe.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
if pe.evtype == evtypeStderr {
|
||||||
|
return string(pe.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<no error>"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pe processEvent) Unwrap() error {
|
||||||
|
return pe.err
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
func handleEvents(pw io.WriteCloser, pr, pe io.Reader, waiter func() error) (<-chan processEvent, io.WriteCloser, error) {
|
||||||
|
|
||||||
|
chEvents := make(chan processEvent, 0)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
processEventWorker(pr, evtypeStdout, chEvents)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
processEventWorker(pe, evtypeStderr, chEvents)
|
||||||
|
}()
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// Only call cmd.Wait() after pipes are closed
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
err := waiter()
|
||||||
|
chEvents <- processEvent{
|
||||||
|
evtype: evtypeExit,
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
|
||||||
|
close(chEvents)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return chEvents, pw, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func processEventWorker(p io.Reader, evtype int, dest chan<- processEvent) {
|
||||||
|
for {
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
n, err := p.Read(buf)
|
||||||
|
|
||||||
|
if n > 0 {
|
||||||
|
dest <- processEvent{
|
||||||
|
evtype: evtype,
|
||||||
|
data: buf[0:n],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
dest <- processEvent{
|
||||||
|
evtype: evtype,
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume all errors are permanent
|
||||||
|
// Ordering can produce either io.EOF, ErrClosedPipe, or PathError{"file already closed"}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,40 +3,15 @@ package sqliteclidriver
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
func LocalBinEvents(databasePath string) (<-chan processEvent, io.WriteCloser, error) {
|
||||||
evtypeStdout int = iota
|
// TODO find a way to strictly separate parameters and paths (`--` is not supported here)
|
||||||
evtypeStderr
|
cmd := exec.Command(`/usr/bin/sqlite3`, `-noheader`, `-json`, databasePath)
|
||||||
evtypeExit
|
return execEvents(cmd)
|
||||||
)
|
|
||||||
|
|
||||||
type processEvent struct {
|
|
||||||
evtype int
|
|
||||||
data []byte
|
|
||||||
err error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pe processEvent) Error() string {
|
func execEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
|
||||||
if pe.err != nil {
|
|
||||||
return pe.err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
if pe.evtype == evtypeStderr {
|
|
||||||
return string(pe.data)
|
|
||||||
}
|
|
||||||
|
|
||||||
return "<no error>"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pe processEvent) Unwrap() error {
|
|
||||||
return pe.err
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
|
|
||||||
|
|
||||||
pw, err := cmd.StdinPipe()
|
pw, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -58,58 +33,5 @@ func ExecEvents(cmd *exec.Cmd) (<-chan processEvent, io.WriteCloser, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
chEvents := make(chan processEvent, 0)
|
return handleEvents(pw, pr, pe, cmd.Wait)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
processEventWorker(pr, evtypeStdout, chEvents)
|
|
||||||
}()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
processEventWorker(pe, evtypeStderr, chEvents)
|
|
||||||
}()
|
|
||||||
wg.Add(2)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
// Only call cmd.Wait() after pipes are closed
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
err = cmd.Wait()
|
|
||||||
chEvents <- processEvent{
|
|
||||||
evtype: evtypeExit,
|
|
||||||
err: err,
|
|
||||||
}
|
|
||||||
|
|
||||||
close(chEvents)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return chEvents, pw, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func processEventWorker(p io.Reader, evtype int, dest chan<- processEvent) {
|
|
||||||
for {
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, err := p.Read(buf)
|
|
||||||
|
|
||||||
if n > 0 {
|
|
||||||
dest <- processEvent{
|
|
||||||
evtype: evtype,
|
|
||||||
data: buf[0:n],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
dest <- processEvent{
|
|
||||||
evtype: evtype,
|
|
||||||
err: err,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume all errors are permanent
|
|
||||||
// Ordering can produce either io.EOF, ErrClosedPipe, or PathError{"file already closed"}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
func TestEventCmd(t *testing.T) {
|
func TestEventCmd(t *testing.T) {
|
||||||
cmd := exec.Command("/bin/bash", "-c", `echo "hello world"`)
|
cmd := exec.Command("/bin/bash", "-c", `echo "hello world"`)
|
||||||
|
|
||||||
ch, _, err := ExecEvents(cmd)
|
ch, _, err := execEvents(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ func TestEventCmd(t *testing.T) {
|
|||||||
func TestEventCmdStdin(t *testing.T) {
|
func TestEventCmdStdin(t *testing.T) {
|
||||||
cmd := exec.Command("/usr/bin/tr", "a-z", "A-Z")
|
cmd := exec.Command("/usr/bin/tr", "a-z", "A-Z")
|
||||||
|
|
||||||
ch, pw, err := ExecEvents(cmd)
|
ch, pw, err := execEvents(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
94
sqliteclidriver/eventssh.go
Normal file
94
sqliteclidriver/eventssh.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package sqliteclidriver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SSHEvents(cl *ssh.Client, databasePath string) (<-chan processEvent, io.WriteCloser, error) {
|
||||||
|
// Client must have already been Dial()'ed
|
||||||
|
|
||||||
|
ses, err := cl.NewSession()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("NewSession: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pw, err := ses.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("StdinPipe: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pr, err := ses.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("StdoutPipe: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pe, err := ses.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("StderrPipe: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME use accurate Bash escaping
|
||||||
|
// TODO find a way to strictly separate parameters and paths (`--` is not supported here)
|
||||||
|
ses.Start(`/usr/bin/sqlite3 -noheader -json "` + strconv.Quote(databasePath) + `"`)
|
||||||
|
|
||||||
|
return handleEvents(pw, pr, pe, ses.Wait)
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type sshDriver struct {
|
||||||
|
cl *ssh.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *sshDriver) Open(connectionString string) (driver.Conn, error) {
|
||||||
|
// TODO support custom binpath from our connection string
|
||||||
|
chEvents, pw, err := SSHEvents(d.cl, connectionString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SCConn{
|
||||||
|
listen: chEvents,
|
||||||
|
w: pw,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Driver = &sshDriver{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
type sshConnector struct {
|
||||||
|
connectionString string
|
||||||
|
driver *sshDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *sshConnector) Connect(context.Context) (driver.Conn, error) {
|
||||||
|
// FIXME support context
|
||||||
|
return c.driver.Open(c.connectionString)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *sshConnector) Driver() driver.Driver {
|
||||||
|
return c.driver
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ driver.Connector = &sshConnector{} // interface assertion
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
// OpenSSH opens an sql.DB connection over SSH using the supplied ssh.Client
|
||||||
|
// object.
|
||||||
|
func OpenSSH(cl *ssh.Client, databasePath string) *sql.DB {
|
||||||
|
return sql.OpenDB(&sshConnector{
|
||||||
|
connectionString: databasePath,
|
||||||
|
driver: &sshDriver{
|
||||||
|
cl: cl,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -21,25 +21,25 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"qbolt/lexer"
|
"qbolt/lexer"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DriverName = `sqliteclidriver`
|
||||||
|
|
||||||
var ErrNotSupported = errors.New("Not supported")
|
var ErrNotSupported = errors.New("Not supported")
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// SCDriver is a thing that can open connections to the database for a given
|
||||||
|
// connection string. It has no particular state.
|
||||||
type SCDriver struct{}
|
type SCDriver struct{}
|
||||||
|
|
||||||
func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
|
func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
|
||||||
// TODO support custom binpath from our connection string
|
// TODO support custom binpath from our connection string
|
||||||
|
chEvents, pw, err := LocalBinEvents(connectionString)
|
||||||
cmd := exec.Command(`/usr/bin/sqlite3`, `-noheader`, `-json`, connectionString) // n.b. doesn't support `--`
|
|
||||||
|
|
||||||
chEvents, pw, err := ExecEvents(cmd)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -53,17 +53,21 @@ func (d *SCDriver) Open(connectionString string) (driver.Conn, error) {
|
|||||||
var _ driver.Driver = &SCDriver{} // interface assertion
|
var _ driver.Driver = &SCDriver{} // interface assertion
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
sql.Register("sqliteclidriver", &SCDriver{})
|
sql.Register(DriverName, &SCDriver{})
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// SCConnector is a container holding a driver and connection string together.
|
||||||
|
// It is the result of parsing a sql.Open(driverName, connectionString) call
|
||||||
|
// and has not parsed anything.
|
||||||
type SCConnector struct {
|
type SCConnector struct {
|
||||||
connectionString string
|
connectionString string
|
||||||
driver *SCDriver
|
driver *SCDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SCConnector) Connect(context.Context) (driver.Conn, error) {
|
func (c *SCConnector) Connect(context.Context) (driver.Conn, error) {
|
||||||
|
// FIXME support context
|
||||||
return c.driver.Open(c.connectionString)
|
return c.driver.Open(c.connectionString)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ var _ driver.Connector = &SCConnector{} // interface assertion
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// SCConn represents a single, active, open, connection to the database.
|
||||||
type SCConn struct {
|
type SCConn struct {
|
||||||
listen <-chan processEvent
|
listen <-chan processEvent
|
||||||
w io.WriteCloser
|
w io.WriteCloser
|
||||||
|
|||||||
12
sshTunnel.go
12
sshTunnel.go
@@ -21,24 +21,24 @@ type SSHTunnel struct {
|
|||||||
Type autoconfig.OneOf
|
Type autoconfig.OneOf
|
||||||
Password *struct {
|
Password *struct {
|
||||||
Password autoconfig.Password
|
Password autoconfig.Password
|
||||||
}
|
} `yicon:":/assets/key.png" json:",omitempty"`
|
||||||
PrivateKeyExternal *struct {
|
PrivateKeyExternal *struct {
|
||||||
PrivateKeyFile autoconfig.ExistingFile `ylabel:"Private Key"`
|
PrivateKeyFile autoconfig.ExistingFile `ylabel:"Private Key"`
|
||||||
PrivateKeyFilePassword autoconfig.Password `ylabel:"Password (optional)"`
|
PrivateKeyFilePassword autoconfig.Password `ylabel:"Password (optional)"`
|
||||||
} `ylabel:"Private key (External)"`
|
} `ylabel:"Private key (External)" yicon:":/assets/page_key.png" json:",omitempty"`
|
||||||
PrivateKeyInternal *struct {
|
PrivateKeyInternal *struct {
|
||||||
PrivateKeyContent autoconfig.MultiLineString `ylabel:"Private Key"`
|
PrivateKeyContent autoconfig.MultiLineString `ylabel:"Private Key"`
|
||||||
PrivateKeyContentPassword autoconfig.Password `ylabel:"Password (optional)"`
|
PrivateKeyContentPassword autoconfig.Password `ylabel:"Password (optional)"`
|
||||||
} `ylabel:"Private key (Internal)"`
|
} `ylabel:"Private key (Internal)" yicon:":/assets/page_key.png" json:",omitempty"`
|
||||||
SSHAgent *sshAgentConn `ylabel:"SSH Agent"`
|
SSHAgent *sshAgentConn `ylabel:"SSH Agent" yicon:":/assets/vendor_ssh.png" json:",omitempty"`
|
||||||
}
|
}
|
||||||
H2 autoconfig.Header `ylabel:"Server host key:" json:",omitempty"`
|
H2 autoconfig.Header `ylabel:"Server host key:" json:",omitempty"`
|
||||||
HostVerification struct {
|
HostVerification struct {
|
||||||
Type autoconfig.OneOf
|
Type autoconfig.OneOf
|
||||||
InsecureSkipVerify *struct{}
|
InsecureSkipVerify *struct{} `json:",omitempty"`
|
||||||
ExternalKnownHostsFile *struct {
|
ExternalKnownHostsFile *struct {
|
||||||
Path autoconfig.ExistingFile
|
Path autoconfig.ExistingFile
|
||||||
}
|
} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user