New plugin hook: canned_queries(), refs #852

This commit is contained in:
Simon Willison 2020-06-18 16:22:33 -07:00
commit 6c26345836
12 changed files with 203 additions and 50 deletions

View file

@ -193,3 +193,12 @@ def register_routes():
@hookimpl
def startup(datasette):
datasette._startup_hook_fired = True
@hookimpl
def canned_queries(datasette, database, actor):
return {
"from_hook": "select 1, '{}' as actor_id".format(
actor["id"] if actor else "null"
)
}

View file

@ -129,3 +129,17 @@ def startup(datasette):
datasette._startup_hook_calculation = result.first()[0]
return inner
@hookimpl
def canned_queries(datasette, database):
async def inner():
return {
"from_async_hook": "select {}".format(
(
await datasette.get_database(database).execute("select 1 + 1")
).first()[0]
)
}
return inner