Skip to content

Commit 5d5445a

Browse files
committed
better handling of an empty result-set
1 parent 6c9a1b6 commit 5d5445a

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

redisgraph/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def __str__(self):
5353

5454
return res
5555

56-
5756
class Edge(object):
5857
"""
5958
An edge connecting two nodes.
@@ -144,12 +143,9 @@ def query(self, q):
144143
result_set = None
145144
response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q)
146145

147-
if len(response) == 1:
148-
statistics = response[0]
149-
else:
150-
data = response[0]
151-
statistics = response[1]
152-
result_set = [res.decode().split(',') for res in data]
146+
data = response[0]
147+
statistics = response[1]
148+
result_set = [res.decode().split(',') for res in data]
153149

154150
return QueryResult(result_set, statistics)
155151

redisgraph/query_result.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, result_set, statistics):
2424
3. Prints the statistics of the query.
2525
"""
2626
def pretty_print(self):
27-
if self.result_set is not None:
27+
if not self.is_empty():
2828
tbl = PrettyTable(self.result_set[0])
2929
for row in self.result_set[1:]:
3030
tbl.add_row(row)
@@ -37,6 +37,9 @@ def pretty_print(self):
3737
for stat in self.statistics:
3838
print(stat)
3939

40+
def is_empty(self):
41+
return len(self.result_set) == 0
42+
4043
def _retrieve_data_from_statistics(self, statistics):
4144
return {
4245
self.LABELS_ADDED: self._get_value(self.LABELS_ADDED, statistics),

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22
setup(
33
name='redisgraph',
4-
version='1.2',
4+
version='1.3',
55

66
description='RedisGraph Python Client',
77
url='https://github.com/swilly22/redisgraph-py',

0 commit comments

Comments
 (0)