Skip to content

API documentation #133

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
Jun 22, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion redisgraph/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, src_node, relation, dest_node, edge_id=None,
"""
Create a new edge.
"""
if (src_node is None or dest_node is None):
if src_node is None or dest_node is None:
# NOTE(bors-42): It makes sense to change AssertionError to
# ValueError here
raise AssertionError("Both src_node & dest_node must be provided")
Expand Down
38 changes: 35 additions & 3 deletions redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Graph:
def __init__(self, name, redis_con=None, host='localhost', port=6379, password=None):
"""
Create a new graph.

Args:
name: string that represents the name of the graph
redis_con: connection to Redis
"""
self.name = name # Graph key
if redis_con is not None:
Expand Down Expand Up @@ -63,6 +67,12 @@ def _refresh_attributes(self):
self._properties[i] = p[0]

def get_label(self, idx):
"""
Returns a label by it's index

Args:
idx: The index of the label
"""
try:
label = self._labels[idx]
except IndexError:
Expand All @@ -72,6 +82,12 @@ def get_label(self, idx):
return label

def get_relation(self, idx):
"""
Returns a relationship type by it's index

Args:
idx: The index of the relation
"""
try:
relationshipType = self._relationshipTypes[idx]
except IndexError:
Expand All @@ -81,6 +97,12 @@ def get_relation(self, idx):
return relationshipType

def get_property(self, idx):
"""
Returns a property by it's index

Args:
idx: The index of the property
"""
try:
propertie = self._properties[idx]
except IndexError:
Expand Down Expand Up @@ -134,7 +156,7 @@ def flush(self):
self.nodes = {}
self.edges = []

def build_params_header(self, params):
def _build_params_header(self, params):
if not isinstance(params, dict):
raise TypeError("'params' must be a dict")
# Header starts with "CYPHER"
Expand All @@ -152,14 +174,20 @@ def build_params_header(self, params):
def query(self, q, params=None, timeout=None, read_only=False):
"""
Executes a query against the graph.

Args:
q: the query
params: query parameters
timeout: maximum runtime for read queries in milliseconds
read_only: executes a readonly query if set to True
"""

# maintain original 'q'
query = q

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

# construct query command
# ask for compact result-set format
Expand Down Expand Up @@ -200,9 +228,13 @@ def execution_plan(self, query, params=None):
"""
Get the execution plan for given query,
GRAPH.EXPLAIN returns an array of operations.

Args:
query: the query that will be executed
params: query parameters
"""
if params is not None:
query = self.build_params_header(params) + query
query = self._build_params_header(params) + query

plan = self.redis_con.execute_command("GRAPH.EXPLAIN", self.name, query, query)
return self._execution_plan_to_string(plan)
Expand Down
2 changes: 1 addition & 1 deletion redisgraph/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Node:
"""
A node within the garph.
A node within the graph.
"""
def __init__(self, node_id=None, alias=None, label=None, properties=None):
"""
Expand Down