]> git.jsancho.org Git - datasette-pytables.git/commitdiff
Sort by column without managing errors
authorJavier Sancho <jsf@jsancho.org>
Fri, 1 Jun 2018 10:17:56 +0000 (12:17 +0200)
committerJavier Sancho <jsf@jsancho.org>
Fri, 1 Jun 2018 10:17:56 +0000 (12:17 +0200)
datasette_pytables/__init__.py

index 93f9b89cfa0577b9d4b10215cec6b191c595c3d3..2e6920eceab3f96c3f28e17a566962023534fb44 100644 (file)
@@ -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)