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

"Edit SQL" button on canned queries #1019

Closed
jsfenfen opened this issue Oct 14, 2020 · 7 comments
Closed

"Edit SQL" button on canned queries #1019

jsfenfen opened this issue Oct 14, 2020 · 7 comments
Milestone

Comments

@jsfenfen
Copy link
Sponsor Contributor

jsfenfen commented Oct 14, 2020

Feature request: Would it be possible to add an "edit this query" button on canned queries? Clicking it would open the canned query as an editable sql query. I think the intent is to have named parameters to allow this, but sometimes you just gotta rewrite it?

@simonw
Copy link
Owner

simonw commented Oct 14, 2020

I've found myself wanting this too.

It should respect the allow-sql permission so it doesn't display if the user isn't able to run custom SQL.

@simonw
Copy link
Owner

simonw commented Oct 14, 2020

So it would appear on this page: https://latest.datasette.io/fixtures/neighborhood_search#fragment-goes-here

Probably as a blue "Edit SQL" link next to those buttons.

575FB160-4F75-43B2-B2AB-D75E60F10477

@simonw
Copy link
Owner

simonw commented Oct 14, 2020

Maybe like this:

fixtures__select_neighborhood__facet_cities_name__state_from_facetable_join_facet_cities_on_facetable_city_id___facet_cities_id_where_neighborhood_like_________text________order_by_neighborhood_

@simonw
Copy link
Owner

simonw commented Oct 14, 2020

Another edge-case: https://latest.datasette.io/fixtures/pragma_cache_size (PRAGMA cache_size;) isn't an allowed query usually, so linking to "Edit SQL" for it would link to an error page: https://latest.datasette.io/fixtures?sql=PRAGMA+cache_size%3B

Can use datasette.utils.validate_sql_select(sql) to check for that - it raises datasette.utils.InvalidSql if there's a problem.

@simonw
Copy link
Owner

simonw commented Oct 14, 2020

One last edge-case (I think) - magic parameters aren't supported for non-canned-queries, so if a query includes those it shouldn't show an Edit SQL link: https://latest.datasette.io/fixtures/magic_parameters

I don't have a clean way of detecting if a query contains defined magic parameters, but I can instead do a dumb substring match for :_ and skip showing the Edit SQL link if that is present.

@simonw simonw closed this as completed in f3a087a Oct 14, 2020
@simonw
Copy link
Owner

simonw commented Oct 14, 2020

Demos:

@jsfenfen
Copy link
Sponsor Contributor Author

jsfenfen commented Oct 14, 2020

🎉 Thanks so much @simonw ! 🎉

simonw added a commit that referenced this issue Oct 20, 2020
@simonw simonw added this to the 0.51 milestone Oct 23, 2020
simonw added a commit that referenced this issue Oct 31, 2020
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

2 participants