{"html_url": "https://github.com/simonw/datasette/issues/2134#issuecomment-1671500965", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2134", "id": 1671500965, "node_id": "IC_kwDOBm6k_c5joRSl", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-09T14:31:43Z", "updated_at": "2023-08-09T14:31:43Z", "author_association": "OWNER", "body": "Here's a simple plugin that can do this:\r\n```python\r\nfrom datasette import hookimpl\r\n\r\n@hookimpl\r\ndef startup(datasette):\r\n db = datasette.add_memory_database(\"counters\")\r\n\r\n async def inner():\r\n await db.execute_write(\"create table if not exists counters (name text primary key, value integer)\")\r\n await db.execute_write(\"insert or ignore into counters (name, value) values ('counter', 0)\")\r\n\r\n return inner\r\n\r\n\r\n@hookimpl\r\ndef canned_queries(database):\r\n if database == \"counters\":\r\n return {\r\n \"increment\": {\r\n \"sql\": \"update counters set value = value + 1 where name = 'counter'\",\r\n \"write\": True,\r\n },\r\n \"decrement\": {\r\n \"sql\": \"update counters set value = value - 1 where name = 'counter'\",\r\n \"write\": True,\r\n },\r\n }\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1843391585, "label": "Add writable canned query demo to latest.datasette.io"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2134#issuecomment-1671503163", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2134", "id": 1671503163, "node_id": "IC_kwDOBm6k_c5joR07", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-09T14:32:30Z", "updated_at": "2023-08-09T14:32:30Z", "author_association": "OWNER", "body": "Annoying thing about this plugin is that you don't see the new counter value when you submit the increment or decrement query.\r\n\r\nMaybe canned queries should support SQL multiple statements? Could return the result of the last one.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1843391585, "label": "Add writable canned query demo to latest.datasette.io"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2134#issuecomment-1671526372", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2134", "id": 1671526372, "node_id": "IC_kwDOBm6k_c5joXfk", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-09T14:39:54Z", "updated_at": "2023-08-09T14:39:54Z", "author_association": "OWNER", "body": "Alternatively, what about if there was a custom SQL function available during canned write queries for setting the output message? Then the fact that canned queries don't return a table view wouldn't be a problem. Bit weird though.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1843391585, "label": "Add writable canned query demo to latest.datasette.io"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2134#issuecomment-1671581610", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2134", "id": 1671581610, "node_id": "IC_kwDOBm6k_c5jok-q", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-09T15:01:14Z", "updated_at": "2023-08-10T00:19:56Z", "author_association": "OWNER", "body": "Or... how about if the `on_success_message` option could define a SQL query to be executed to generate that message? Maybe `on_success_message_sql`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1843391585, "label": "Add writable canned query demo to latest.datasette.io"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/2134#issuecomment-1672384439", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/2134", "id": 1672384439, "node_id": "IC_kwDOBm6k_c5jro-3", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-10T01:05:56Z", "updated_at": "2023-08-10T01:22:46Z", "author_association": "OWNER", "body": "Now live at https://latest.datasette.io/counters\r\n\r\n![increment](https://github.com/simonw/datasette/assets/9599/ffb3625b-b61b-4189-80e3-7b4e8b411f14)\r\n", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1843391585, "label": "Add writable canned query demo to latest.datasette.io"}, "performed_via_github_app": null}