option for streamed responses.
This commit is contained in:
parent
dbc1edeca9
commit
8226e51408
@ -448,6 +448,7 @@ class Table(object):
|
||||
_limit = kwargs.pop('_limit', None)
|
||||
_offset = kwargs.pop('_offset', 0)
|
||||
order_by = kwargs.pop('order_by', None)
|
||||
_streamed = kwargs.pop('_streamed', False)
|
||||
_step = kwargs.pop('_step', QUERY_STEP)
|
||||
if _step is False or _step == 0:
|
||||
_step = None
|
||||
@ -459,7 +460,13 @@ class Table(object):
|
||||
offset=_offset)
|
||||
if len(order_by):
|
||||
query = query.order_by(*order_by)
|
||||
return ResultIter(self.db.executable.execute(query),
|
||||
|
||||
conn = self.db.executable
|
||||
if _streamed:
|
||||
conn = self.db.engine.connect()
|
||||
conn = conn.execution_options(stream_results=True)
|
||||
|
||||
return ResultIter(conn.execute(query),
|
||||
row_type=self.db.row_type,
|
||||
step=_step)
|
||||
|
||||
|
||||
6
setup.py
6
setup.py
@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='dataset',
|
||||
version='1.0.3',
|
||||
version='1.0.4',
|
||||
description="Toolkit for Python-based database access.",
|
||||
long_description="",
|
||||
classifiers=[
|
||||
@ -29,8 +29,8 @@ setup(
|
||||
install_requires=[
|
||||
'sqlalchemy >= 1.1.0',
|
||||
'alembic >= 0.6.2',
|
||||
'normality >= 0.3.9',
|
||||
"six >= 1.7.3"
|
||||
'normality >= 0.5.1',
|
||||
"six >= 1.11.0"
|
||||
],
|
||||
tests_require=[
|
||||
'nose'
|
||||
|
||||
@ -327,6 +327,13 @@ class TableTestCase(unittest.TestCase):
|
||||
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2, _offset=2))
|
||||
assert len(ds) == 1, ds
|
||||
|
||||
def test_streamed(self):
|
||||
ds = list(self.tbl.find(place=TEST_CITY_1, _streamed=True, _step=1))
|
||||
assert len(ds) == 3, len(ds)
|
||||
for row in self.tbl.find(place=TEST_CITY_1, _streamed=True, _step=1):
|
||||
row['temperature'] = -1
|
||||
self.tbl.update(row, ['id'])
|
||||
|
||||
def test_distinct(self):
|
||||
x = list(self.tbl.distinct('place'))
|
||||
assert len(x) == 2, x
|
||||
|
||||
Loading…
Reference in New Issue
Block a user