query_actions plugin hook

* New query_actions plugin hook, closes #2283
This commit is contained in:
Simon Willison 2024-02-27 21:55:16 -08:00 committed by GitHub
commit 6ec0081f5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 151 additions and 0 deletions

View file

@ -7,6 +7,7 @@ from datasette.utils.asgi import asgi_send_json, Response
import base64
import pint
import json
import urllib
ureg = pint.UnitRegistry()
@ -390,6 +391,23 @@ def table_actions(datasette, database, table, actor):
]
@hookimpl
def query_actions(datasette, database, query_name, sql):
args = {
"sql": sql,
}
if query_name:
args["query_name"] = query_name
return [
{
"href": datasette.urls.database(database)
+ "/-/explain?"
+ urllib.parse.urlencode(args),
"label": "Explain this query",
},
]
@hookimpl
def database_actions(datasette, database, actor, request):
if actor: