-
Notifications
You must be signed in to change notification settings - Fork 11
/
file_dialect.go
executable file
·77 lines (68 loc) · 1.79 KB
/
file_dialect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package dsc
import (
"fmt"
"net/url"
"path"
"strings"
)
type fileDialect struct {
DefaultDialect
}
//DropTable drops a table in datastore managed by passed in manager.
func (d fileDialect) DropTable(manager Manager, datastore string, table string) error {
fileManager, ok := manager.(*FileManager)
if !ok {
return fmt.Errorf("invalid store manager: %T, expected %T", &FileManager{}, manager)
}
tableURL := fileManager.getTableURL(manager, table)
exists, err := fileManager.service.Exists(tableURL)
if err != nil {
return err
}
if !exists {
return nil
}
object, err := fileManager.service.StorageObject(tableURL)
if err != nil {
return err
}
if object == nil {
return nil
}
return fileManager.service.Delete(object)
}
//GetTables return tables names for passed in datastore managed by passed in manager.
func (d fileDialect) GetTables(manager Manager, datastore string) ([]string, error) {
fileManager, ok := manager.(*FileManager)
if !ok {
return nil, fmt.Errorf("Invalid store manager: %T, expected %T", &FileManager{}, manager)
}
exists, err := fileManager.service.Exists(fileManager.baseURL.URL)
if err != nil {
return nil, err
}
if !exists {
return []string{}, nil
}
objects, err := fileManager.service.List(fileManager.baseURL.URL)
ext := "." + manager.Config().Get("ext")
var result = make([]string, 0)
for _, object := range objects {
if object.IsFolder() {
continue
}
parsedURL, err := url.Parse(object.URL())
if err != nil {
return nil, err
}
_, name := path.Split(parsedURL.Path)
if strings.HasSuffix(name, ext) {
result = append(result, name)
}
}
return result, nil
}
//GetCurrentDatastore returns url, base path
func (d fileDialect) GetCurrentDatastore(manager Manager) (string, error) {
return manager.Config().Get("url"), nil
}