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)
|
_limit = kwargs.pop('_limit', None)
|
||||||
_offset = kwargs.pop('_offset', 0)
|
_offset = kwargs.pop('_offset', 0)
|
||||||
order_by = kwargs.pop('order_by', None)
|
order_by = kwargs.pop('order_by', None)
|
||||||
|
_streamed = kwargs.pop('_streamed', False)
|
||||||
_step = kwargs.pop('_step', QUERY_STEP)
|
_step = kwargs.pop('_step', QUERY_STEP)
|
||||||
if _step is False or _step == 0:
|
if _step is False or _step == 0:
|
||||||
_step = None
|
_step = None
|
||||||
@ -459,7 +460,13 @@ class Table(object):
|
|||||||
offset=_offset)
|
offset=_offset)
|
||||||
if len(order_by):
|
if len(order_by):
|
||||||
query = query.order_by(*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,
|
row_type=self.db.row_type,
|
||||||
step=_step)
|
step=_step)
|
||||||
|
|
||||||
|
|||||||
6
setup.py
6
setup.py
@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='dataset',
|
name='dataset',
|
||||||
version='1.0.3',
|
version='1.0.4',
|
||||||
description="Toolkit for Python-based database access.",
|
description="Toolkit for Python-based database access.",
|
||||||
long_description="",
|
long_description="",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
@ -29,8 +29,8 @@ setup(
|
|||||||
install_requires=[
|
install_requires=[
|
||||||
'sqlalchemy >= 1.1.0',
|
'sqlalchemy >= 1.1.0',
|
||||||
'alembic >= 0.6.2',
|
'alembic >= 0.6.2',
|
||||||
'normality >= 0.3.9',
|
'normality >= 0.5.1',
|
||||||
"six >= 1.7.3"
|
"six >= 1.11.0"
|
||||||
],
|
],
|
||||||
tests_require=[
|
tests_require=[
|
||||||
'nose'
|
'nose'
|
||||||
|
|||||||
@ -327,6 +327,13 @@ class TableTestCase(unittest.TestCase):
|
|||||||
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2, _offset=2))
|
ds = list(self.tbl.find(place=TEST_CITY_1, _limit=2, _offset=2))
|
||||||
assert len(ds) == 1, ds
|
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):
|
def test_distinct(self):
|
||||||
x = list(self.tbl.distinct('place'))
|
x = list(self.tbl.distinct('place'))
|
||||||
assert len(x) == 2, x
|
assert len(x) == 2, x
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user