X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=datasette_pytables%2F__init__.py;h=74c72b1173fd7af371c414255c181c1c6bdaa3be;hp=4a7c5c8c3e83af5c4ef5a1f35f97f64b84b2bb63;hb=2ec11308121b4b9c0064ffdde3b583efb95228bc;hpb=3c2e826f2fd5c6a05ada7dceb09d9e9e1b8cf5e6 diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 4a7c5c8..74c72b1 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -41,12 +41,12 @@ def _parse_sql(sql, params): parsed = parse(sql) except: # Propably it's a PyTables expression - for token in ['group by', 'order by', 'limit']: + for token in ['group by', 'order by', 'limit', '']: res = re.search('(?i)where (.*)' + token, sql) if res: modified_sql = re.sub('(?i)where (.*)(' + token + ')', '\g<2>', sql) parsed = parse(modified_sql) - parsed['where'] = res.group(1) + parsed['where'] = res.group(1).strip() break # Always a list of fields @@ -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)