X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=datasette_pytables%2F__init__.py;h=2e6920eceab3f96c3f28e17a566962023534fb44;hp=58fee10364d3fec5c83d5b011579555f8d492712;hb=9a7a609df0a94dff41bb9a58dc61b25b0a326582;hpb=d3ebe73db6b25569b800ccd55ad8eb90dd88b773 diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index 58fee10..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) @@ -251,6 +263,7 @@ class Connection: else: raise Exception("SQLite queries cannot be executed with this connector") + class Row(list): def __init__(self, values=None): self.labels = []