home / docs / sections

sections: plugin_hooks:plugin-hook-query-actions

This data as json

id page ref title content breadcrumbs references
plugin_hooks:plugin-hook-query-actions plugin_hooks plugin-hook-query-actions query_actions(datasette, actor, database, query_name, request, sql, params) datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) , or to execute SQL queries. actor - dictionary or None The currently authenticated actor . database - string The name of the database. query_name - string or None The name of the canned query, or None if this is an arbitrary SQL query. request - Request object The current HTTP request. sql - string The SQL query being executed params - dictionary The parameters passed to the SQL query, if any. Populates a "Query actions" menu on the canned query and arbitrary SQL query pages. This example adds a new query action linking to a page for explaining a query: from datasette import hookimpl import urllib @hookimpl def query_actions(datasette, database, query_name, sql): # Don't explain an explain if sql.lower().startswith("explain"): return return [ { "href": datasette.urls.database(database) + "?" + urllib.parse.urlencode( { "sql": "explain " + sql, } ), "label": "Explain this query", "description": "Get a summary of how SQLite executes the query", }, ] Example: datasette-create-view ["Plugin hooks", "Action hooks"] [{"href": "https://datasette.io/plugins/datasette-create-view", "label": "datasette-create-view"}]
Powered by Datasette · Queries took 2.207ms