kopia lustrzana https://github.com/simonw/datasette
Don't explain an explain even in the demo, refs #2293
rodzic
5de6797d4a
commit
4d24bf6b34
|
@ -1557,7 +1557,10 @@ This example adds a new query action linking to a page for explaining a query:
|
||||||
|
|
||||||
|
|
||||||
@hookimpl
|
@hookimpl
|
||||||
def query_actions(datasette, database, sql):
|
def query_actions(datasette, database, query_name, sql):
|
||||||
|
# Don't explain an explain
|
||||||
|
if sql.lower().startswith("explain"):
|
||||||
|
return
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"href": datasette.urls.database(database)
|
"href": datasette.urls.database(database)
|
||||||
|
@ -1571,7 +1574,6 @@ This example adds a new query action linking to a page for explaining a query:
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
.. _plugin_hook_database_actions:
|
.. _plugin_hook_database_actions:
|
||||||
|
|
||||||
database_actions(datasette, actor, database, request)
|
database_actions(datasette, actor, database, request)
|
||||||
|
|
|
@ -393,11 +393,9 @@ def table_actions(datasette, database, table, actor):
|
||||||
|
|
||||||
@hookimpl
|
@hookimpl
|
||||||
def query_actions(datasette, database, query_name, sql):
|
def query_actions(datasette, database, query_name, sql):
|
||||||
args = {
|
# Don't explain an explain
|
||||||
"sql": sql,
|
if sql.lower().startswith("explain"):
|
||||||
}
|
return
|
||||||
if query_name:
|
|
||||||
args["query_name"] = query_name
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"href": datasette.urls.database(database)
|
"href": datasette.urls.database(database)
|
||||||
|
|
|
@ -954,6 +954,8 @@ async def test_hook_table_actions(ds_client, table_or_view):
|
||||||
"/fixtures/pragma_cache_size",
|
"/fixtures/pragma_cache_size",
|
||||||
"/fixtures?sql=explain+PRAGMA+cache_size%3B",
|
"/fixtures?sql=explain+PRAGMA+cache_size%3B",
|
||||||
),
|
),
|
||||||
|
# Don't attempt to explain an explain
|
||||||
|
("/fixtures?sql=explain+select+1", None),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_hook_query_actions(ds_client, path, expected_url):
|
async def test_hook_query_actions(ds_client, path, expected_url):
|
||||||
|
@ -967,6 +969,9 @@ async def test_hook_query_actions(ds_client, path, expected_url):
|
||||||
response = await ds_client.get(path)
|
response = await ds_client.get(path)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
links = get_table_actions_links(response.text)
|
links = get_table_actions_links(response.text)
|
||||||
|
if expected_url is None:
|
||||||
|
assert links == []
|
||||||
|
else:
|
||||||
assert links == [{"label": "Explain this query", "href": expected_url}]
|
assert links == [{"label": "Explain this query", "href": expected_url}]
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue