-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.txt
141 lines (72 loc) · 3.16 KB
/
README.txt
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Graphology-go is a persistent graph database written in Golang. It uses Gremlin type Queries to query the Graph database.
Installing Graphology-go :
go get github.com/geekskool/graphology-go
Use Graphology-go :
import "github.com/geekskool/graphology-go"
Getting started :
0 . How to do the setup for database?
===>
//set root directory for db files
graphology.SetPath("./path/to/database/")
1 . How to create a new empty database ?
===>
//factory function for creating an empty graph(database)
graph, err := graphology.CreateGraph("greekmythology")
note: The name of the graph is the name of the database with an extension of .db
eg : above graph will be saved as "greekmythology.db"
2 . How to load or open an existing database?
===>
//restore(retrieve) a database from a file
graph, err = graphology.Open("greekmythology.db")
note: make sure the path to the database is set. ( Getting Started 0)
3 . How to list all the available databases?
===>
dblst := graphology.ListAllDBs()
4 . How to Create a graph?
===>
graph, err := graphology.CreateGraph("greekmythology")
Creating a graph is same as creating a database.
5 . How to create a new vertex and set its value?
===>
eg: var v1 Vertex //create a variable of type Vertex
v1.Name = "jupiter" // set value of the Fields
v.Label = "god"
...
6 . How to add a vertex to the graph?
===>
id, err := graph.AddVertex(v1) // takes a Vertex variable as argument
note : you can also add array of Vertices to the Graph
_, errs := graph.AddVertices(vertices) // vertices is an array of Vertex ([]Vertex)
7 . How to create a new edge and set its value?
===>
var e1 Edge // create a variable of type Edge
e1.Id = "father" // set value of the Fields
...
8 . How to add an edge to the graph?
===>
id, err := g.AddEdge(e1) // takes Edge variable as an argument
note : you can also add array of Edges to the Graph
_, errs := graph.AddEdges(edges) // edges = []Edge
9 . How to save the graph?
===>
err = graph.Save() // saves graph as name.db in the path set
10 . How to initialize a Query?
===>
var query *graphology.Query // create a variable of type query
query = graph.V(name) // set the query to start with some Vertex with name "name"
11 . Different Queries?
===>
* graph.Query("hydra").In("battled").Values() // In() -- incoming Edges
* graph.Query("jupiter").Out("lives").Values() // Out() -- outgoing Edges
* graph.Query("jupiter").In("father").Out("battled").In("pet").Out("lives").Values() // In(), Out()
// Unique() --- all Unique results
// Take(5) --- take first 5 resuts
// Except("jupiter") --- keep all Vertices in result except "jupiter" Vertex
* graph.Query("hercules").Out("father").Out("brother").Out("brother").Unique().Take(2).Except("jupiter").Value()
// Filter(fn) : takes a function defined by the User. and Filters out result accordingly
graph.Query("hercules").Out("father").Out("brother").Out("brother").Unique().Take(2).Except("jupi").filter(func(v Vertex) bool {
if v.Props["age"] == 5000 {
return true
}
return false
}).Value