Skip to content

added parameters support #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,24 @@ def flush(self):
self.nodes = {}
self.edges = []

def query(self, q):
def query(self, q, params=None):
"""
Executes a query against the graph.
"""
if params is not None:
assert type(params) == dict
params_header = "CYPHER "
for key, value in params.items():
if type(value) == str:
value = quote_string(value)
if value is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

value = "null"
params_header += str(key) + "=" + str(value) + " "
q = params_header + q
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining this logic.
Consider encapsulating this logic in a separated function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


statistics = None
result_set = None

response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q, "--compact")
return QueryResult(self, response)

Expand Down
13 changes: 13 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ def test_path(self):
# All done, remove graph.
redis_graph.delete()

def test_param(self):
redis_graph = Graph('params', self.r)

params = [1, 2.3, "str", True, False, None, [0, 1, 2]]

for param in params:
query = "RETURN $param"
result = redis_graph.query(query, {'param': param})
expected_results = [[param]]
self.assertEqual(expected_results, result.result_set)

# All done, remove graph.
redis_graph.delete()

if __name__ == '__main__':
unittest.main()