From: Javier Sancho Date: Fri, 1 Jun 2018 10:17:56 +0000 (+0200) Subject: Sort by column without managing errors X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=commitdiff_plain;h=6ca6ff3a33c6920d45b97397daf1222df32111c5 Sort by column without managing errors --- 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)