]> git.jsancho.org Git - datasette-pytables.git/commitdiff
Truncate query results according to page_size limit
authorJavier Sancho <jsf@jsancho.org>
Wed, 23 May 2018 11:03:56 +0000 (13:03 +0200)
committerJavier Sancho <jsf@jsancho.org>
Wed, 23 May 2018 11:03:56 +0000 (13:03 +0200)
datasette_pytables/__init__.py
tests/test_api.py

index 6e34774bc24e83688571fcac6645741a9c98ba28..74c72b1173fd7af371c414255c181c1c6bdaa3be 100644 (file)
@@ -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)
index 834a65df893e2dff7bf2946991c913ad5cd80b8a..85b4bb1c164cfa94866d45c7553f03f09c91f66c 100644 (file)
@@ -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'},