From 2ec11308121b4b9c0064ffdde3b583efb95228bc Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 23 May 2018 13:03:56 +0200 Subject: [PATCH] Truncate query results according to page_size limit --- datasette_pytables/__init__.py | 8 +++++++- tests/test_api.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 6e34774..74c72b1 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -71,7 +71,7 @@ class Connection: self.path = path self.h5file = tables.open_file(path) - def execute(self, sql, params=None, truncate=False): + def execute(self, sql, params=None, truncate=False, page_size=None): if params is None: params = {} rows = [] @@ -140,6 +140,12 @@ class Connection: if end - start > max_rows: end = start + max_rows + # Truncate if needed + if page_size and truncate: + if end - start > page_size: + end = start + page_size + truncated = True + # Execute query if query: table_rows = table.where(query, params, start, end) diff --git a/tests/test_api.py b/tests/test_api.py index 834a65d..85b4bb1 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -63,6 +63,7 @@ def test_custom_sql(app_client): 'sql': 'select identity from [/group1/table1]', 'params': {} } == data['query'] + assert 50 == len(data['rows']) assert [ {'identity': 'This is particle: 0'}, {'identity': 'This is particle: 1'}, -- 2.39.2