ArangoDB

Module "graph"

The graph module provides basic functions dealing with graph structures. The examples assume

arango> var Graph = require("graph").Graph;

arango> g = new Graph("graph", "vertices", "edges");
Graph("graph")

  1. Graph Constructors and Methods
    1. Graph.addEdge
    2. Graph.addVertex
    3. Graph constructor
    4. Graph.getEdges
    5. Graph.getVertex
    6. Graph.getVertices
    7. Graph.removeEdge
    8. Graph.removeVertex
    9. Graph.drop
  2. Vertex Methods
    1. Vertex.addInEdge
    2. Vertex.addOutEdge
    3. Vertex.edges
    4. Vertex.getId
    5. Vertex.getInEdges
    6. Vertex.getOutEdges
    7. Vertex.getProperty
    8. Vertex.getPropertyKeys
    9. Vertex.properties
    10. Vertex.setProperty
  3. Edge Methods
    1. Edge.getId
    2. Edge.getInVertex
    3. Edge.getLabel
    4. Edge.getOutVertex
    5. Edge.getProperty
    6. Edge.getPropertyKeys
    7. Edge.properties
    8. Edge.setProperty

Graph Constructors and Methods


Graph(name, vertices, edges)
Constructs a new graph object using the collection vertices for all vertices and the collection edges for all edges. Note that it is possible to construct two graphs with the same vertex set, but different edge sets.


Graph(name)
Returns a known graph.

Examples

arango> var Graph = require("graph").Graph;

arango> new Graph("graph", db.vertices, db.edges);
Graph("graph")

arango> new Graph("graph", "vertices", "edges");
Graph("graph")


graph.addEdge(out, in, id)
Creates a new edge from out to in and returns the edge object. The identifier id must be a unique identifier or null.


graph.addEdge(out, in, id, label)
Creates a new edge from out to in with label and returns the edge object.


graph.addEdge(out, in, id, data)
Creates a new edge and returns the edge object. The edge contains the properties defined in data.


graph.addEdge(out, in, id, label, data)
Creates a new edge and returns the edge object. The edge has the label label and contains the properties defined in data.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(2);
Vertex(2)

