From 8f981acbd074be2eec098253112f8ef479373a5e Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Tue, 3 Nov 2020 18:29:58 +0100 Subject: [PATCH] Paginate with offset argument --- datasette_pytables/__init__.py | 7 +++++++ tests/test_api.py | 1 + 2 files changed, 8 insertions(+) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 9cb9005..889dcca 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -198,6 +198,11 @@ class PyTablesConnector(dc.Connector): if 'limit' in parsed_sql: limit = int(parsed_sql['limit']) + # Offset + offset = None + if 'offset' in parsed_sql: + offset = int(parsed_sql['offset']) + # Truncate if needed if page_size and max_returned_rows and truncate: if max_returned_rows == page_size: @@ -245,6 +250,8 @@ class PyTablesConnector(dc.Connector): # Get results get_rowid = make_get_rowid() get_row_value = make_get_row_value() + if offset: + table_rows = table_rows[offset:] count = 0 for table_row in table_rows: count += 1 diff --git a/tests/test_api.py b/tests/test_api.py index b1900ef..71c9262 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -232,6 +232,7 @@ def test_paginate_tables_and_arrays(app_client, path, expected_rows, expected_pa fetched.extend(response.json['rows']) path = response.json['next_url'] if path: + path = path.replace('http://localhost', '') assert response.json['next'] assert '_next={}'.format(response.json['next']) in path -- 2.39.5