Skip to content

Commit e2de7fb

Browse files
committed
fixint output
1 parent 3891fb1 commit e2de7fb

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

aragorm/query.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ async def run(self, as_dict=True, credentials=None):
8787
output = getattr(self, '_output')
8888
if output:
8989
if output.as_list:
90-
if output[0].keys().length != 1:
90+
if len(raw[0].keys()) != 1:
9191
raise ValueError(
9292
'Each row returned more than on value'
9393
)
9494
else:
95-
output = [i for i in itertools.chain(*output.values())]
95+
raw = list(
96+
itertools.chain(*[j.values() for j in raw])
97+
)
9698
if output.as_json:
97-
output = json.dumps(raw)
99+
raw = json.dumps(raw)
98100

99101
return raw
100102

@@ -234,6 +236,8 @@ def output(
234236
if type(as_json) is bool:
235237
self._output.as_json = as_json
236238

239+
return self
240+
237241

238242
###############################################################################
239243

tests/table/test_output.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from ..base import DBTestCase
2+
from ..example_project.tables import Pokemon
3+
4+
5+
class TestOutput(DBTestCase):
6+
7+
def test_output_as_list(self):
8+
self.insert_row()
9+
10+
response = Pokemon.select(
11+
'name'
12+
).output(
13+
as_list=True
14+
).run_sync()
15+
16+
self.assertTrue(
17+
response == ['pikachu']
18+
)
19+
20+
def test_output_as_json(self):
21+
self.insert_row()
22+
23+
response = Pokemon.select(
24+
'name'
25+
).output(
26+
as_json=True
27+
).run_sync()
28+
29+
self.assertTrue(
30+
response == '[{"name":"pikachu"}]'
31+
)

0 commit comments

Comments
 (0)