]> git.jsancho.org Git - datasette-pytables.git/blobdiff - datasette_pytables/__init__.py
Truncate query results according to page_size limit
[datasette-pytables.git] / datasette_pytables / __init__.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)