mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New plugin hook: canned_queries(), refs #852
This commit is contained in:
parent
d2f387591b
commit
6c26345836
12 changed files with 203 additions and 50 deletions
|
|
@ -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"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue