-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutil.go
61 lines (55 loc) · 1.07 KB
/
util.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
package psql
import (
"encoding/json"
"fmt"
"regexp"
"github.com/bmeg/grip/gdbi"
)
type Row struct {
Id string
Label string
From string
To string
Data []byte
}
func ConvertVertexRow(row *Row, load bool) (*gdbi.Vertex, error) {
props := make(map[string]interface{})
if load {
err := json.Unmarshal(row.Data, &props)
if err != nil {
return nil, fmt.Errorf("unmarshal error: %v", err)
}
}
v := &gdbi.Vertex{
ID: row.Id,
Label: row.Label,
Data: props,
Loaded: load,
}
return v, nil
}
func ConvertEdgeRow(row *Row, load bool) (*gdbi.Edge, error) {
props := make(map[string]interface{})
if load {
err := json.Unmarshal(row.Data, &props)
if err != nil {
return nil, fmt.Errorf("unmarshal error: %v", err)
}
}
e := &gdbi.Edge{
ID: row.Id,
Label: row.Label,
From: row.From,
To: row.To,
Data: props,
Loaded: load,
}
return e, nil
}
func dbDoesNotExist(err error) bool {
matched, err := regexp.MatchString(`database "[a-z_]+" does not exist`, err.Error())
if err != nil {
return false
}
return matched
}