issue_comments: 709575818
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | issue | performed_via_github_app |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/simonw/datasette/issues/894#issuecomment-709575818 | https://api.github.com/repos/simonw/datasette/issues/894 | 709575818 | MDEyOklzc3VlQ29tbWVudDcwOTU3NTgxOA== | 9599 | 2020-10-15T20:35:03Z | 2020-10-15T20:35:03Z | OWNER | Prototype so far: ```diff diff --git a/datasette/views/table.py b/datasette/views/table.py index ea11a51..d61f8bd 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -497,17 +497,32 @@ class TableView(RowTableShared): if sort and sort_desc: raise DatasetteError("Cannot use _sort and _sort_desc at the same time") + def parse_sort(sort): + if "~" in sort: + if sort.endswith("~default"): + col = sort.rsplit("~", 1)[0] + return col, escape_sqlite(col) + elif sort.endswith("~numeric"): + col = sort.rsplit("~", 1)[0] + return col, "cast(nullif({}, '') as real)".format(escape_sqlite(col)) + else: + return sort, escape_sqlite(sort) + else: + return sort, escape_sqlite(sort) + if sort: - if sort not in sortable_columns: - raise DatasetteError("Cannot sort table by {}".format(sort)) + sort_column, sort_clause = parse_sort(sort) + if sort_column not in sortable_columns: + raise DatasetteError("Cannot sort table by {}".format(sort_column)) - order_by = escape_sqlite(sort) + order_by = sort_clause if sort_desc: - if sort_desc not in sortable_columns: - raise DatasetteError("Cannot sort table by {}".format(sort_desc)) + sort_column, sort_clause = parse_sort(sort_desc) + if sort_column not in sortable_columns: + raise DatasetteError("Cannot sort table by {}".format(sort_column)) - order_by = "{} desc".format(escape_sqlite(sort_desc)) + order_by = "{} desc".format(sort_clause) from_sql = "from {table_name} {where}".format( table_name=escape_sqlite(table), ``` | {"total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0} | 657572753 |