()
| 11 | var graph Graph |
| 12 | |
| 13 | func createGraph() { |
| 14 | conn, _ := redis.Dial("tcp", "0.0.0.0:6379") |
| 15 | conn.Do("FLUSHALL") |
| 16 | graph = GraphNew("social", conn) |
| 17 | |
| 18 | // Create 2 nodes connect via a single edge. |
| 19 | japan := NodeNew("Country", "j", nil) |
| 20 | john := NodeNew("Person", "p", nil) |
| 21 | edge := EdgeNew("Visited", john, japan, nil) |
| 22 | |
| 23 | // Set node properties. |
| 24 | john.SetProperty("name", "John Doe") |
| 25 | john.SetProperty("age", 33) |
| 26 | john.SetProperty("gender", "male") |
| 27 | john.SetProperty("status", "single") |
| 28 | |
| 29 | japan.SetProperty("name", "Japan") |
| 30 | japan.SetProperty("population", 126800000) |
| 31 | |
| 32 | edge.SetProperty("year", 2017) |
| 33 | |
| 34 | // Introduce entities to graph. |
| 35 | graph.AddNode(john) |
| 36 | graph.AddNode(japan) |
| 37 | graph.AddEdge(edge) |
| 38 | |
| 39 | // Flush graph to DB. |
| 40 | _, err := graph.Commit() |
| 41 | if err != nil { |
| 42 | panic(err) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func setup() { |
| 47 | createGraph() |
no test coverage detected