@@ -13,6 +13,10 @@ class Graph:
13
13
def __init__ (self , name , redis_con = None , host = 'localhost' , port = 6379 , password = None ):
14
14
"""
15
15
Create a new graph.
16
+
17
+ Args:
18
+ name: string that represents the name of the graph
19
+ redis_con: connection to Redis
16
20
"""
17
21
self .name = name # Graph key
18
22
if redis_con is not None :
@@ -63,6 +67,12 @@ def _refresh_attributes(self):
63
67
self ._properties [i ] = p [0 ]
64
68
65
69
def get_label (self , idx ):
70
+ """
71
+ Returns a label by it's index
72
+
73
+ Args:
74
+ idx: The index of the label
75
+ """
66
76
try :
67
77
label = self ._labels [idx ]
68
78
except IndexError :
@@ -72,6 +82,12 @@ def get_label(self, idx):
72
82
return label
73
83
74
84
def get_relation (self , idx ):
85
+ """
86
+ Returns a relationship type by it's index
87
+
88
+ Args:
89
+ idx: The index of the relation
90
+ """
75
91
try :
76
92
relationshipType = self ._relationshipTypes [idx ]
77
93
except IndexError :
@@ -81,6 +97,12 @@ def get_relation(self, idx):
81
97
return relationshipType
82
98
83
99
def get_property (self , idx ):
100
+ """
101
+ Returns a property by it's index
102
+
103
+ Args:
104
+ idx: The index of the property
105
+ """
84
106
try :
85
107
propertie = self ._properties [idx ]
86
108
except IndexError :
@@ -134,7 +156,7 @@ def flush(self):
134
156
self .nodes = {}
135
157
self .edges = []
136
158
137
- def build_params_header (self , params ):
159
+ def _build_params_header (self , params ):
138
160
if not isinstance (params , dict ):
139
161
raise TypeError ("'params' must be a dict" )
140
162
# Header starts with "CYPHER"
@@ -152,14 +174,20 @@ def build_params_header(self, params):
152
174
def query (self , q , params = None , timeout = None , read_only = False ):
153
175
"""
154
176
Executes a query against the graph.
177
+
178
+ Args:
179
+ q: the query
180
+ params: query parameters
181
+ timeout: maximum runtime for read queries in milliseconds
182
+ read_only: executes a readonly query if set to True
155
183
"""
156
184
157
185
# maintain original 'q'
158
186
query = q
159
187
160
188
# handle query parameters
161
189
if params is not None :
162
- query = self .build_params_header (params ) + query
190
+ query = self ._build_params_header (params ) + query
163
191
164
192
# construct query command
165
193
# ask for compact result-set format
@@ -200,9 +228,13 @@ def execution_plan(self, query, params=None):
200
228
"""
201
229
Get the execution plan for given query,
202
230
GRAPH.EXPLAIN returns an array of operations.
231
+
232
+ Args:
233
+ query: the query that will be executed
234
+ params: query parameters
203
235
"""
204
236
if params is not None :
205
- query = self .build_params_header (params ) + query
237
+ query = self ._build_params_header (params ) + query
206
238
207
239
plan = self .redis_con .execute_command ("GRAPH.EXPLAIN" , self .name , query , query )
208
240
return self ._execution_plan_to_string (plan )
0 commit comments