{"html_url": "https://github.com/simonw/datasette/issues/2147#issuecomment-1687433388", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2147", "id": 1687433388, "node_id": "IC_kwDOBm6k_c5klDCs", "user": {"value": 18899, "label": "jackowayed"}, "created_at": "2023-08-22T05:05:33Z", "updated_at": "2023-08-22T05:05:33Z", "author_association": "NONE", "body": "Thanks for all this! You're totally right that the ASGI option is doable, if a bit low level and coupled to the current URI design. I'm totally fine with that being the final answer.\r\n\r\nprocess_view is interesting and in the general direction of what I had in mind.\r\n\r\nA somewhat less powerful idea: Is there value in giving a hook for just the query that's about to be run? Maybe I'm thinking a little narrowly about this problem I decided I wanted to solve, but I could see other uses for a hook of the sketch below:\r\n\r\n```\r\ndef prepare_query(database, table, query):\r\n \"\"\"Modify query that is about to be run in some way. Return the (possibly rewritten) query to run, or None to disallow running the query\"\"\"\r\n```\r\n(Maybe you actually want to return a tuple so there can be an error message when you disallow, or something.)\r\n\r\nMaybe it's too narrowly useful and some of the other pieces of datasette obviate some of these ideas, but off the cuff I could imagine using it to:\r\n* Require a LIMIT. Either fail the query or add the limit if it's not there.\r\n* Do logging, like my usecase.\r\n* Do other analysis on whether you want to allow the query to run; a linter? query complexity? \r\n\r\nDefinitely feel free to say no, or not now. This is all me just playing around with what datasette and its plugin architecture can do with toy ideas, so don't let me push you to commit to a hook you don't feel confident fits well in the design.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1858228057, "label": "Plugin hook for database queries that are run"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2147#issuecomment-1690955706", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2147", "id": 1690955706, "node_id": "IC_kwDOBm6k_c5kye-6", "user": {"value": 18899, "label": "jackowayed"}, "created_at": "2023-08-24T03:54:35Z", "updated_at": "2023-08-24T03:54:35Z", "author_association": "NONE", "body": "That's fair. The best idea I can think of is that if a plugin wanted to limit intensive queries, it could add LIMITs or something. A hook that gives you visibility of queries and maybe the option to reject felt a little more limited than the existing plugin hooks, so I was trying to think of what else one might want to do while looking at to-be-run queries.\r\n\r\nBut without a real motivating example, I see why you don't want to add that.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1858228057, "label": "Plugin hook for database queries that are run"}, "performed_via_github_app": null}