{"html_url": "https://github.com/simonw/datasette/issues/429#issuecomment-482628978", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482628978, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MjYyODk3OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-12T16:00:04Z", "updated_at": "2019-04-12T16:00:04Z", "author_association": "OWNER", "body": "I originally thought of this as a plugin but then realized that it's 100% compatible with Datasette's existing arbitrary SQL clauses and would make some of my other projects (especially involving custom queries that still need faceting) a whole lot easier.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 432636432, "label": "?_where=sql-fragment parameter for table views"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/429#issuecomment-482638695", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482638695, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MjYzODY5NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-12T16:29:25Z", "updated_at": "2019-04-13T01:14:17Z", "author_association": "OWNER", "body": "Getting a prototype working was hardly any code at all:\r\n\r\nhttp://127.0.0.1:8001/fixtures/facetable?_where=city_id+in+(select+id+from+facet_cities+where+name+like+%22%25an%25%22)\r\n\r\n```\r\ndiff --git a/datasette/views/table.py b/datasette/views/table.py\r\nindex b7c9a4b..7ca9572 100644\r\n--- a/datasette/views/table.py\r\n+++ b/datasette/views/table.py\r\n@@ -295,6 +295,10 @@ class TableView(RowTableShared):\r\n filters = Filters(sorted(other_args.items()), units, ureg)\r\n where_clauses, params = filters.build_where_clauses(table)\r\n \r\n+ # Add _where= from querystring\r\n+ if self.ds.config(\"allow_sql\") and \"_where\" in request.args:\r\n+ where_clauses.extend(request.args[\"_where\"])\r\n+\r\n # _search support:\r\n fts_table = special_args.get(\"_fts_table\")\r\n fts_table = fts_table or table_metadata.get(\"fts_table\")\r\n```\r\n\r\nStill needed:\r\n\r\n- [x] Unit tests\r\n- [x] Probably some kind of visual display on the table page so you know that extra clauses have been added (and maybe a UI for dropping them again)\r\n\r\nI'm going to leave the `:named` parameter support out of the first version of this feature.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 432636432, "label": "?_where=sql-fragment parameter for table views"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/429#issuecomment-482640079", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482640079, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MjY0MDA3OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-12T16:34:01Z", "updated_at": "2019-04-12T16:34:01Z", "author_association": "OWNER", "body": "UI concept:\r\n\r\n\r\n\r\n```\r\n
city_id in (select id from facet_cities where name like \"%an%\")
[remove]