Streaming mode for downloading all rows as a CSV (#315)

* table.csv?_stream=1 to download all rows - refs #266

This option causes Datasette to serve ALL rows in the table, by internally
following the _next= pagination links and serving everything out as a stream.

Also added new config option, allow_csv_stream, which can be used to disable
this feature.

* New config option max_csv_mb limiting size of CSV export
This commit is contained in:
Simon Willison 2018-06-17 20:21:02 -07:00 committed by GitHub
commit fc3660cfad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 142 additions and 24 deletions

View file

@ -220,7 +220,7 @@ class RowTableShared(BaseView):
class TableView(RowTableShared):
async def data(self, request, name, hash, table, default_labels=False):
async def data(self, request, name, hash, table, default_labels=False, _next=None, _size=None):
canned_query = self.ds.get_canned_query(name, table)
if canned_query is not None:
return await self.custom_sql(
@ -375,7 +375,7 @@ class TableView(RowTableShared):
count_sql = "select count(*) {}".format(from_sql)
_next = special_args.get("_next")
_next = _next or special_args.get("_next")
offset = ""
if _next:
if is_view:
@ -462,7 +462,7 @@ class TableView(RowTableShared):
extra_args = {}
# Handle ?_size=500
page_size = request.raw_args.get("_size")
page_size = _size or request.raw_args.get("_size")
if page_size:
if page_size == "max":
page_size = self.max_returned_rows
@ -512,6 +512,8 @@ class TableView(RowTableShared):
facet_results = {}
facets_timed_out = []
for column in facets:
if _next:
continue
facet_sql = """
select {col} as value, count(*) as count
{from_sql} {and_or_where} {col} is not null
@ -665,6 +667,8 @@ class TableView(RowTableShared):
for facet_column in columns:
if facet_column in facets:
continue
if _next:
continue
if not self.ds.config["suggest_facets"]:
continue
suggested_facet_sql = '''