Skip to content

Commit

Permalink
Better demo plugin for query_actions, refs simonw#2293
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 6, 2024
1 parent 86335dc commit 5de6797
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1561,10 +1561,10 @@ This example adds a new query action linking to a page for explaining a query:
return [
{
"href": datasette.urls.database(database)
+ "/-/explain?"
+ "?"
+ urllib.parse.urlencode(
{
"sql": sql,
"sql": "explain " + sql,
}
),
"label": "Explain this query",
Expand Down
8 changes: 6 additions & 2 deletions tests/plugins/my_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,12 @@ def query_actions(datasette, database, query_name, sql):
return [
{
"href": datasette.urls.database(database)
+ "/-/explain?"
+ urllib.parse.urlencode(args),
+ "?"
+ urllib.parse.urlencode(
{
"sql": "explain " + sql,
}
),
"label": "Explain this query",
},
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ def get_table_actions_links(html):
@pytest.mark.parametrize(
"path,expected_url",
(
("/fixtures?sql=select+1", "/fixtures/-/explain?sql=select+1"),
("/fixtures?sql=select+1", "/fixtures?sql=explain+select+1"),
(
"/fixtures/pragma_cache_size",
"/fixtures/-/explain?sql=PRAGMA+cache_size%3B&query_name=pragma_cache_size",
"/fixtures?sql=explain+PRAGMA+cache_size%3B",
),
),
)
Expand Down

0 comments on commit 5de6797

Please sign in to comment.