77 "encoding/json"
88 "errors"
99 "fmt"
10- "log"
1110
1211 "github.com/arangodb/go-driver/v2/arangodb"
1312
@@ -26,11 +25,6 @@ type arangoDriver struct {
2625}
2726
2827func (a * arangoDriver ) ListDatabases () (current string , available []string , err error ) {
29- if a == nil || a .c == nil {
30- return "" , nil , errors .New ("arangoDriver is not initialized" )
31- }
32-
33- log .Print ("Fetching list of databases" )
3428 databases , err := a .c .AccessibleDatabases (context .Background ())
3529 if err != nil {
3630 return "" , nil , fmt .Errorf ("failed to list databases: %w" , err )
@@ -45,17 +39,11 @@ func (a *arangoDriver) ListDatabases() (current string, available []string, err
4539}
4640
4741func (a * arangoDriver ) SelectDatabase (name string ) error {
48- if a == nil {
49- return errors .New ("arangoDriver is not initialized" )
50- }
51- log .Printf ("Selecting database: %s" , name )
5242 a .dbName = name
5343 return nil
5444}
5545
56- func (a * arangoDriver ) Close () {
57- log .Print ("Closing connection (not yet implemented)" )
58- }
46+ func (a * arangoDriver ) Close () {}
5947
6048func (a * arangoDriver ) Columns (opts * core.TableOptions ) ([]* core.Column , error ) {
6149 db , err := a .c .GetDatabase (context .Background (), a .dbName , nil )
@@ -70,7 +58,7 @@ func (a *arangoDriver) Columns(opts *core.TableOptions) ([]*core.Column, error)
7058 COLLECT attribute = a WITH COUNT INTO len
7159 SORT len DESC
7260 LIMIT 10
73- sort attribute
61+ SORT attribute
7462 RETURN {attribute}`
7563
7664 bindVars := map [string ]any {"@col" : opts .Table }
@@ -89,7 +77,7 @@ func (a *arangoDriver) Columns(opts *core.TableOptions) ([]*core.Column, error)
8977 }
9078 column , ok := doc ["attribute" ].(string )
9179 if ! ok {
92- column = ""
80+ return nil , fmt . Errorf ( "failed to read document: %w" , err )
9381 }
9482 columns = append (columns , & core.Column {Type : "collection" , Name : column })
9583 }
@@ -131,14 +119,20 @@ func (a *arangoDriver) Query(ctx context.Context, query string) (core.ResultStre
131119}
132120
133121func (a * arangoDriver ) Structure () ([]* core.Structure , error ) {
134- if a == nil || a .c == nil {
135- return nil , errors .New ("arangoDriver is not initialized" )
136- }
137-
138122 ctx := context .Background ()
139- databases , err := a .c .Databases (ctx )
140- if err != nil {
141- return nil , fmt .Errorf ("failed to list databases: %w" , err )
123+ databases := []arangodb.Database {}
124+ err := errors .New ("database not selected" )
125+ if a .dbName == "_system" { // if the database is _system, we'll walk all databases
126+ databases , err = a .c .Databases (ctx )
127+ if err != nil {
128+ return nil , fmt .Errorf ("failed to list databases: %w" , err )
129+ }
130+ } else {
131+ database , err := a .c .GetDatabase (ctx , a .dbName , nil )
132+ if err != nil {
133+ return nil , fmt .Errorf ("failed to get database: %w" , err )
134+ }
135+ databases = []arangodb.Database {database }
142136 }
143137
144138 structures := make ([]* core.Structure , len (databases ))
0 commit comments