Skip to content

Commit

Permalink
Allow iterating over result wrapper for multiple times (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander3771 authored and rudyryk committed Jan 16, 2018
1 parent b94a662 commit fcbb866
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,7 @@ def __init__(self, *, cursor=None, query=None):
self._result_wrapper = self._get_result_wrapper(query)

def __iter__(self):
while True:
yield self._result_wrapper.iterate()
return iter(self._result_wrapper)

def __len__(self):
return len(self._rows)
Expand Down
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,18 @@ def test(objects):

self.run_with_managers(test)

def test_multiple_iterate_over_result(self):
@asyncio.coroutine
def test(objects):
obj1 = yield from objects.create(TestModel, text="Test 1")
obj2 = yield from objects.create(TestModel, text="Test 2")
result = yield from objects.execute(
TestModel.select().order_by(TestModel.text))
self.assertEqual(list(result), [obj1, obj2])
self.assertEqual(list(result), [obj1, obj2])

self.run_with_managers(test)

def test_insert_many_rows_query(self):
@asyncio.coroutine
def test(objects):
Expand Down

0 comments on commit fcbb866

Please sign in to comment.