arango> e = g.addEdge(v1, v2, 3);
Edge(3)
arango> e = g.addEdge(v1, v2, 4, "1->2", { name : "Emil");
Edge(4)


graph.addVertex(id)
Creates a new vertex and returns the vertex object. The identifier id must be a unique identifier or null.


graph.addVertex(id, data)
Creates a new vertex and returns the vertex object. The vertex contains the properties defined in data.

Examples

Without any properties:

arango> v = g.addVertex("hugo");
Vertex("hugo")

With given properties:

arango> v = g.addVertex("Emil", { age : 123 });
Vertex("Emil")

arango> v.getProperty("age");
123


graph.getEdges()
Returns an iterator for all edges of the graph. The iterator supports the methods hasNext and next.

Examples

arango> f = g.getEdges();
[edge iterator]

arango> f.hasNext();
true

arango> e = f.next();
Edge(<graph>, "2141724:4636053")


graph.getVertex(id)
Returns the vertex identified by id or null.

Examples

arango> g.addVertex(1);
Vertex(1)

arango> g.getVertex(1)
Vertex(1)


graph.getVertices()
Returns an iterator for all vertices of the graph. The iterator supports the methods hasNext and next.

Examples

arango> f = g.getVertices();
[vertex iterator]

arango> f.hasNext();
true

arango> v = f.next();
Vertex(18364)


graph.removeVertex(vertex)
Deletes the vertex and all its edges.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(2);
Vertex(2)

arango> e = g.addEdge(v1, v2, 3);
Edge(3)

arango> g.removeVertex(v1);

arango> v2.edges();
[ ]


graph.removeEdge(vertex)
Deletes the edge. Note that the in and out vertices are left untouched.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(2);
Vertex(2)

arango> e = g.addEdge(v1, v2, 3);
Edge(3)

arango> g.removeEdge(e);

arango> v2.edges();
[ ]


graph.drop()
Drops the graph, the vertices, and the edges. Handle with care.

Vertex Methods


vertex.addInEdge(peer, id)
Creates a new edge from peer to vertex and returns the edge object. The identifier id must be a unique identifier or null.


vertex.addInEdge(peer, id, label)
Creates a new edge from peer to vertex with given label and returns the edge object.


vertex.addInEdge(peer, id, label, data)
Creates a new edge from peer to vertex with given label and properties defined in data. Returns the edge object.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(2);
Vertex(2)

arango> v1.addInEdge(v2, "2 -> 1");
Edge("2 -> 1")

arango> v1.getInEdges();
[ Edge("2 -> 1") ]
arango> v1.addInEdge(v2, "D", "knows", { data : 1 });
Edge("D")

arango> v1.getInEdges();
[ Edge("K"), Edge("2 -> 1"), Edges("D") ]


vertex.addOutEdge(peer)
Creates a new edge from vertex to peer and returns the edge object.


vertex.addOutEdge(peer, label)
Creates a new edge from vertex to peer with given label and returns the edge object.


vertex.addOutEdge(peer, label, data)
Creates a new edge from vertex to peer with given label and properties defined in data. Returns the edge object.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(2);
Vertex(2)

arango> v1.addOutEdge(v2, "1->2");
Edge("1->2")

arango> v1.getOutEdges();
[ Edge(1->2") ]
arango> v1.addOutEdge(v2, 3, "knows");
Edge(3)
arango> v1.addOutEdge(v2, 4, "knows", { data : 1 });
Edge(4)


vertex.edges()
Returns a list of in- or outbound edges of the vertex.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> v2 = g.addVertex(); 
Vertex(2)

arango> e = g.addEdge(v1, v2, "1->2");
Edge("1->2")

arango> v1.edges();
[  Edge("1->2") ]

arango> v2.edges();
[  Edge("1->2") ]


vertex.getId()
Returns the identifier of the vertex. If the vertex was deleted, then undefined is returned.

Examples

arango> v = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v.getId();
"1"


vertex.getInEdges(label, ...)
Returns a list of inbound edges of the vertex with given label(s).

Examples

arango> v1 = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v2 = g.addVertex(2, { name : "Emil" }); 
Vertex(2)

arango> e1 = g.addEdge(v1, v2, 3, "knows");
Edge(3)

arango> e2 = g.addEdge(v1, v2, 4, "hates");
Edge(4)

arango> v2.getInEdges();
[ Edge(3), Edge(4) ]

arango> v2.getInEdges("knows");
[ Edge(3) ]

arango> v2.getInEdges("hates");
[ Edge(4) ]

arango> v2.getInEdges("knows", "hates");
[ Edge(3), Edge(4) ]


vertex.getOutEdges(label, ...)
Returns a list of outbound edges of the vertex with given label(s).

Examples

arango> v1 = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v2 = g.addVertex(2, { name : "Emil" }); 
Vertex(2)

arango> e1 = g.addEdge(v1, v2, 3, "knows");
Edge(3)

arango> e2 = g.addEdge(v1, v2, 4, "hates");
Edge(4)

arango> v1.getInEdges();
[ Edge(3), Edge(4) ]

arango> v1.getInEdges("knows");
[ Edge(3) ]

arango> v1.getInEdges("hates");
[ Edge(4) ]

arango> v1.getInEdges("knows", "hates");
[ Edge(3), Edge(4) ]


vertex.getProperty(name)
Returns the property name a vertex.

Examples

arango> v = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v.getProperty("name");
Hugo


vertex.getPropertyKeys()
Returns all propety names a vertex.

Examples

arango> v = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v.getPropertyKeys();
[ "name" ]

arango> v.setProperty("email", "hugo@hugo.de");
"hugo@hugo.de"

arango> v.getPropertyKeys();
[ "name", "email" ]


vertex.properties()
Returns all properties and their values of a vertex

Examples

arango> v = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v.properties();
{ name : "Hugo" }


vertex.setProperty(name, value)
Changes or sets the property name a vertex to value.

Examples

arango> v = g.addVertex(1, { name : "Hugo" });
Vertex(1)

arango> v.getProperty("name");
"Hugo"

arango> v.setProperty("name", "Emil");
"Emil"

arango> v.getProperty("name");
"Emil"

Edge Methods


edge.getId()
Returns the identifier of the edge.

Examples

arango> v = g.addVertex("v");
Vertex("v")

arango> e = g.addEdge(v, v, 1, "self");
Edge(1)

arango> e.getId();
1


edge.getInVertex()
Returns the vertex at the head of the edge.

Examples

arango> v1 = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "self");
Edge(2)

arango> e.getInVertex();
Vertex(1)


edge.getLabel()
Returns the label of the edge.

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "knows");
Edge(2)

arango> e.getLabel();
knows


edge.getOutVertex()
Returns the vertex at the tail of the edge.

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "self");
Edge(2)

arango> e.getOutVertex();
Vertex(1)


edge.getProperty(name)
Returns the property name an edge.

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "self", { "weight" : 10 });
Edge(2)

arango> e.getProperty("weight");
10


edge.getPropertyKeys()
Returns all propety names an edge.

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "self", { weight: 10 })
Edge(2)

arango> e.getPropertyKeys()
[ "weight" ]

arango> e.setProperty("name", "Hugo");
Hugo

arango> e.getPropertyKeys()
[ "weight", "name" ]


edge.properties()
Returns all properties and their values of an edge

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "knows");
Edge(2)

arango> e.properties();
{ "weight" : 10 }


edge.setProperty(name, value)
Changes or sets the property name an edges to value.

Examples

arango> v = g.addVertex(1);
Vertex(1)

arango> e = g.addEdge(v, v, 2, "self", { weight: 10 })
Edge(2)

arango> e.getPropert("weight")
10

arango> e.setProperty("weight", 20);
20

arango> e.getPropert("weight")
20