Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canned_queries() plugin hook #852

Closed
simonw opened this issue Jun 18, 2020 · 9 comments
Closed

canned_queries() plugin hook #852

simonw opened this issue Jun 18, 2020 · 9 comments

Comments

@simonw
Copy link
Owner

simonw commented Jun 18, 2020

Canned queries are currently baked into metadata.json which is read once on startup.

Allowing users to interactively create new canned queries - even if just through a plugin - would make a lot of sense.

Is this a new plugin hook or some other mechanism? Lots to think about here.

@simonw
Copy link
Owner Author

simonw commented Jun 18, 2020

Question about this on Twitter: https://twitter.com/amjithr/status/1273440766862352384

@simonw
Copy link
Owner Author

simonw commented Jun 18, 2020

The easiest way to do this would be with a new plugin hook:

def canned_queries(datasette, database):
    """Return a list of canned query definitions
    or an awaitable function that returns them"

Another approach would be to make the whole of metadata.json customizable by plugins.

I think I like the dedicated canned_queries option better. I'm not happy with the way metadata keeps growing - see #493 - so adding a dedicated hook would be more future proof against other changes I might make to the metadata mechanism.

@simonw simonw changed the title Mechanism for adding new canned queries without restarting Datasette canned_queries() plugin hook Jun 18, 2020
@simonw simonw added this to the Datasette 0.45 milestone Jun 18, 2020
@simonw
Copy link
Owner Author

simonw commented Jun 18, 2020

It would be neat if the queries returned by this hook could be restricted to specific users. I think I can do that by returning an "allow" block as part of the query.

But... what if we allow users to save private queries and we might have thousands of users each with hundreds of saved queries?

For that case it would be good if the plugin hook could take an optional actor parameter.

This would also allow us to dynamically generate a canned query for "return the bookmarks belonging to this actor" or similar!

@simonw
Copy link
Owner Author

simonw commented Jun 18, 2020

@hookspec
def canned_queries(datasette, database, actor):
    "Return a dictionary of canned query definitions or an awaitable function that returns them"

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

I'll close this once I've built a plugin against it.

@simonw
Copy link
Owner Author

simonw commented Jun 19, 2020

Plugin idea: datasette-saved-queries - it uses the startup hook to initialize a saved_queries table, then uses the canned_queries hook to add a writable canned query for saving records to that table.

Then it returns any queries from that table as additional canned queries.

Bonus idea: it could write the user's actor_id to a column if they are signed in, and provide a link to see "just my saved queries" in that case.

@simonw
Copy link
Owner Author

simonw commented Jun 20, 2020

New repo: https://github.com/simonw/datasette-saved-queries - which I created using the new cookiecutter template at https://github.com/simonw/datasette-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant