-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcypher.go
54 lines (43 loc) · 1.04 KB
/
cypher.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
package neo4j
import "encoding/json"
// Cypher struct
type Cypher struct {
Query map[string]string
Payload interface{}
}
// CypherResponse struct for the Neo4J cyhpher query response
type CypherResponse struct {
Columns map[string]interface{} `json:"columns"`
Data map[string]interface{} `json:"data"`
}
func (c *Cypher) mapBatchResponse(neo4j *Neo4j, data interface{}) (bool, error) {
encodedData, err := jsonEncode(data)
err = c.decodeResponse(encodedData)
if err != nil {
return false, err
}
return true, nil
}
func (c *Cypher) getBatchQuery(operation string) (map[string]interface{}, error) {
return map[string]interface{}{
"method": "POST",
"to": "/cypher",
"body": c.Query,
}, nil
}
func (c *Cypher) decodeResponse(data string) error {
resp := map[string]interface{}{}
err := json.Unmarshal([]byte(data), &resp)
if err != nil {
return err
}
jsonizedData, err := json.Marshal(resp)
if err != nil {
return err
}
err = json.Unmarshal(jsonizedData, &c.Payload)
if err != nil {
return err
}
return nil
}