{"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\"fixtures__facetable__10_rows\"\r\n\r\n```\r\n

1 extra where clause:

\r\n

city_id in (select id from facet_cities where name like \"%an%\") [remove]

\r\n```", "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-482640250", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482640250, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MjY0MDI1MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-12T16:34:32Z", "updated_at": "2019-04-12T16:34:32Z", "author_association": "OWNER", "body": "Keeping track of these and building the \"remove\" links correctly is going to be a tiny bit fiddly.", "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-482640383", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482640383, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MjY0MDM4Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-12T16:34:56Z", "updated_at": "2019-04-12T16:34:56Z", "author_association": "OWNER", "body": "Maybe put this section above the \"view and edit SQL\" link.", "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-482766801", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 482766801, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4Mjc2NjgwMQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-04-13T01:56:19Z", "updated_at": "2019-04-13T01:56:19Z", "author_association": "OWNER", "body": "Documentation is here: https://datasette.readthedocs.io/en/latest/json_api.html#special-table-arguments\r\n\r\nDemo:\r\n\r\n* https://latest.datasette.io/fixtures/facetable?_where=state=%22MI%22&_where=city_id=3\r\n* https://latest.datasette.io/fixtures/facetable?_where=city_id%20in%20(select%20id%20from%20facet_cities%20where%20name%20!=%20%22Detroit%22)", "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-483202658", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/429", "id": 483202658, "node_id": "MDEyOklzc3VlQ29tbWVudDQ4MzIwMjY1OA==", "user": {"value": 82988, "label": "psychemedia"}, "created_at": "2019-04-15T10:48:01Z", "updated_at": "2019-04-15T10:48:01Z", "author_association": "CONTRIBUTOR", "body": "Minor UI observation:\r\n\r\n![image](https://user-images.githubusercontent.com/82988/56127017-2bf78e80-5f74-11e9-9120-9393eb5d4988.png)\r\n\r\n`_where=` renders a `[remove]` link whereas `_facet=` gets a cross to remove it. ", "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}