Skip to content

Commit 5bbb6c3

Browse files
support dict as a parameter value
1 parent bb300e1 commit 5bbb6c3

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

redisgraph/graph.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,25 @@ def _build_params_header(self, params):
162162
# Header starts with "CYPHER"
163163
params_header = "CYPHER "
164164
for key, value in params.items():
165-
# If value is string add quotation marks.
166-
if isinstance(value, str):
167-
value = quote_string(value)
168-
# Value is None, replace with "null" string.
169-
elif value is None:
170-
value = "null"
171-
params_header += str(key) + "=" + str(value) + " "
165+
params_header += str(key) + "=" + str(self._parse_value(value)) + " "
172166
return params_header
173167

168+
def _parse_value(self, value):
169+
# If value is string add quotation marks.
170+
if isinstance(value, str):
171+
value = quote_string(value)
172+
# If value is dictionary, need to remove quotation mark
173+
elif isinstance(value, dict):
174+
temp_value = "{"
175+
for key, val in value.items():
176+
temp_value += str(key) + ":" + str(val) + ","
177+
value = temp_value[:-1] + "}"
178+
# Value is None, replace with "null" string.
179+
elif value is None:
180+
value = "null"
181+
182+
return value
183+
174184
def query(self, q, params=None, timeout=None, read_only=False):
175185
"""
176186
Executes a query against the graph.

0 commit comments

Comments
 (0)