@@ -60,6 +60,31 @@ class Graph(object):
6060 """
6161 Graph, collection of nodes and edges.
6262 """
63+
64+ class QueryResult (object ):
65+ def __init__ (self , result_set , statistics ):
66+ self .result_set = result_set
67+ self .statistics = statistics
68+
69+ """Prints the data from the query response:
70+ 1. First row result_set contains the columns names. Thus the first row in PrettyTable
71+ will contain the columns.
72+ 2. The row after that will contain the data returned, or 'No Data returned' if there is none.
73+ 3. Prints the statistics of the query.
74+ """
75+ def pretty_print (self ):
76+ tbl = PrettyTable (self .result_set [0 ])
77+ for row in self .result_set [1 :]:
78+ tbl .add_row (row )
79+
80+ if len (self .result_set ) == 1 :
81+ tbl .add_row (['No data returned.' ])
82+
83+ print (str (tbl ) + '\n ' )
84+
85+ for stat in self .statistics :
86+ print (stat )
87+
6388 def __init__ (self , name , redis_con ):
6489 """
6590 Create a new graph.
@@ -109,24 +134,10 @@ def query(self, q):
109134 Executes a query against the graph.
110135 """
111136 response = self .redis_con .execute_command ("GRAPH.QUERY" , self .name , q )
112- resultset = response [0 ]
137+ data = response [0 ]
113138 statistics = response [1 ]
114- columns = resultset [0 ].split ("," )
115- resultset = resultset [1 :]
116- tbl = PrettyTable (columns )
117-
118- for idx , result in enumerate (resultset ):
119- tbl .add_row (result .split ("," ))
120-
121- if len (resultset ) == 0 :
122- tbl .add_row (['No data returned.' ])
123-
124- print tbl
125-
126- for stat in statistics :
127- print stat
128-
129- return tbl
139+ result_set = [res .split (',' ) for res in data ]
140+ return self .QueryResult (result_set , statistics )
130141
131142 def execution_plan (self , query ):
132143 """
0 commit comments