app: upcast loadedDatabase to more specific interfaces
This commit is contained in:
parent
6dd0635c9e
commit
7573cf0453
@ -83,10 +83,6 @@ func (ld *badgerLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *badgerLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
// In the Badger implementation, there is only one child: "Data"
|
||||
if len(ndata.bucketPath) == 0 {
|
||||
@ -102,10 +98,6 @@ func (ld *badgerLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) Close() {
|
||||
_ = ld.db.Close()
|
||||
ld.arena = nil
|
||||
|
@ -192,10 +192,6 @@ func (ld *boltLoadedDatabase) DeleteBucket(sender vcl.IComponent, ndata *navData
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) Close() {
|
||||
_ = ld.db.Close()
|
||||
ld.arena = nil
|
||||
|
@ -70,10 +70,6 @@ func (ld *debconfLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *debconfLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *debconfLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
// In the debconf implementation, there is only one child: "Data"
|
||||
if len(ndata.bucketPath) == 0 {
|
||||
@ -89,10 +85,6 @@ func (ld *debconfLoadedDatabase) NavContext(ndata *navData) ([]contextAction, er
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *debconfLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *debconfLoadedDatabase) Close() {
|
||||
ld.arena = nil
|
||||
}
|
||||
|
@ -23,14 +23,6 @@ func (n *noLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
@ -74,10 +74,6 @@ func (ld *pebbleLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *pebbleLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
// In the pebble implementation, there is only one child: "Data"
|
||||
if len(ndata.bucketPath) == 0 {
|
||||
@ -93,10 +89,6 @@ func (ld *pebbleLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) Close() {
|
||||
_ = ld.db.Close()
|
||||
ld.arena = nil
|
||||
|
@ -132,10 +132,6 @@ func (ld *redisLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) error
|
||||
}
|
||||
}
|
||||
|
||||
func (n *redisLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *redisLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
// ctx := context.Background()
|
||||
|
||||
|
@ -100,10 +100,6 @@ func (ld *sqliteLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) error
|
||||
|
||||
}
|
||||
|
||||
func (n *sqliteLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return ErrNotSupported
|
||||
}
|
||||
|
||||
func (ld *sqliteLoadedDatabase) sqliteGetColumnNamesForTable(tableName string) ([]string, error) {
|
||||
colr, err := ld.db.Query(`SELECT name FROM pragma_table_info( ? )`, tableName)
|
||||
if err != nil {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
var ErrNavNotExist error = errors.New("The selected item no longer exists")
|
||||
var ErrNotSupported error = errors.New("Unsupported action for this database type")
|
||||
|
||||
type contextAction struct {
|
||||
Name string
|
||||
@ -20,14 +19,20 @@ type loadedDatabase interface {
|
||||
DriverName() string
|
||||
RootElement() *vcl.TTreeNode
|
||||
RenderForNav(f *TMainForm, ndata *navData) error
|
||||
ApplyChanges(f *TMainForm, ndata *navData) error
|
||||
ExecQuery(query string, resultArea *vcl.TStringGrid) error
|
||||
NavChildren(ndata *navData) ([]string, error)
|
||||
NavContext(ndata *navData) ([]contextAction, error)
|
||||
Keepalive(ndata *navData)
|
||||
Close()
|
||||
}
|
||||
|
||||
type queryableLoadedDatabase interface {
|
||||
ExecQuery(query string, resultArea *vcl.TStringGrid) error
|
||||
}
|
||||
|
||||
type editableLoadedDatabase interface {
|
||||
ApplyChanges(f *TMainForm, ndata *navData) error
|
||||
}
|
||||
|
||||
// navData is the .Data() pointer for each TTreeNode in the left-hand tree.
|
||||
type navData struct {
|
||||
ld loadedDatabase
|
||||
|
18
main.go
18
main.go
@ -668,7 +668,14 @@ func (f *TMainForm) OnDataCommitClick(sender vcl.IObject) {
|
||||
scrollPos := f.contentBox.TopRow()
|
||||
|
||||
ndata := (*navData)(node.Data())
|
||||
err := ndata.ld.ApplyChanges(f, ndata)
|
||||
|
||||
editableLd, ok := ndata.ld.(editableLoadedDatabase)
|
||||
if !ok {
|
||||
vcl.ShowMessage("Unsupported action for this database")
|
||||
return
|
||||
}
|
||||
|
||||
err := editableLd.ApplyChanges(f, ndata)
|
||||
if err != nil {
|
||||
vcl.ShowMessage(err.Error())
|
||||
}
|
||||
@ -757,7 +764,14 @@ func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
||||
}
|
||||
|
||||
ndata := (*navData)(node.Data())
|
||||
err := ndata.ld.ExecQuery(queryString, f.queryResult)
|
||||
|
||||
queryableLd, ok := ndata.ld.(queryableLoadedDatabase)
|
||||
if !ok {
|
||||
vcl.ShowMessage("Unsupported action for this database")
|
||||
return
|
||||
}
|
||||
|
||||
err := queryableLd.ExecQuery(queryString, f.queryResult)
|
||||
if err != nil {
|
||||
vcl.ShowMessage(err.Error())
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user