Edges¶
An edge is an entity that represents a connection between two documents. The main idea of edges is that you can build your own graph (tree) between sets of documents and then perform searches within the document hierarchy.
In order to define a vertex, from_document and to_document should
be specified during the creation of the edge:
from arango import create
c = create()
c.test.create()
# create FROM document
from_doc = c.test.documents.create({
"sample_key": "sample_value"
})
# create TO document
to_doc = c.test.documents.create({
"sample_key1": "sample_value1"
})
# creating edge with custom data
c.test.edges.create(from_doc, to_doc, {"custom": 1})
Warning
Code below should be implemented by using AQL (AQL Queries).
Not implemented at the moment.
# getting edge by document
# c.test.edges(from_doc)
# getting with direction
# c.test.edges(from_doc, direction="in")
# assert c.test.edges(from_doc).first.from_document == from_doc
# assert c.test.edges(from_doc).first.to_document == to_doc
Edges for Collection instance¶
Edges are accessible via a collection instance, for example connection.collection.sample_collection.edges.
Usually this expressions looks lot shorter.
Basically via edges shortcut accessible Edges Proxy - Proxy object which have several shortcuts and produce Resultset object.
Below described basic method within Edges proxy:
Making queries¶
Warning
This functionality not implmented yet. Use AQL - AQL Queries section with custom wrapper to work with Edges.
More details in Edges REST Api documentation of ArangoDB
Edge¶
Edge instance methods consist from basic CRUD methods and additional methods specific obly for Edges:
-
class
arango.edge.Edge(collection=None, _id=None, _rev=None, _from=None, _to=None, **kwargs)¶ Edge instance object
-
body¶ This property return Edge content
-
create(from_doc, to_doc, body=None, **kwargs)¶ Method to create new edge.
from_docandto_docmay be both document-handle or instances ofDocumentobject.Possible arguments: waitForSync
Read more about additional arguments Edges REST Api
This method may raise EdgeAlreadyCreated exception in case edge already created.
Return edge instance (
self) orNone
-
delete()¶ Method to delete current edge. If edge deleted this method return
Trueand in other caseFalse
-
from_document¶ From vertex, return instance of
DocumentorNone
-
get(name=None, default=None)¶ This method very similar to
dict‘sgetmethod. The difference is that default value should be specified explicitly.To get specific value for specific key in body use and default (fallback) value
0:edge.get(name="sample_key", default=0)
-
save(**kwargs)¶ Method to save Edge. This is useful when edge udpated several times via
updatePossible arguments: waitForSync
Read more about additional arguments Edges REST Api
-
to_document¶ To vertex, return instance of
DocumentorNone
-
update(body, from_doc=None, to_doc=None, save=True, **kwargs)¶ Method to update edge. In case from_doc or do_doc not specified or equal to
Nonethen currentfrom_documentandto_documentwill be used.In case
saveargument set toFalseedge will not be updated untilsave()method will be called.This method may raise EdgeNotYetCreated exception in case you trying to update edge which is not saved yet.
Exception EdgeIncompatibleDataType will be raised in case body of the edge isn’t
dict.
-