From 6ca6ff3a33c6920d45b97397daf1222df32111c5 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Fri, 1 Jun 2018 12:17:56 +0200 Subject: [PATCH] Sort by column without managing errors --- datasette_pytables/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 93f9b89..2e6920e 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -146,6 +146,16 @@ class Connection: else: query = parsed_sql['where'] + # Sort by column + orderby = '' + if 'orderby' in parsed_sql: + orderby = parsed_sql['orderby'] + if type(orderby) is list: + orderby = orderby[0] + orderby = orderby['value'] + if orderby == 'rowid': + orderby = '' + # Limit number of rows limit = None if 'limit' in parsed_sql: @@ -159,6 +169,8 @@ class Connection: # Execute query if query: table_rows = table.where(query, params, start, end) + elif orderby: + table_rows = table.itersorted(orderby, start=start, stop=end) else: table_rows = table.iterrows(start, end) -- 2.39.5