simonw / datasette-saved-queries

Datasette plugin that lets users save and execute queries
12 stars 0 forks source link

UI for saving queries, including writable queries #10

Open simonw opened 10 months ago

simonw commented 10 months ago

This plugin needs a major update, partly based on the needs of Datasette Cloud.

simonw commented 9 months ago

I tried this but it didn't seem to work:

diff --git a/datasette_saved_queries/__init__.py b/datasette_saved_queries/__init__.py
index 2d0e13b..f3fb411 100644
--- a/datasette_saved_queries/__init__.py
+++ b/datasette_saved_queries/__init__.py
@@ -1,7 +1,25 @@
 from datasette import hookimpl
+import urllib.parse
 import sqlite_utils

+@hookimpl
+def database_actions(datasette, database, request):
+    print("database_actions", request)
+    if request.args.get("sql"):
+        return [
+            {
+                "href": datasette.urls.path(
+                    "/-/save-query/{}?{}".format(
+                        database, urllib.parse.urlencode({
+                            "sql": request.args["sql"],
+                        })
+                    )
+                ),
+                "label": "Save this SQL query",
+            }
+        ]
+
 def create_tables(conn):
     db = sqlite_utils.Database(conn)
     if not db["saved_queries"].exists():
simonw commented 9 months ago

I just added a new Datasette plugin hook that can help with this:

simonw commented 9 months ago

Idea: have an option to save a canned query as private, which means only your actor will be able to view it in the future.

Probably display them with "private" in the name, if that's possible.

simonw commented 9 months ago

That plugin hook is now available in https://github.com/simonw/datasette/releases/tag/1.0a12