Skip to content
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

added query params argument #140

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
19 changes: 11 additions & 8 deletions redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def flush(self):
self.edges = []

def _build_params_header(self, params):
if not isinstance(params, dict):
if isinstance(params, str):
#params is in header format use it as is
return params
elif not isinstance(params, dict):
raise TypeError("'params' must be a dict")
# Header starts with "CYPHER"
params_header = "CYPHER "
Expand Down Expand Up @@ -185,17 +188,17 @@ def query(self, q, params=None, timeout=None, read_only=False):
# maintain original 'q'
query = q

# handle query parameters
if params is not None:
query = self._build_params_header(params) + query

# construct query command
# ask for compact result-set format
# specify known graph version
cmd = "GRAPH.RO_QUERY" if read_only else "GRAPH.QUERY"
# command = [cmd, self.name, query, "--compact", "version", self.version]
command = [cmd, self.name, query, "--compact"]

# query params are specified
if params:
command += ["query_params", self._build_params_header(params)]

# include timeout is specified
if timeout:
if not isinstance(timeout, int):
Expand Down Expand Up @@ -234,9 +237,9 @@ def execution_plan(self, query, params=None):
params: query parameters
"""
if params is not None:
query = self._build_params_header(params) + query

plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query)
plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, "query_params", self._build_params_header(params))
else:
plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query)
return self._execution_plan_to_string(plan)

def delete(self):
Expand Down